Commit 30bbca43 authored by Lucas Serrano's avatar Lucas Serrano
Browse files

Adding padding test

parent 549aac5e
......@@ -296,7 +296,6 @@ class BaseMatrix {
std::memcpy(this->array, a, sizeof(T)*NRows*VecSize);
}
else {
const pack_t zero = bs::Zero<pack_t>();
for (int i=0; i<NRows; i++) {
// In this case we copy data row by row
pack_t row = bs::load<pack_t>(&a[i*NCols]);
......@@ -338,6 +337,16 @@ class BaseMatrix {
}
}
bool is_padding_zero() const {
bool padding_ok = true;
for (int i=0; i<NRows; i++) {
for (int j=NCols; j<VecSize; j++) {
if (array[i*VecSize+j] != 0) padding_ok = false;
}
}
return padding_ok;
}
private:
friend void matrix_add<matrix_t>(matrix_t &a, matrix_t &b, matrix_t &c);
......
......@@ -14,7 +14,7 @@ template <typename M>
using my_type = typename M::ElementType;
double precision = 1e-13;
if (typeid(my_type) == typeid(float)) {
precision = 1e-5;
precision = 5e-6;
}
bool is_equal = true;
std::array<my_type, M::NRows * M::NCols> array_a = a.dump_array();
......@@ -54,6 +54,7 @@ TEST(Inverse, Cholesky) {
Inverse<float, 3, 3, 8>::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());
const std::array<float, 9> base_harder_float_array = {
14, 16, 11,
......@@ -73,6 +74,7 @@ TEST(Inverse, Cholesky) {
Inverse<float, 3, 3, 8>::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());
......@@ -94,6 +96,7 @@ TEST(Inverse, Cholesky) {
Inverse<double, 3, 3, 8>::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());
const std::array<double, 9> base_harder_double_array = {
14, 16, 11,
......@@ -113,4 +116,5 @@ TEST(Inverse, Cholesky) {
Inverse<double, 3, 3, 8>::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());
}
......@@ -8,18 +8,21 @@ TEST(BaseMatrixInstanciation, NoArguments) {
const std::array<float, 6> null_matrix = {0, 0, 0, 0, 0, 0};
BaseMatrix<float, 2, 3, 8> 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);
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]);
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]);
ASSERT_EQ(array_2x3_float_matrix.dump_array(), array);
BaseMatrix<float, 1, 6, 8> array_1x6_float_matrix(&array[0]);
......@@ -30,6 +33,7 @@ TEST(BaseMatrixInstanciation, ArrayArguments) {
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]);
ASSERT_EQ(array_3x2_double_matrix.dump_array(), double_array);
EXPECT_TRUE(array_3x2_double_matrix.is_padding_zero());
}
TEST(BaseMatrixAssignment, ArrayRValue) {
......@@ -37,6 +41,7 @@ TEST(BaseMatrixAssignment, ArrayRValue) {
BaseMatrix<float, 3, 2, 8> 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());
}
TEST(BaseMatrixAssignment, BaseMatrixRValue) {
......@@ -46,4 +51,5 @@ TEST(BaseMatrixAssignment, BaseMatrixRValue) {
left_matrix = right_matrix;
ASSERT_EQ(left_matrix.dump_array(), right_matrix.dump_array());
EXPECT_TRUE(left_matrix.is_padding_zero());
}
......@@ -15,6 +15,7 @@ TEST(MatrixAdd, Square) {
matrix_add(base_float_mat, add_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 9> base_double_array = {1,2,3,4,5,6,7,8,9};
const std::array<double, 9> add_double_array = {1,1,1,1,1,1,1,1,1};
......@@ -26,6 +27,7 @@ TEST(MatrixAdd, Square) {
matrix_add(base_double_mat, add_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixAdd, Rectangular2x3) {
......@@ -39,6 +41,7 @@ TEST(MatrixAdd, Rectangular2x3) {
matrix_add(base_float_mat, add_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 6> base_double_array = {1,2,3,4,5,6};
const std::array<double, 6> add_double_array = {1,1,1,1,1,1};
......@@ -50,6 +53,7 @@ TEST(MatrixAdd, Rectangular2x3) {
matrix_add(base_double_mat, add_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixSub, Square) {
......@@ -63,6 +67,7 @@ TEST(MatrixSub, Square) {
matrix_sub(base_float_mat, sub_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 9> base_double_array = {1,2,3,4,5,6,7,8,9};
const std::array<double, 9> sub_double_array = {1,1,1,1,1,1,1,1,1};
......@@ -74,6 +79,7 @@ TEST(MatrixSub, Square) {
matrix_sub(base_double_mat, sub_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixSub, Rectangular2x3) {
......@@ -87,6 +93,7 @@ TEST(MatrixSub, Rectangular2x3) {
matrix_sub(base_float_mat, sub_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 6> base_double_array = {1,2,3,4,5,6};
const std::array<double, 6> sub_double_array = {1,1,1,1,1,1};
......@@ -98,6 +105,7 @@ TEST(MatrixSub, Rectangular2x3) {
matrix_sub(base_double_mat, sub_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixMulMM, Square) {
......@@ -123,6 +131,7 @@ TEST(MatrixMulMM, Square) {
matrix_mul_m_m(left_float_mat, right_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 9> left_double_array = {
1, 2, 0,
......@@ -146,6 +155,7 @@ TEST(MatrixMulMM, Square) {
matrix_mul_m_m(left_double_mat, right_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixMulMM, Rectangular2x3t3x2) {
......@@ -169,6 +179,7 @@ TEST(MatrixMulMM, Rectangular2x3t3x2) {
matrix_mul_m_m(left_float_mat, right_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 6> left_double_array = {
......@@ -191,6 +202,7 @@ TEST(MatrixMulMM, Rectangular2x3t3x2) {
matrix_mul_m_m(left_double_mat, right_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixMulMtM, Square) {
......@@ -216,6 +228,7 @@ TEST(MatrixMulMtM, Square) {
matrix_mul_mt_m(left_float_mat, right_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 9> left_double_array = {
1, 2, 1,
......@@ -239,6 +252,7 @@ TEST(MatrixMulMtM, Square) {
matrix_mul_mt_m(left_double_mat, right_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixMulMtM, Rectangular2x3t3x2) {
......@@ -263,6 +277,7 @@ TEST(MatrixMulMtM, Rectangular2x3t3x2) {
matrix_mul_mt_m(left_float_mat, right_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 6> left_double_array = {
......@@ -286,6 +301,7 @@ TEST(MatrixMulMtM, Rectangular2x3t3x2) {
matrix_mul_mt_m(left_double_mat, right_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixMulMMt, Square) {
......@@ -311,6 +327,7 @@ TEST(MatrixMulMMt, Square) {
matrix_mul_m_mt(left_float_mat, right_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 9> left_double_array = {
1, 2, 0,
......@@ -334,6 +351,7 @@ TEST(MatrixMulMMt, Square) {
matrix_mul_m_mt(left_double_mat, right_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
TEST(MatrixMulMMt, Rectangular2x3t3x2) {
......@@ -356,6 +374,7 @@ TEST(MatrixMulMMt, Rectangular2x3t3x2) {
matrix_mul_m_mt(left_float_mat, right_float_mat, result_float_mat);
EXPECT_EQ(result_float_mat.dump_array(), result_float_array);
EXPECT_TRUE(result_float_mat.is_padding_zero());
const std::array<double, 6> left_double_array = {
......@@ -377,4 +396,5 @@ TEST(MatrixMulMMt, Rectangular2x3t3x2) {
matrix_mul_m_mt(left_double_mat, right_double_mat, result_double_mat);
EXPECT_EQ(result_double_mat.dump_array(), result_double_array);
EXPECT_TRUE(result_double_mat.is_padding_zero());
}
......@@ -8,16 +8,19 @@ TEST(VectorInstanciation, NoArguments) {
const std::array<float, 5> null_vector = {0, 0, 0, 0, 0};
Vector<float, 5, 8> no_args_vector;
ASSERT_EQ(no_args_vector.dump_array(), null_vector);
EXPECT_TRUE(no_args_vector.is_padding_zero());
}
TEST(VectorInstanciation, ArrayArguments) {
const std::array<float, 6> float_array = {1, 2, 3, 4, 5, 6};
Vector<float, 6, 8> float_vector(&float_array[0]);
ASSERT_EQ(float_vector.dump_array(), float_array);
EXPECT_TRUE(float_vector.is_padding_zero());
const std::array<double, 4> double_array = {1, 2, 3, 4};
Vector<double, 4, 8> double_vector(&double_array[0]);
ASSERT_EQ(double_vector.dump_array(), double_array);
EXPECT_TRUE(double_vector.is_padding_zero());
}
TEST(VectorAssignment, ArrayRValue) {
......@@ -25,6 +28,7 @@ TEST(VectorAssignment, ArrayRValue) {
Vector<float, 6, 8> float_vector;
float_vector = &array[0];
ASSERT_EQ(float_vector.dump_array(), array);
EXPECT_TRUE(float_vector.is_padding_zero());
}
TEST(VectorAssignment, VectorRValue) {
......@@ -34,6 +38,7 @@ TEST(VectorAssignment, VectorRValue) {
left_vector = right_vector;
ASSERT_EQ(left_vector.dump_array(), right_vector.dump_array());
EXPECT_TRUE(left_vector.is_padding_zero());
}
TEST(MatrixVectorProduct, SimpleProduct) {
......@@ -50,4 +55,5 @@ TEST(MatrixVectorProduct, SimpleProduct) {
matrix_mul_m_v(matrix, vector, result_vector);
ASSERT_EQ(result_vector.dump_array(), result_array);
EXPECT_TRUE(result_vector.is_padding_zero());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment