From f5d25c2f95172ae96a5bf725102a26aebdb420d4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 28 Feb 2019 11:57:54 +0100 Subject: compat/simple-mat: rename awkward identifiers --- compat/simple-mat.hpp | 153 ++++++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 74 deletions(-) diff --git a/compat/simple-mat.hpp b/compat/simple-mat.hpp index b82f1cb0..49ae2c85 100644 --- a/compat/simple-mat.hpp +++ b/compat/simple-mat.hpp @@ -55,60 +55,60 @@ namespace simple_mat { enum { value = h * w == sizeof...(ts) }; }; -template +template class Mat { - static_assert(h_ > 0 && w_ > 0, "must have positive mat dimensions"); - num data[h_][w_]; + static_assert(H > 0 && W > 0, "must have positive mat dimensions"); + num data[H][W]; public: - // parameters w_ and h_ are rebound so that SFINAE occurs + // parameters W and H are rebound so that SFINAE occurs // removing them causes a compile-time error -sh 20150811 - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline operator()(t i) const& { return data[(unsigned)i][0]; } - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline operator()(t i) const& { return data[0][(unsigned)i]; } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline operator()(t i) & { return data[(unsigned)i][0]; } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline operator()(t i) & { return data[0][(unsigned)i]; } -#define OTR_MAT_ASSERT_SWIZZLE static_assert(P == h_ && Q == w_) +#define OTR_MAT_ASSERT_SWIZZLE static_assert(P == H && Q == W) // const variants - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline x() const& { OTR_MAT_ASSERT_SWIZZLE; return operator()(0); } - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline y() const& { OTR_MAT_ASSERT_SWIZZLE; return operator()(1); } - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline z() const& { OTR_MAT_ASSERT_SWIZZLE; return operator()(2); } - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline w() const& { OTR_MAT_ASSERT_SWIZZLE; return operator()(3); } // mutable variants - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline x() & { OTR_MAT_ASSERT_SWIZZLE; return operator()(0); } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline y() & { OTR_MAT_ASSERT_SWIZZLE; return operator()(1); } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline z() & { OTR_MAT_ASSERT_SWIZZLE; return operator()(2); } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline w() & { OTR_MAT_ASSERT_SWIZZLE; return operator()(3); } - template + template constexpr auto norm_squared() const -> std::enable_if_t::value, num> { - static_assert(P == h_ && Q == w_); + static_assert(P == H && Q == W); const num val = dot(*this); constexpr num eps = num(1e-4); @@ -121,11 +121,11 @@ public: inline auto norm() const { return num(std::sqrt(norm_squared())); } - template + template std::enable_if_t::value, num> constexpr dot(const Mat& p2) const { - static_assert(P == h_ && Q == w_); + static_assert(P == H && Q == W); num ret = 0; constexpr int len = vector_len::value; @@ -134,11 +134,11 @@ public: return ret; } - template + template std::enable_if_t::value, Mat::P, is_dim3::Q>> constexpr cross(const Mat& b) const { - static_assert(P == h_ && Q == w_); + static_assert(P == H && Q == W); const auto& a = *this; return Mat(a.y()*b.z() - a.z()*b.y(), @@ -146,62 +146,62 @@ public: a.x()*b.y() - a.y()*b.x()); } - constexpr Mat operator+(const Mat& other) const + constexpr Mat operator+(const Mat& other) const { - Mat ret; - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + Mat ret; + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) ret(j, i) = data[j][i] + other.data[j][i]; return ret; } - constexpr Mat operator-(const Mat& other) const + constexpr Mat operator-(const Mat& other) const { - Mat ret; - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + Mat ret; + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) ret(j, i) = data[j][i] - other.data[j][i]; return ret; } - constexpr Mat operator+(const num other) const + constexpr Mat operator+(const num other) const { - Mat ret; - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + Mat ret; + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) ret(j, i) = data[j][i] + other; return ret; } - constexpr Mat operator-(const num other) const + constexpr Mat operator-(const num other) const { - Mat ret; - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + Mat ret; + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) ret(j, i) = data[j][i] - other; return ret; } template - constexpr Mat operator*(const Mat& other) const + constexpr Mat operator*(const Mat& other) const { - Mat ret; - for (int k = 0; k < h_; k++) + Mat ret; + for (int k = 0; k < H; k++) for (int i = 0; i < p; i++) { ret(k, i) = 0; - for (int j = 0; j < w_; j++) + for (int j = 0; j < W; j++) ret(k, i) += data[k][j] * other(j, i); } return ret; } - constexpr Mat mult_elementwise(const Mat& other) const& + constexpr Mat mult_elementwise(const Mat& other) const& { - Mat ret; + Mat ret; - for (unsigned j = 0; j < h_; j++) - for (unsigned i = 0; i < w_; i++) + for (unsigned j = 0; j < H; j++) + for (unsigned i = 0; i < W; i++) ret(j, i) = data[j][i] * other.data[j][i]; return ret; @@ -213,11 +213,16 @@ public: template constexpr inline num& operator()(t j, u i) & { return data[(unsigned)j][(unsigned)i]; } - template::value>> +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmissing-braces" +#endif + + template::value>> constexpr Mat(const ts... xs) : data{static_cast(xs)...} { - static_assert(h__ == h_ && w__ == w_); + static_assert(h2 == H && w2 == W); } #ifdef __clang__ @@ -226,16 +231,16 @@ public: constexpr Mat() { - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) data[j][i] = num(0); } Mat(const num* mem) { - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) - data[j][i] = mem[i*h_+j]; + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) + data[j][i] = mem[i*H+j]; } constexpr operator num*() & { return (num*)data; } @@ -244,37 +249,37 @@ public: // XXX add more operators as needed, third-party dependencies mostly // not needed merely for matrix algebra -sh 20141030 - template - static std::enable_if_t> eye() + template + static std::enable_if_t> eye() { - static_assert(h_ == h__); + static_assert(H == H_); - Mat ret; - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + Mat ret; + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) ret.data[j][i] = 0; - for (int i = 0; i < h_; i++) + for (int i = 0; i < H; i++) ret.data[i][i] = 1; return ret; } - constexpr Mat t() const + constexpr Mat t() const { - Mat ret; + Mat ret; - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) ret(i, j) = data[j][i]; return ret; } - constexpr Mat& operator=(const Mat& rhs) + constexpr Mat& operator=(const Mat& rhs) { - for (unsigned j = 0; j < h_; j++) - for (unsigned i = 0; i < w_; i++) + for (unsigned j = 0; j < H; j++) + for (unsigned i = 0; i < W; i++) data[j][i] = rhs(j, i); return *this; @@ -287,12 +292,12 @@ constexpr Mat operator*(num scalar, const Mat& mat) return mat * scalar; } -template -constexpr Mat operator*(const Mat& self, num other) +template +constexpr Mat operator*(const Mat& self, num other) { - Mat ret; - for (int j = 0; j < h_; j++) - for (int i = 0; i < w_; i++) + Mat ret; + for (int j = 0; j < H; j++) + for (int i = 0; i < W; i++) ret(j, i) = self(j, i) * other; return ret; } -- cgit v1.2.3