aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-10-21 01:34:39 +0100
committergingerBill <bill@gingerbill.org>2021-10-21 01:34:39 +0100
commit48d277a3c4604481074df2914efbaba9e0dbed25 (patch)
tree6ff9cb7c65046197e043f8b83fdbd2c872dce170 /src/types.cpp
parente0b9475378f4d69ebaf3e141ed941674b2c0d3f3 (diff)
Allow conversions between matrices of the same element count
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/types.cpp b/src/types.cpp
index d3fa363c2..3abcebdfb 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -1293,7 +1293,7 @@ i64 matrix_type_stride_in_elems(Type *t) {
}
-i64 matrix_type_total_elems(Type *t) {
+i64 matrix_type_total_internal_elems(Type *t) {
t = base_type(t);
GB_ASSERT(t->kind == Type_Matrix);
i64 size = type_size_of(t);
@@ -1301,37 +1301,29 @@ i64 matrix_type_total_elems(Type *t) {
return size/gb_max(elem_size, 1);
}
-void matrix_indices_from_index(Type *t, i64 index, i64 *row_index_, i64 *column_index_) {
+i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) {
t = base_type(t);
GB_ASSERT(t->kind == Type_Matrix);
- i64 row_count = t->Matrix.row_count;
- i64 column_count = t->Matrix.column_count;
- GB_ASSERT(0 <= index && index < row_count*column_count);
-
- i64 row_index = index / column_count;
- i64 column_index = index % column_count;
-
- if (row_index_) *row_index_ = row_index;
- if (column_index_) *column_index_ = column_index;
+ GB_ASSERT(0 <= row_index && row_index < t->Matrix.row_count);
+ GB_ASSERT(0 <= column_index && column_index < t->Matrix.column_count);
+ i64 stride_elems = matrix_type_stride_in_elems(t);
+ return stride_elems*column_index + row_index;
}
-
i64 matrix_index_to_offset(Type *t, i64 index) {
t = base_type(t);
GB_ASSERT(t->kind == Type_Matrix);
- i64 row_index, column_index;
- matrix_indices_from_index(t, index, &row_index, &column_index);
- i64 stride_elems = matrix_type_stride_in_elems(t);
- return stride_elems*column_index + row_index;
+ i64 row_index = index%t->Matrix.row_count;
+ i64 column_index = index/t->Matrix.row_count;
+ return matrix_indices_to_offset(t, row_index, column_index);
}
-i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) {
+
+
+bool is_matrix_square(Type *t) {
t = base_type(t);
GB_ASSERT(t->kind == Type_Matrix);
- GB_ASSERT(0 <= row_index && row_index < t->Matrix.row_count);
- GB_ASSERT(0 <= column_index && column_index < t->Matrix.column_count);
- i64 stride_elems = matrix_type_stride_in_elems(t);
- return stride_elems*column_index + row_index;
+ return t->Matrix.row_count == t->Matrix.column_count;
}
bool is_type_valid_for_matrix_elems(Type *t) {