mirror of
https://github.com/Relintai/pmlpp.git
synced 2025-01-02 16:29:35 +01:00
Removed std::vectors from MLPPMatrixTests.
This commit is contained in:
parent
dfee510778
commit
a0e9a9faa1
@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include "core/log/logger.h"
|
#include "core/log/logger.h"
|
||||||
|
|
||||||
//TODO remove
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "../mlpp/lin_alg/mlpp_matrix.h"
|
#include "../mlpp/lin_alg/mlpp_matrix.h"
|
||||||
|
|
||||||
void MLPPMatrixTests::run_tests() {
|
void MLPPMatrixTests::run_tests() {
|
||||||
@ -33,42 +30,42 @@ void MLPPMatrixTests::run_tests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MLPPMatrixTests::test_mlpp_matrix() {
|
void MLPPMatrixTests::test_mlpp_matrix() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 0, 0, 0 },
|
1, 0, 0, 0, //
|
||||||
{ 0, 1, 0, 0 },
|
0, 1, 0, 0, //
|
||||||
{ 0, 0, 1, 0 },
|
0, 0, 1, 0, //
|
||||||
{ 0, 0, 0, 1 }
|
0, 0, 0, 1, //
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat;
|
Ref<MLPPMatrix> rmat;
|
||||||
rmat.instance();
|
rmat.instance();
|
||||||
rmat->set_from_std_vectors(A);
|
rmat->set_from_ptr(A, 4, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat2;
|
Ref<MLPPMatrix> rmat2;
|
||||||
rmat2.instance();
|
rmat2.instance();
|
||||||
rmat2->set_from_std_vectors(A);
|
rmat2->set_from_ptr(A, 4, 4);
|
||||||
|
|
||||||
is_approx_equals_mat(rmat, rmat2, "set_from_std_vectors test.");
|
is_approx_equals_mat(rmat, rmat2, "set_from_ptr test.");
|
||||||
|
|
||||||
rmat2->set_from_std_vectors(A);
|
rmat2->set_from_ptr(A, 4, 4);
|
||||||
|
|
||||||
is_approx_equals_mat(rmat, rmat2, "re-set_from_std_vectors test.");
|
is_approx_equals_mat(rmat, rmat2, "re-set_from_ptr test.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPMatrixTests::test_row_add() {
|
void MLPPMatrixTests::test_row_add() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> B = {
|
const real_t B[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> C = {
|
const real_t C[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<real_t> rv;
|
Vector<real_t> rv;
|
||||||
@ -79,15 +76,15 @@ void MLPPMatrixTests::test_row_add() {
|
|||||||
|
|
||||||
Ref<MLPPMatrix> rmata;
|
Ref<MLPPMatrix> rmata;
|
||||||
rmata.instance();
|
rmata.instance();
|
||||||
rmata->set_from_std_vectors(A);
|
rmata->set_from_ptr(A, 1, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatb;
|
Ref<MLPPMatrix> rmatb;
|
||||||
rmatb.instance();
|
rmatb.instance();
|
||||||
rmatb->set_from_std_vectors(B);
|
rmatb->set_from_ptr(B, 2, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatc;
|
Ref<MLPPMatrix> rmatc;
|
||||||
rmatc.instance();
|
rmatc.instance();
|
||||||
rmatc->set_from_std_vectors(C);
|
rmatc->set_from_ptr(C, 3, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat;
|
Ref<MLPPMatrix> rmat;
|
||||||
rmat.instance();
|
rmat.instance();
|
||||||
@ -102,19 +99,19 @@ void MLPPMatrixTests::test_row_add() {
|
|||||||
is_approx_equals_mat(rmatc, rmat, "rmat->row_add(rv);");
|
is_approx_equals_mat(rmatc, rmat, "rmat->row_add(rv);");
|
||||||
}
|
}
|
||||||
void MLPPMatrixTests::test_row_add_pool_vector() {
|
void MLPPMatrixTests::test_row_add_pool_vector() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> B = {
|
const real_t B[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> C = {
|
const real_t C[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
PoolVector<real_t> rv;
|
PoolVector<real_t> rv;
|
||||||
@ -125,15 +122,15 @@ void MLPPMatrixTests::test_row_add_pool_vector() {
|
|||||||
|
|
||||||
Ref<MLPPMatrix> rmata;
|
Ref<MLPPMatrix> rmata;
|
||||||
rmata.instance();
|
rmata.instance();
|
||||||
rmata->set_from_std_vectors(A);
|
rmata->set_from_ptr(A, 1, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatb;
|
Ref<MLPPMatrix> rmatb;
|
||||||
rmatb.instance();
|
rmatb.instance();
|
||||||
rmatb->set_from_std_vectors(B);
|
rmatb->set_from_ptr(B, 2, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatc;
|
Ref<MLPPMatrix> rmatc;
|
||||||
rmatc.instance();
|
rmatc.instance();
|
||||||
rmatc->set_from_std_vectors(C);
|
rmatc->set_from_ptr(C, 3, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat;
|
Ref<MLPPMatrix> rmat;
|
||||||
rmat.instance();
|
rmat.instance();
|
||||||
@ -148,19 +145,19 @@ void MLPPMatrixTests::test_row_add_pool_vector() {
|
|||||||
is_approx_equals_mat(rmatc, rmat, "rmat->row_add_pool_vector(rv);");
|
is_approx_equals_mat(rmatc, rmat, "rmat->row_add_pool_vector(rv);");
|
||||||
}
|
}
|
||||||
void MLPPMatrixTests::test_row_add_mlpp_vector() {
|
void MLPPMatrixTests::test_row_add_mlpp_vector() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> B = {
|
const real_t B[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> C = {
|
const real_t C[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<MLPPVector> rv;
|
Ref<MLPPVector> rv;
|
||||||
@ -172,15 +169,15 @@ void MLPPMatrixTests::test_row_add_mlpp_vector() {
|
|||||||
|
|
||||||
Ref<MLPPMatrix> rmata;
|
Ref<MLPPMatrix> rmata;
|
||||||
rmata.instance();
|
rmata.instance();
|
||||||
rmata->set_from_std_vectors(A);
|
rmata->set_from_ptr(A, 1, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatb;
|
Ref<MLPPMatrix> rmatb;
|
||||||
rmatb.instance();
|
rmatb.instance();
|
||||||
rmatb->set_from_std_vectors(B);
|
rmatb->set_from_ptr(B, 2, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatc;
|
Ref<MLPPMatrix> rmatc;
|
||||||
rmatc.instance();
|
rmatc.instance();
|
||||||
rmatc->set_from_std_vectors(C);
|
rmatc->set_from_ptr(C, 3, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat;
|
Ref<MLPPMatrix> rmat;
|
||||||
rmat.instance();
|
rmat.instance();
|
||||||
@ -195,22 +192,24 @@ void MLPPMatrixTests::test_row_add_mlpp_vector() {
|
|||||||
is_approx_equals_mat(rmatc, rmat, "rmat->row_add_mlpp_vector(rv);");
|
is_approx_equals_mat(rmatc, rmat, "rmat->row_add_mlpp_vector(rv);");
|
||||||
}
|
}
|
||||||
void MLPPMatrixTests::test_rows_add_mlpp_matrix() {
|
void MLPPMatrixTests::test_rows_add_mlpp_matrix() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4 //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> B = {
|
const real_t B[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> C = {
|
const real_t C[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<real_t> r = { 1, 2, 3, 4 };
|
//const real_t r[] = {
|
||||||
|
// 1, 2, 3, 4
|
||||||
|
//};
|
||||||
|
|
||||||
PoolVector<real_t> rvp;
|
PoolVector<real_t> rvp;
|
||||||
rvp.push_back(1);
|
rvp.push_back(1);
|
||||||
@ -224,15 +223,15 @@ void MLPPMatrixTests::test_rows_add_mlpp_matrix() {
|
|||||||
|
|
||||||
Ref<MLPPMatrix> rmata;
|
Ref<MLPPMatrix> rmata;
|
||||||
rmata.instance();
|
rmata.instance();
|
||||||
rmata->set_from_std_vectors(A);
|
rmata->set_from_ptr(A, 1, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatb;
|
Ref<MLPPMatrix> rmatb;
|
||||||
rmatb.instance();
|
rmatb.instance();
|
||||||
rmatb->set_from_std_vectors(B);
|
rmatb->set_from_ptr(B, 2, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatc;
|
Ref<MLPPMatrix> rmatc;
|
||||||
rmatc.instance();
|
rmatc.instance();
|
||||||
rmatc->set_from_std_vectors(C);
|
rmatc->set_from_ptr(C, 3, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat;
|
Ref<MLPPMatrix> rmat;
|
||||||
rmat.instance();
|
rmat.instance();
|
||||||
@ -248,43 +247,43 @@ void MLPPMatrixTests::test_rows_add_mlpp_matrix() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MLPPMatrixTests::test_row_remove() {
|
void MLPPMatrixTests::test_row_remove() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 5, 6, 7, 8 },
|
5, 6, 7, 8, //
|
||||||
{ 9, 10, 11, 12 },
|
9, 10, 11, 12, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> B = {
|
const real_t B[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 5, 6, 7, 8 },
|
5, 6, 7, 8, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> C = {
|
const real_t C[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> D = {
|
const real_t D[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 5, 6, 7, 8 },
|
5, 6, 7, 8, //
|
||||||
{ 13, 14, 15, 16 },
|
13, 14, 15, 16, //
|
||||||
{ 9, 10, 11, 12 },
|
9, 10, 11, 12, //
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmata;
|
Ref<MLPPMatrix> rmata;
|
||||||
rmata.instance();
|
rmata.instance();
|
||||||
rmata->set_from_std_vectors(A);
|
rmata->set_from_ptr(A, 3, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatb;
|
Ref<MLPPMatrix> rmatb;
|
||||||
rmatb.instance();
|
rmatb.instance();
|
||||||
rmatb->set_from_std_vectors(B);
|
rmatb->set_from_ptr(B, 2, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatc;
|
Ref<MLPPMatrix> rmatc;
|
||||||
rmatc.instance();
|
rmatc.instance();
|
||||||
rmatc->set_from_std_vectors(C);
|
rmatc->set_from_ptr(C, 1, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat;
|
Ref<MLPPMatrix> rmat;
|
||||||
rmat.instance();
|
rmat.instance();
|
||||||
rmat->set_from_std_vectors(D);
|
rmat->set_from_ptr(D, 4, 4);
|
||||||
|
|
||||||
rmat->row_remove(2);
|
rmat->row_remove(2);
|
||||||
is_approx_equals_mat(rmat, rmata, "rmat->row_remove(2);");
|
is_approx_equals_mat(rmat, rmata, "rmat->row_remove(2);");
|
||||||
@ -296,43 +295,43 @@ void MLPPMatrixTests::test_row_remove() {
|
|||||||
is_approx_equals_mat(rmat, rmatc, "rmat->row_remove(1);");
|
is_approx_equals_mat(rmat, rmatc, "rmat->row_remove(1);");
|
||||||
}
|
}
|
||||||
void MLPPMatrixTests::test_row_remove_unordered() {
|
void MLPPMatrixTests::test_row_remove_unordered() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 13, 14, 15, 16 },
|
13, 14, 15, 16, //
|
||||||
{ 9, 10, 11, 12 },
|
9, 10, 11, 12, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> B = {
|
const real_t B[] = {
|
||||||
{ 9, 10, 11, 12 },
|
9, 10, 11, 12, //
|
||||||
{ 13, 14, 15, 16 },
|
13, 14, 15, 16, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> C = {
|
const real_t C[] = {
|
||||||
{ 9, 10, 11, 12 },
|
9, 10, 11, 12, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> D = {
|
const real_t D[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 5, 6, 7, 8 },
|
5, 6, 7, 8, //
|
||||||
{ 9, 10, 11, 12 },
|
9, 10, 11, 12, //
|
||||||
{ 13, 14, 15, 16 },
|
13, 14, 15, 16, //
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmata;
|
Ref<MLPPMatrix> rmata;
|
||||||
rmata.instance();
|
rmata.instance();
|
||||||
rmata->set_from_std_vectors(A);
|
rmata->set_from_ptr(A, 3, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatb;
|
Ref<MLPPMatrix> rmatb;
|
||||||
rmatb.instance();
|
rmatb.instance();
|
||||||
rmatb->set_from_std_vectors(B);
|
rmatb->set_from_ptr(B, 2, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatc;
|
Ref<MLPPMatrix> rmatc;
|
||||||
rmatc.instance();
|
rmatc.instance();
|
||||||
rmatc->set_from_std_vectors(C);
|
rmatc->set_from_ptr(C, 1, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmat;
|
Ref<MLPPMatrix> rmat;
|
||||||
rmat.instance();
|
rmat.instance();
|
||||||
rmat->set_from_std_vectors(D);
|
rmat->set_from_ptr(D, 4, 4);
|
||||||
|
|
||||||
rmat->row_remove_unordered(1);
|
rmat->row_remove_unordered(1);
|
||||||
is_approx_equals_mat(rmat, rmata, "rmat->row_remove_unordered(1);");
|
is_approx_equals_mat(rmat, rmata, "rmat->row_remove_unordered(1);");
|
||||||
@ -345,36 +344,36 @@ void MLPPMatrixTests::test_row_remove_unordered() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MLPPMatrixTests::test_mlpp_matrix_mul() {
|
void MLPPMatrixTests::test_mlpp_matrix_mul() {
|
||||||
std::vector<std::vector<real_t>> A = {
|
const real_t A[] = {
|
||||||
{ 1, 2 },
|
1, 2, //
|
||||||
{ 3, 4 },
|
3, 4, //
|
||||||
{ 5, 6 },
|
5, 6, //
|
||||||
{ 7, 8 }
|
7, 8, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> B = {
|
const real_t B[] = {
|
||||||
{ 1, 2, 3, 4 },
|
1, 2, 3, 4, //
|
||||||
{ 5, 6, 7, 8 }
|
5, 6, 7, 8, //
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> C = {
|
const real_t C[] = {
|
||||||
{ 11, 14, 17, 20 },
|
11, 14, 17, 20, //
|
||||||
{ 23, 30, 37, 44 },
|
23, 30, 37, 44, //
|
||||||
{ 35, 46, 57, 68 },
|
35, 46, 57, 68, //
|
||||||
{ 47, 62, 77, 92 }
|
47, 62, 77, 92, //
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmata;
|
Ref<MLPPMatrix> rmata;
|
||||||
rmata.instance();
|
rmata.instance();
|
||||||
rmata->set_from_std_vectors(A);
|
rmata->set_from_ptr(A, 4, 2);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatb;
|
Ref<MLPPMatrix> rmatb;
|
||||||
rmatb.instance();
|
rmatb.instance();
|
||||||
rmatb->set_from_std_vectors(B);
|
rmatb->set_from_ptr(B, 2, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatc;
|
Ref<MLPPMatrix> rmatc;
|
||||||
rmatc.instance();
|
rmatc.instance();
|
||||||
rmatc->set_from_std_vectors(C);
|
rmatc->set_from_ptr(C, 4, 4);
|
||||||
|
|
||||||
Ref<MLPPMatrix> rmatr1 = rmata->multn(rmatb);
|
Ref<MLPPMatrix> rmatr1 = rmata->multn(rmatb);
|
||||||
is_approx_equals_mat(rmatr1, rmatc, "Ref<MLPPMatrix> rmatr1 = rmata->multn(rmatb);");
|
is_approx_equals_mat(rmatr1, rmatc, "Ref<MLPPMatrix> rmatr1 = rmata->multn(rmatb);");
|
||||||
|
Loading…
Reference in New Issue
Block a user