Commit 0a783ad7 authored by Lucas Serrano's avatar Lucas Serrano
Browse files

Removed MaximumVectorSize

parent 72868103
......@@ -2,8 +2,9 @@
FastMatrix: A very efficient linear algebra library for extremely small matrices.
## Dependencies
* libboost (>= 1.61)
* libboost (>= 1.62) with `program_options`
* Boost.Simd
* cmake (>= 3.4)
## Using the library
FastMatrix is a template-based header-only library.
......@@ -16,11 +17,11 @@ There is only one header to import in order to use the library:
```
### Creating a matrix
In order to create a matrix you need to create a object from the `BaseMatrix<Type, NRows, NCols, MaxVecSize>` class
where `NRows` and `NCols` are the matrix dimensions and `MaxVecSize` the maximum vector size of type `Type` your hardware can support.
In order to create a matrix you need to create a object from the `BaseMatrix<Type, NRows, NCols>` class
where `NRows` and `NCols` are the matrix dimensions.
```c++
BaseMatrix<float, 2, 3, 8> my_matrix;
BaseMatrix<float, 2, 3> my_matrix;
```
By default your matrix will be initialized to zero.
......@@ -28,7 +29,7 @@ If you want to initialize it to existing values you can pass an array to the con
Values in the array are considered to be row-major.
```c++
double data[16] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,160};
BaseMatrix<double, 4, 4, 4> my_matrix(data);
BaseMatrix<double, 4, 4> my_matrix(data);
```
### Getting the data back
......@@ -63,9 +64,9 @@ int main (int argc, char **argv) {
10, 11, 12
};
BaseMatrix<float, 2, 3, 8> a(left_data);
BaseMatrix<float, 3, 2, 8> b(right_data);
BaseMatrix<float, 2, 2, 8> c;
BaseMatrix<float, 2, 3> a(left_data);
BaseMatrix<float, 3, 2> b(right_data);
BaseMatrix<float, 2, 2> c;
matrix_mul_m_m(a, b, c); // The matrix product c = a*b
......@@ -84,7 +85,7 @@ Building them require to build Boost.SIMD first.
cd /path/to/Fast-Matrix/
mkdir build && cd build
export Boost_DIR=/path/to/boost/root # Only if you didn't install boost from your distribution
cmake -D CMAKE_PREFIX_PATH=path/to/boost.simd/build ..
cmake -D CMAKE_PREFIX_PATH=path/to/boost.simd_build_dir/ ..
make
```
Once the tests are built you can launch them from the test directory.
......
......@@ -16,23 +16,23 @@ namespace bs = boost::simd;
constexpr int nearest_power_of_two(int min_value, int current_value) {
// Computes the nearest power of two relative to `min_value` starting from the power of two `current_value`
return min_value > current_value/2 ? current_value : nearest_power_of_two(min_value, current_value/2);
return min_value <= current_value ? current_value : nearest_power_of_two(min_value, current_value*2);
}
template <typename T, int NRows, int NCols, int MaxVecSize>
template <typename T, int NRows, int NCols>
class BaseMatrix;
template <typename T, int NCols, int MaxVecSize>
template <typename T, int NCols>
class Vector;
template <typename T, int NRows, int NCols, int MaxVecSize>
std::ostream & operator<<(std::ostream &os, const BaseMatrix<T, NRows, NCols, MaxVecSize> &mat) {
template <typename T, int NRows, int NCols>
std::ostream & operator<<(std::ostream &os, const BaseMatrix<T, NRows, NCols> &mat) {
// Matrix printing function
for (int i=0; i<NRows; i++) {
for (int j=0; j<NCols; j++) {
os << mat.array[i*BaseMatrix<T, NRows, NCols, MaxVecSize>::VecSize + j] << ", ";
os << mat.array[i*BaseMatrix<T, NRows, NCols>::VecSize + j] << ", ";
}
os << std::endl;
}
......@@ -59,8 +59,8 @@ static inline void matrix_sub(M &a, M &b, M &c) {
}
}
template <typename T, int l, int m, int n, int MVS>
static inline void matrix_mul_m_m(BaseMatrix<T, l, m, MVS> &a, BaseMatrix<T, m, n, MVS> &b, BaseMatrix<T, l, n, MVS> &c) {
template <typename T, int l, int m, int n>
static inline void matrix_mul_m_m(BaseMatrix<T, l, m> &a, BaseMatrix<T, m, n> &b, BaseMatrix<T, l, n> &c) {
/*
* Computes the following matrix product C = A*B
* where A, B and C are BaseMatrix objects.
......@@ -68,8 +68,8 @@ static inline void matrix_mul_m_m(BaseMatrix<T, l, m, MVS> &a, BaseMatrix<T, m,
* of C in one vector.
* This use only vector operations so the compiler can optimize easily.
*/
static constexpr int LeftVecSize = BaseMatrix<T, l, m, MVS>::VecSize;
static constexpr int RightVecSize = BaseMatrix<T, m, n, MVS>::VecSize;
static constexpr int LeftVecSize = BaseMatrix<T, l, m>::VecSize;
static constexpr int RightVecSize = BaseMatrix<T, m, n>::VecSize;
using pack_t = bs::pack<T, RightVecSize>;
/* Algorithm:
* For each row of C matrix:
......@@ -90,16 +90,16 @@ static inline void matrix_mul_m_m(BaseMatrix<T, l, m, MVS> &a, BaseMatrix<T, m,
}
}
template <typename T, int l, int m, int n, int MVS>
static inline void matrix_mul_mt_m(BaseMatrix<T, m, l, MVS> &a, BaseMatrix<T, m, n, MVS> &b, BaseMatrix<T, l, n, MVS> &c) {
template <typename T, int l, int m, int n>
static inline void matrix_mul_mt_m(BaseMatrix<T, m, l> &a, BaseMatrix<T, m, n> &b, BaseMatrix<T, l, n> &c) {
/*
* Computes the following matrix product C = t(A)*B
* where A, B and C are BaseMatrix objects.
* This code is nearly identical to matrix_mul_m_m but we
* run through A in column instead of row
*/
static constexpr int LeftVecSize = BaseMatrix<T, m, l, MVS>::VecSize;
static constexpr int RightVecSize = BaseMatrix<T, m, n, MVS>::VecSize;
static constexpr int LeftVecSize = BaseMatrix<T, m, l>::VecSize;
static constexpr int RightVecSize = BaseMatrix<T, m, n>::VecSize;
using pack_t = bs::pack<T, RightVecSize>;
for (int i=0; i<l; i++) {
pack_t res = bs::Zero<pack_t>();
......@@ -112,8 +112,8 @@ static inline void matrix_mul_mt_m(BaseMatrix<T, m, l, MVS> &a, BaseMatrix<T, m,
}
}
template <typename T, int l, int m, int n, int MVS>
static inline void matrix_mul_m_mt(BaseMatrix<T, l, m, MVS> &a, BaseMatrix<T, n, m, MVS> &b, BaseMatrix<T, l, n, MVS> &c) {
template <typename T, int l, int m, int n>
static inline void matrix_mul_m_mt(BaseMatrix<T, l, m> &a, BaseMatrix<T, n, m> &b, BaseMatrix<T, l, n> &c) {
/*
* Computes the following matrix product C = A*t(B)
* where A, B and C are BaseMatrix objects.
......@@ -122,8 +122,8 @@ static inline void matrix_mul_m_mt(BaseMatrix<T, l, m, MVS> &a, BaseMatrix<T, n,
* to load columns of t(B) into vector register we can load row of B instead.
* Assuming that B is store in row order, row of B are correctly aligned for loading.
*/
static constexpr int VecSize = BaseMatrix<T, l, m, MVS>::VecSize; //VecSize are the same for left and right matrices
static constexpr int ResVecSize = BaseMatrix<T, l, n, MVS>::VecSize;
static constexpr int VecSize = BaseMatrix<T, l, m>::VecSize; //VecSize are the same for left and right matrices
static constexpr int ResVecSize = BaseMatrix<T, l, n>::VecSize;
using pack_t = bs::pack<T, VecSize>;
/* Algorithm:
* For each C matrix element:
......@@ -142,9 +142,9 @@ static inline void matrix_mul_m_mt(BaseMatrix<T, l, m, MVS> &a, BaseMatrix<T, n,
}
}
template <typename T, int l, int m, int MVS>
static inline void matrix_mul_m_v(BaseMatrix<T, l, m, MVS> &a, Vector<T, m, MVS> &b, Vector<T, l, MVS> &c) {
static constexpr int VecSize = BaseMatrix<T, l, m, MVS>::VecSize;
template <typename T, int l, int m>
static inline void matrix_mul_m_v(BaseMatrix<T, l, m> &a, Vector<T, m> &b, Vector<T, l> &c) {
static constexpr int VecSize = BaseMatrix<T, l, m>::VecSize;
using pack_t = bs::pack<T, VecSize>;
pack_t vector(&b.array[0]);
......@@ -155,9 +155,9 @@ static inline void matrix_mul_m_v(BaseMatrix<T, l, m, MVS> &a, Vector<T, m, MVS>
}
}
template <typename T, int Size, int MaximumVectorSize>
template <typename T, int Size>
class Inverse {
using M = BaseMatrix<T, Size, Size, MaximumVectorSize>;
using M = BaseMatrix<T, Size, Size>;
public:
static void inverse(M &a, M &inv) {
/* Computes inverse of `a` by using Cholesky decomposition.
......@@ -213,9 +213,9 @@ class Inverse {
}
};
template <typename T, int MaximumVectorSize>
class Inverse<T, 2, MaximumVectorSize> {
using M = BaseMatrix<T, 2, 2, MaximumVectorSize>;
template <typename T>
class Inverse<T, 2> {
using M = BaseMatrix<T, 2, 2>;
public:
static void inverse(M &a, M &inv) {
T inv_det = 1/(a.array[0]*a.array[M::VecSize + 1]- a.array[1]*a.array[1]);
......@@ -225,24 +225,20 @@ class Inverse<T, 2, MaximumVectorSize> {
}
};
template <typename T, int NumberRows, int NumberCols, int MaximumVectorSize>
template <typename T, int NumberRows, int NumberCols>
class BaseMatrix {
/* Class for matrix object
* Matrix object are linearized 2D array with padded line to fit vector size
*/
static_assert(NumberCols <= MaximumVectorSize, "Matrix width must be less than maximum vector size");
static_assert((MaximumVectorSize >= 4) & !(MaximumVectorSize & (MaximumVectorSize - 1)), "Maximum vector size must be a power of two.");
protected:
static constexpr int MaxVecSize = MaximumVectorSize;
// We use the smallest vector size possible
static constexpr int VecSize = nearest_power_of_two(NumberCols, MaximumVectorSize);
static constexpr int VecSize = nearest_power_of_two(NumberCols, 1);
static constexpr int blend_index (int i, int c) {
return i < NumberCols ? i : c+i;
}
using matrix_t = BaseMatrix<T, NumberRows, NumberCols, MaximumVectorSize>;
using matrix_t = BaseMatrix<T, NumberRows, NumberCols>;
using pack_t = bs::pack<T, VecSize>;
public:
......@@ -326,29 +322,29 @@ class BaseMatrix {
private:
friend void matrix_add<matrix_t>(matrix_t &a, matrix_t &b, matrix_t &c);
friend void matrix_sub<matrix_t>(matrix_t &a, matrix_t &b, matrix_t &c);
template <typename U, int l, int m, int n, int MVS> friend void matrix_mul_m_m(BaseMatrix<U, l, m, MVS> &a, BaseMatrix<U, m, n, MVS> &b, BaseMatrix<U, l, n, MVS> &c);
template <typename U, int l, int m, int n, int MVS> friend void matrix_mul_mt_m(BaseMatrix<U, m, l, MVS> &a, BaseMatrix<U, m, n, MVS> &b, BaseMatrix<U, l, n, MVS> &c);
template <typename U, int l, int m, int n, int MVS> friend void matrix_mul_m_mt(BaseMatrix<U, l, m, MVS> &a, BaseMatrix<U, n, m, MVS> &b, BaseMatrix<U, l, n, MVS> &c);
template <typename U, int l, int m, int MVS> friend void matrix_mul_m_v(BaseMatrix<U, l, m, MVS> &a, Vector<U, m, MVS> &b, Vector<U, l, MVS> &c);
friend class Inverse<T, NCols, MaxVecSize>;
friend std::ostream & operator<<<T, NRows, NCols, MaxVecSize>(std::ostream &os, const matrix_t &mat);
template <typename U, int l, int m, int n> friend void matrix_mul_m_m(BaseMatrix<U, l, m> &a, BaseMatrix<U, m, n> &b, BaseMatrix<U, l, n> &c);
template <typename U, int l, int m, int n> friend void matrix_mul_mt_m(BaseMatrix<U, m, l> &a, BaseMatrix<U, m, n> &b, BaseMatrix<U, l, n> &c);
template <typename U, int l, int m, int n> friend void matrix_mul_m_mt(BaseMatrix<U, l, m> &a, BaseMatrix<U, n, m> &b, BaseMatrix<U, l, n> &c);
template <typename U, int l, int m> friend void matrix_mul_m_v(BaseMatrix<U, l, m> &a, Vector<U, m> &b, Vector<U, l> &c);
friend class Inverse<T, NCols>;
friend std::ostream & operator<<<T, NRows, NCols>(std::ostream &os, const matrix_t &mat);
protected:
alignas(sizeof(T)*VecSize) T array[NRows*VecSize] = {0};
};
template <typename T, int NumberCols, int MaximumVectorSize>
class Vector: public BaseMatrix<T, 1, NumberCols, MaximumVectorSize> {
template <typename T, int NumberCols>
class Vector: public BaseMatrix<T, 1, NumberCols> {
public:
using BaseMatrix<T, 1, NumberCols, MaximumVectorSize>::BaseMatrix;
using BaseMatrix<T, 1, NumberCols, MaximumVectorSize>::operator=;
using BaseMatrix<T, 1, NumberCols>::BaseMatrix;
using BaseMatrix<T, 1, NumberCols>::operator=;
protected:
using vector_t = Vector<T, NumberCols, MaximumVectorSize>;
using vector_t = Vector<T, NumberCols>;
private:
template <typename U, int l, int m, int MVS> friend void matrix_mul_m_v(BaseMatrix<U, l, m, MVS> &a, Vector<U, m, MVS> &b, Vector<U, l, MVS> &c);
template <typename U, int l, int m> friend void matrix_mul_m_v(BaseMatrix<U, l, m> &a, Vector<U, m> &b, Vector<U, l> &c);
friend void matrix_add<vector_t>(vector_t &a, vector_t &b, vector_t &c);
friend void matrix_sub<vector_t>(vector_t &a, vector_t &b, vector_t &c);
};
......@@ -48,11 +48,11 @@ TEST(Inverse, Cholesky) {
1, -4, 6,
};
BaseMatrix<float, 3, 3, 8> base_easy_float_mat(&base_easy_float_array[0]);
BaseMatrix<float, 3, 3, 8> inverse_easy_float_mat;
BaseMatrix<float, 3, 3, 8> result_easy_float_mat(&result_easy_float_array[0]);
BaseMatrix<float, 3, 3> base_easy_float_mat(&base_easy_float_array[0]);
BaseMatrix<float, 3, 3> inverse_easy_float_mat;
BaseMatrix<float, 3, 3> result_easy_float_mat(&result_easy_float_array[0]);
Inverse<float, 3, 8>::inverse(base_easy_float_mat, inverse_easy_float_mat);
Inverse<float, 3>::inverse(base_easy_float_mat, inverse_easy_float_mat);
EXPECT_PRED_FORMAT2(compare_floating_point_matrices, inverse_easy_float_mat, result_easy_float_mat);
EXPECT_TRUE(inverse_easy_float_mat.is_padding_zero());
......@@ -68,11 +68,11 @@ TEST(Inverse, Cholesky) {
-71./529, 36./529, 38./529,
};
BaseMatrix<float, 3, 3, 8> base_harder_float_mat(&base_harder_float_array[0]);
BaseMatrix<float, 3, 3, 8> inverse_harder_float_mat;
BaseMatrix<float, 3, 3, 8> result_harder_float_mat(&result_harder_float_array[0]);
BaseMatrix<float, 3, 3> base_harder_float_mat(&base_harder_float_array[0]);
BaseMatrix<float, 3, 3> inverse_harder_float_mat;
BaseMatrix<float, 3, 3> result_harder_float_mat(&result_harder_float_array[0]);
Inverse<float, 3, 8>::inverse(base_harder_float_mat, inverse_harder_float_mat);
Inverse<float, 3>::inverse(base_harder_float_mat, inverse_harder_float_mat);
EXPECT_PRED_FORMAT2(compare_floating_point_matrices, inverse_harder_float_mat, result_harder_float_mat);
EXPECT_TRUE(inverse_harder_float_mat.is_padding_zero());
......@@ -90,11 +90,11 @@ TEST(Inverse, Cholesky) {
1, -4, 6,
};
BaseMatrix<double, 3, 3, 8> base_easy_double_mat(&base_easy_double_array[0]);
BaseMatrix<double, 3, 3, 8> inverse_easy_double_mat;
BaseMatrix<double, 3, 3, 8> result_easy_double_mat(&result_easy_double_array[0]);
BaseMatrix<double, 3, 3> base_easy_double_mat(&base_easy_double_array[0]);
BaseMatrix<double, 3, 3> inverse_easy_double_mat;
BaseMatrix<double, 3, 3> result_easy_double_mat(&result_easy_double_array[0]);
Inverse<double, 3, 8>::inverse(base_easy_double_mat, inverse_easy_double_mat);
Inverse<double, 3>::inverse(base_easy_double_mat, inverse_easy_double_mat);
EXPECT_PRED_FORMAT2(compare_floating_point_matrices, inverse_easy_double_mat, result_easy_double_mat);
EXPECT_TRUE(inverse_easy_double_mat.is_padding_zero());
......@@ -110,11 +110,11 @@ TEST(Inverse, Cholesky) {
-71./529, 36./529, 38./529,
};
BaseMatrix<double, 3, 3, 8> base_harder_double_mat(&base_harder_double_array[0]);
BaseMatrix<double, 3, 3, 8> inverse_harder_double_mat;
BaseMatrix<double, 3, 3, 8> result_harder_double_mat(&result_harder_double_array[0]);
BaseMatrix<double, 3, 3> base_harder_double_mat(&base_harder_double_array[0]);
BaseMatrix<double, 3, 3> inverse_harder_double_mat;
BaseMatrix<double, 3, 3> result_harder_double_mat(&result_harder_double_array[0]);
Inverse<double, 3, 8>::inverse(base_harder_double_mat, inverse_harder_double_mat);
Inverse<double, 3>::inverse(base_harder_double_mat, inverse_harder_double_mat);
EXPECT_PRED_FORMAT2(compare_floating_point_matrices, inverse_harder_double_mat, result_harder_double_mat);
EXPECT_TRUE(inverse_harder_double_mat.is_padding_zero());
}
......@@ -130,11 +130,11 @@ TEST(Inverse, Small) {
-4./3, 7./3,
};
BaseMatrix<float, 2, 2, 8> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 2, 2, 8> inverse_float_mat;
BaseMatrix<float, 2, 2, 8> result_float_mat(&result_float_array[0]);
BaseMatrix<float, 2, 2> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 2, 2> inverse_float_mat;
BaseMatrix<float, 2, 2> result_float_mat(&result_float_array[0]);
Inverse<float, 2, 8>::inverse(base_float_mat, inverse_float_mat);
Inverse<float, 2>::inverse(base_float_mat, inverse_float_mat);
EXPECT_PRED_FORMAT2(compare_floating_point_matrices, inverse_float_mat, result_float_mat);
EXPECT_TRUE(inverse_float_mat.is_padding_zero());
......@@ -149,11 +149,11 @@ TEST(Inverse, Small) {
-4./3, 7./3,
};
BaseMatrix<double, 2, 2, 8> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 2, 2, 8> inverse_double_mat;
BaseMatrix<double, 2, 2, 8> result_double_mat(&result_double_array[0]);
BaseMatrix<double, 2, 2> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 2, 2> inverse_double_mat;
BaseMatrix<double, 2, 2> result_double_mat(&result_double_array[0]);
Inverse<double, 2, 8>::inverse(base_double_mat, inverse_double_mat);
Inverse<double, 2>::inverse(base_double_mat, inverse_double_mat);
EXPECT_PRED_FORMAT2(compare_floating_point_matrices, inverse_double_mat, result_double_mat);
EXPECT_TRUE(inverse_double_mat.is_padding_zero());
}
......@@ -6,57 +6,57 @@
TEST(BaseMatrixInstanciation, NoArguments) {
const std::array<float, 6> null_matrix = {0, 0, 0, 0, 0, 0};
BaseMatrix<float, 2, 3, 8> no_args_matrix;
BaseMatrix<float, 2, 3> no_args_matrix;
ASSERT_EQ(no_args_matrix.dump_array(), null_matrix);
EXPECT_TRUE(no_args_matrix.is_padding_zero());
}
TEST(BaseMatrixInstanciation, ScalarArguments) {
const std::array<float, 9> diag_matrix = {5, 0, 0, 0, 5, 0, 0, 0, 5};
BaseMatrix<float, 3, 3, 8> scalar_arg_matrix(5);
BaseMatrix<float, 3, 3> scalar_arg_matrix(5);
ASSERT_EQ(scalar_arg_matrix.dump_array(), diag_matrix);
EXPECT_TRUE(scalar_arg_matrix.is_padding_zero());
}
TEST(BaseMatrixInstanciation, ArrayArguments) {
const std::array<float, 6> array = {1, 2, 3, 4, 5, 6};
BaseMatrix<float, 3, 2, 8> array_3x2_float_matrix(&array[0]);
BaseMatrix<float, 3, 2> array_3x2_float_matrix(&array[0]);
ASSERT_EQ(array_3x2_float_matrix.dump_array(), array);
EXPECT_TRUE(array_3x2_float_matrix.is_padding_zero());
BaseMatrix<float, 2, 3, 8> array_2x3_float_matrix(&array[0]);
BaseMatrix<float, 2, 3> array_2x3_float_matrix(&array[0]);
ASSERT_EQ(array_2x3_float_matrix.dump_array(), array);
BaseMatrix<float, 1, 6, 8> array_1x6_float_matrix(&array[0]);
BaseMatrix<float, 1, 6> array_1x6_float_matrix(&array[0]);
ASSERT_EQ(array_1x6_float_matrix.dump_array(), array);
BaseMatrix<float, 6, 1, 8> array_6x1_float_matrix(&array[0]);
BaseMatrix<float, 6, 1> array_6x1_float_matrix(&array[0]);
ASSERT_EQ(array_6x1_float_matrix.dump_array(), array);
const std::array<float, 16> squared_array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
BaseMatrix<float, 4, 4, 4> array_4x4_float_matrix(&squared_array[0]);
BaseMatrix<float, 4, 4> array_4x4_float_matrix(&squared_array[0]);
ASSERT_EQ(array_4x4_float_matrix.dump_array(), squared_array);
const std::array<double, 6> double_array = {1, 2, 3, 4, 5, 6};
BaseMatrix<double, 3, 2, 8> array_3x2_double_matrix(&double_array[0]);
BaseMatrix<double, 3, 2> array_3x2_double_matrix(&double_array[0]);
ASSERT_EQ(array_3x2_double_matrix.dump_array(), double_array);
EXPECT_TRUE(array_3x2_double_matrix.is_padding_zero());
}
TEST(BaseMatrixAssignment, ArrayRValue) {
const std::array<float, 6> array = {1, 2, 3, 4, 5, 6};
BaseMatrix<float, 3, 2, 8> array_3x2_float_matrix;
BaseMatrix<float, 3, 2> array_3x2_float_matrix;
array_3x2_float_matrix = &array[0];
ASSERT_EQ(array_3x2_float_matrix.dump_array(), array);
EXPECT_TRUE(array_3x2_float_matrix.is_padding_zero());
const std::array<float, 16> squared_array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
BaseMatrix<float, 4, 4, 4> array_4x4_float_matrix;
BaseMatrix<float, 4, 4> array_4x4_float_matrix;
array_4x4_float_matrix = &squared_array[0];
ASSERT_EQ(array_4x4_float_matrix.dump_array(), squared_array);
}
TEST(BaseMatrixAssignment, BaseMatrixRValue) {
const std::array<float, 6> array_right_matrix = {1, 2, 3, 4, 5, 6};
BaseMatrix<float, 3, 2, 8> left_matrix;
BaseMatrix<float, 3, 2, 8> right_matrix(&array_right_matrix[0]);
BaseMatrix<float, 3, 2> left_matrix;
BaseMatrix<float, 3, 2> right_matrix(&array_right_matrix[0]);
left_matrix = right_matrix;
ASSERT_EQ(left_matrix.dump_array(), right_matrix.dump_array());
......@@ -66,29 +66,29 @@ TEST(BaseMatrixAssignment, BaseMatrixRValue) {
TEST(BaseMatrixStore, StoreMethod) {
const std::array<float, 6> array = {1, 2, 3, 4, 5, 6};
std::array<float, 6> stored_array;
BaseMatrix<float, 3, 2, 8> array_3x2_float_matrix(&array[0]);
BaseMatrix<float, 3, 2> array_3x2_float_matrix(&array[0]);
array_3x2_float_matrix.store(&stored_array[0]);
ASSERT_EQ(stored_array, array);
EXPECT_TRUE(array_3x2_float_matrix.is_padding_zero());
BaseMatrix<float, 2, 3, 8> array_2x3_float_matrix(&array[0]);
BaseMatrix<float, 2, 3> array_2x3_float_matrix(&array[0]);
array_2x3_float_matrix.store(&stored_array[0]);
ASSERT_EQ(stored_array, array);
BaseMatrix<float, 1, 6, 8> array_1x6_float_matrix(&array[0]);
BaseMatrix<float, 1, 6> array_1x6_float_matrix(&array[0]);
array_1x6_float_matrix.store(&stored_array[0]);
ASSERT_EQ(stored_array, array);
BaseMatrix<float, 6, 1, 8> array_6x1_float_matrix(&array[0]);
BaseMatrix<float, 6, 1> array_6x1_float_matrix(&array[0]);
array_6x1_float_matrix.store(&stored_array[0]);
ASSERT_EQ(stored_array, array);
const std::array<float, 16> squared_array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
std::array<float, 16> squared_stored_array;
BaseMatrix<float, 4, 4, 4> array_4x4_float_matrix(&squared_array[0]);
BaseMatrix<float, 4, 4> array_4x4_float_matrix(&squared_array[0]);
array_4x4_float_matrix.store(&squared_stored_array[0]);
ASSERT_EQ(squared_stored_array, squared_array);
const std::array<double, 6> double_array = {1, 2, 3, 4, 5, 6};
std::array<double, 6> double_stored_array = {1, 2, 3, 4, 5, 6};
BaseMatrix<double, 3, 2, 8> array_3x2_double_matrix(&double_array[0]);
BaseMatrix<double, 3, 2> array_3x2_double_matrix(&double_array[0]);
array_3x2_double_matrix.store(&double_stored_array[0]);
ASSERT_EQ(double_stored_array, double_array);
EXPECT_TRUE(array_3x2_double_matrix.is_padding_zero());
......
......@@ -9,9 +9,9 @@ TEST(MatrixAdd, Square) {
const std::array<float, 9> add_float_array = {1,1,1,1,1,1,1,1,1};
const std::array<float, 9> result_float_array = {2,3,4,5,6,7,8,9,10};
BaseMatrix<float, 3, 3, 8> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 3, 3, 8> add_float_mat(&add_float_array[0]);
BaseMatrix<float, 3, 3, 8> result_float_mat;
BaseMatrix<float, 3, 3> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 3, 3> add_float_mat(&add_float_array[0]);
BaseMatrix<float, 3, 3> result_float_mat;
matrix_add(base_float_mat, add_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
......@@ -21,9 +21,9 @@ TEST(MatrixAdd, Square) {
const std::array<double, 9> add_double_array = {1,1,1,1,1,1,1,1,1};
const std::array<double, 9> result_double_array = {2,3,4,5,6,7,8,9,10};
BaseMatrix<double, 3, 3, 8> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 3, 3, 8> add_double_mat(&add_double_array[0]);
BaseMatrix<double, 3, 3, 8> result_double_mat;
BaseMatrix<double, 3, 3> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 3, 3> add_double_mat(&add_double_array[0]);
BaseMatrix<double, 3, 3> result_double_mat;
matrix_add(base_double_mat, add_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
......@@ -35,9 +35,9 @@ TEST(MatrixAdd, Rectangular2x3) {
const std::array<float, 6> add_float_array = {1,1,1,1,1,1};
const std::array<float, 6> result_float_array = {2,3,4,5,6,7};
BaseMatrix<float, 2, 3, 8> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 2, 3, 8> add_float_mat(&add_float_array[0]);
BaseMatrix<float, 2, 3, 8> result_float_mat;
BaseMatrix<float, 2, 3> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 2, 3> add_float_mat(&add_float_array[0]);
BaseMatrix<float, 2, 3> result_float_mat;
matrix_add(base_float_mat, add_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
......@@ -47,9 +47,9 @@ TEST(MatrixAdd, Rectangular2x3) {
const std::array<double, 6> add_double_array = {1,1,1,1,1,1};
const std::array<double, 6> result_double_array = {2,3,4,5,6,7};
BaseMatrix<double, 2, 3, 8> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 2, 3, 8> add_double_mat(&add_double_array[0]);
BaseMatrix<double, 2, 3, 8> result_double_mat;
BaseMatrix<double, 2, 3> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 2, 3> add_double_mat(&add_double_array[0]);
BaseMatrix<double, 2, 3> result_double_mat;
matrix_add(base_double_mat, add_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
......@@ -61,9 +61,9 @@ TEST(MatrixSub, Square) {
const std::array<float, 9> sub_float_array = {1,1,1,1,1,1,1,1,1};
const std::array<float, 9> result_float_array = {0,1,2,3,4,5,6,7,8};
BaseMatrix<float, 3, 3, 8> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 3, 3, 8> sub_float_mat(&sub_float_array[0]);
BaseMatrix<float, 3, 3, 8> result_float_mat;
BaseMatrix<float, 3, 3> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 3, 3> sub_float_mat(&sub_float_array[0]);
BaseMatrix<float, 3, 3> result_float_mat;
matrix_sub(base_float_mat, sub_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
......@@ -73,9 +73,9 @@ TEST(MatrixSub, Square) {
const std::array<double, 9> sub_double_array = {1,1,1,1,1,1,1,1,1};
const std::array<double, 9> result_double_array = {0,1,2,3,4,5,6,7,8};
BaseMatrix<double, 3, 3, 8> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 3, 3, 8> sub_double_mat(&sub_double_array[0]);
BaseMatrix<double, 3, 3, 8> result_double_mat;
BaseMatrix<double, 3, 3> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 3, 3> sub_double_mat(&sub_double_array[0]);
BaseMatrix<double, 3, 3> result_double_mat;
matrix_sub(base_double_mat, sub_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
......@@ -87,9 +87,9 @@ TEST(MatrixSub, Rectangular2x3) {
const std::array<float, 6> sub_float_array = {1,1,1,1,1,1};
const std::array<float, 6> result_float_array = {0,1,2,3,4,5};
BaseMatrix<float, 2, 3, 8> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 2, 3, 8> sub_float_mat(&sub_float_array[0]);
BaseMatrix<float, 2, 3, 8> result_float_mat;
BaseMatrix<float, 2, 3> base_float_mat(&base_float_array[0]);
BaseMatrix<float, 2, 3> sub_float_mat(&sub_float_array[0]);
BaseMatrix<float, 2, 3> result_float_mat;
matrix_sub(base_float_mat, sub_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
......@@ -99,9 +99,9 @@ TEST(MatrixSub, Rectangular2x3) {
const std::array<double, 6> sub_double_array = {1,1,1,1,1,1};
const std::array<double, 6> result_double_array = {0,1,2,3,4,5};
BaseMatrix<double, 2, 3, 8> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 2, 3, 8> sub_double_mat(&sub_double_array[0]);
BaseMatrix<double, 2, 3, 8> result_double_mat;
BaseMatrix<double, 2, 3> base_double_mat(&base_double_array[0]);
BaseMatrix<double, 2, 3> sub_double_mat(&sub_double_array[0]);
BaseMatrix<double, 2, 3> result_double_mat;
matrix_sub(base_double_mat, sub_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
......@@ -125,9 +125,9 @@ TEST(MatrixMulMM, Square) {
3.1, 2.1, 4.7,
};
BaseMatrix<float, 3, 3, 8> left_float_mat(&left_float_array[0]);
BaseMatrix<float, 3, 3, 8> right_float_mat(&right_float_array[0]);
BaseMatrix<float, 3, 3, 8> result_float_mat;
BaseMatrix<float, 3, 3> left_float_mat(&left_float_array[0]);
BaseMatrix<float, 3, 3> right_float_mat(&right_float_array[0]);
BaseMatrix<float, 3, 3> result_float_mat;
matrix_mul_m_m(left_float_mat, right_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
......@@ -149,9 +149,9 @@ TEST(MatrixMulMM, Square) {