From 21d0f54da8b2fdc40013d03241a33971f4a565cd Mon Sep 17 00:00:00 2001 From: Mathias Heyer Date: Wed, 26 Nov 2025 12:39:47 -0800 Subject: [PATCH 1/2] Use integer types for matrix::num_rows and num_cols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a -Wdeprecated-enum-enum-conversion warning on GCC and Clang when compiling with C++20. Previously, num_rows and num_cols were members of an anonymous union within each templated matrix type. This meant that arithmetic operations between num_rows and num_cols of different matrices were technically implicitly converting between different types, resulting in this error: n file included from basis_universal/encoder/basisu_enc.h:4310, from basis_universal/encoder/basisu_astc_hdr_6x6_enc.h:3, from basis_universal/encoder/basisu_astc_hdr_6x6_enc.cpp:2: basis_universal/encoder/basisu_math.h: In instantiation of ‘bu_math::matrix<(X::num_rows * Y::num_rows), (X::num_cols * Y::num_cols), typename X::scalar_type> bu_math::matrix_kronecker_product(const X&, const Y&) [with X = matrix<2, 2, float>; Y = matrix<1, 2, float>; typename X::scalar_type = float]’: basis_universal/encoder/basisu_math.h:2411:57: required from here basis_universal/encoder/basisu_math.h:2362:60: warning: arithmetic between different enumeration types ‘bu_math::matrix<2, 2, float>::’ and ‘bu_math::matrix<1, 2, float>::’ is deprecated [-Wdeprecated-enum-enum-conversion] 2362 | template matrix matrix_kronecker_product(const X& a, const Y& b) | ~~~~~~~~^~~~~~~~~~~~~ Changing the types of num_rows and num_cols to uint32_t fixes this. Co-Authored-By: Mathias Heyer Signed-off-by: Nia Bickford --- encoder/basisu_math.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/encoder/basisu_math.h b/encoder/basisu_math.h index 66bb749a..e44618fe 100644 --- a/encoder/basisu_math.h +++ b/encoder/basisu_math.h @@ -1186,11 +1186,8 @@ namespace bu_math { public: typedef T scalar_type; - enum - { - num_rows = R, - num_cols = C - }; + static const uint32_t num_rows = R; + static const uint32_t num_cols = C; typedef vec col_vec; typedef vec < (R > 1) ? (R - 1) : 0, T > subcol_vec; From f70ed9268998c18b350373b66c330855a510f3ed Mon Sep 17 00:00:00 2001 From: Nia Bickford Date: Thu, 27 Nov 2025 02:30:39 -0800 Subject: [PATCH 2/2] Also avoid uint32_t -> int casts that produced warnings in CI Signed-off-by: Nia Bickford --- encoder/basisu_math.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/encoder/basisu_math.h b/encoder/basisu_math.h index e44618fe..47768016 100644 --- a/encoder/basisu_math.h +++ b/encoder/basisu_math.h @@ -1130,12 +1130,12 @@ namespace bu_math template Z& matrix_mul_helper(Z& result, const X& lhs, const Y& rhs) { - static_assert((int)Z::num_rows == (int)X::num_rows); - static_assert((int)Z::num_cols == (int)Y::num_cols); - static_assert((int)X::num_cols == (int)Y::num_rows); + static_assert(Z::num_rows == X::num_rows); + static_assert(Z::num_cols == Y::num_cols); + static_assert(X::num_cols == Y::num_rows); assert(((void*)&result != (void*)&lhs) && ((void*)&result != (void*)&rhs)); - for (int r = 0; r < X::num_rows; r++) - for (int c = 0; c < Y::num_cols; c++) + for (uint32_t r = 0; r < X::num_rows; r++) + for (uint32_t c = 0; c < Y::num_cols; c++) { typename Z::scalar_type s = lhs(r, 0) * rhs(0, c); for (uint32_t i = 1; i < X::num_cols; i++) @@ -1148,12 +1148,12 @@ namespace bu_math template Z& matrix_mul_helper_transpose_lhs(Z& result, const X& lhs, const Y& rhs) { - static_assert((int)Z::num_rows == (int)X::num_cols); - static_assert((int)Z::num_cols == (int)Y::num_cols); - static_assert((int)X::num_rows == (int)Y::num_rows); + static_assert(Z::num_rows == X::num_cols); + static_assert(Z::num_cols == Y::num_cols); + static_assert(X::num_rows == Y::num_rows); assert(((void*)&result != (void*)&lhs) && ((void*)&result != (void*)&rhs)); - for (int r = 0; r < X::num_cols; r++) - for (int c = 0; c < Y::num_cols; c++) + for (uint32_t r = 0; r < X::num_cols; r++) + for (uint32_t c = 0; c < Y::num_cols; c++) { typename Z::scalar_type s = lhs(0, r) * rhs(0, c); for (uint32_t i = 1; i < X::num_rows; i++) @@ -1166,12 +1166,12 @@ namespace bu_math template Z& matrix_mul_helper_transpose_rhs(Z& result, const X& lhs, const Y& rhs) { - static_assert((int)Z::num_rows == (int)X::num_rows); - static_assert((int)Z::num_cols == (int)Y::num_rows); - static_assert((int)X::num_cols == (int)Y::num_cols); + static_assert(Z::num_rows == X::num_rows); + static_assert(Z::num_cols == Y::num_rows); + static_assert(X::num_cols == Y::num_cols); assert(((void*)&result != (void*)&lhs) && ((void*)&result != (void*)&rhs)); - for (int r = 0; r < X::num_rows; r++) - for (int c = 0; c < Y::num_rows; c++) + for (uint32_t r = 0; r < X::num_rows; r++) + for (uint32_t c = 0; c < Y::num_rows; c++) { typename Z::scalar_type s = lhs(r, 0) * rhs(c, 0); for (uint32_t i = 1; i < X::num_cols; i++) @@ -2141,7 +2141,7 @@ namespace bu_math static inline matrix make_tensor_product_matrix(const row_vec& v, const row_vec& w) { matrix ret; - for (int r = 0; r < num_rows; r++) + for (uint32_t r = 0; r < num_rows; r++) ret[r] = row_vec::mul_components(v.broadcast(r), w); return ret; }