-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
484 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <iostream> | ||
#include <stp/stp_eigen.hpp> | ||
|
||
using Eigen::MatrixXi; | ||
|
||
void print(const matrix_chain& mc) | ||
{ | ||
int i = 1; | ||
for(const matrix& m : mc) | ||
{ | ||
std::cout << "M" << i << ": " << m.rows() << "x" << m.cols() << "\n"; | ||
i++; | ||
} | ||
} | ||
|
||
matrix random_generation(int row, int col) | ||
{ | ||
matrix result(row, col); | ||
for(int i = 0; i < row; i++) | ||
for(int j = 0; j < col; j++) | ||
result(i, j) = rand() % 2; | ||
return result; | ||
} | ||
|
||
void test1() | ||
{ | ||
matrix_chain mc; | ||
for(int i = 0; i < 22; i++) | ||
{ | ||
mc.push_back(random_generation(2, 4)); | ||
} | ||
// print(mc); | ||
matrix r1 = stp::matrix_chain_multiply(mc, true); | ||
matrix r2 = stp::matrix_chain_multiply(mc, true, stp::mc_multiply_method::sequence); | ||
assert(r1 == r2); | ||
} | ||
|
||
void test2() | ||
{ | ||
matrix_chain mc; | ||
for(int i = 0; i < 22; i++) | ||
{ | ||
mc.push_back(random_generation(4, 2)); | ||
} | ||
// print(mc); | ||
matrix r1 = stp::matrix_chain_multiply(mc, true); | ||
matrix r2 = stp::matrix_chain_multiply(mc, true, stp::mc_multiply_method::sequence); | ||
assert(r1 == r2); | ||
} | ||
|
||
void test3() | ||
{ | ||
matrix_chain mc; | ||
for(int i = 0; i < 100; i++) | ||
{ | ||
if(rand() % 2 == 1) mc.push_back(random_generation(4, 2)); | ||
else mc.push_back(random_generation(2, 4)); | ||
} | ||
// print(mc); | ||
matrix r1 = stp::matrix_chain_multiply(mc, true); | ||
matrix r2 = stp::matrix_chain_multiply(mc, true, stp::mc_multiply_method::sequence); | ||
assert(r1 == r2); | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
std::cout << "-------------------------------------------------------\n"; | ||
test1(); | ||
std::cout << "-------------------------------------------------------\n"; | ||
test2(); | ||
std::cout << "-------------------------------------------------------\n"; | ||
test3(); | ||
std::cout << "-------------------------------------------------------\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <iostream> | ||
#include <stp/stp_eigen.hpp> | ||
|
||
using Eigen::MatrixXi; | ||
|
||
matrix random_generation(int row, int col) | ||
{ | ||
matrix result(row, col); | ||
for(int i = 0; i < row; i++) | ||
for(int j = 0; j < col; j++) | ||
result(i, j) = rand() % 2; | ||
return result; | ||
} | ||
|
||
int main() | ||
{ | ||
//n % p = 0 type matrix multiplication test | ||
for(int i = 0; i < 10; i++) | ||
{ | ||
int m = 200; | ||
int n = 4 << i; | ||
int p = 4; | ||
int q = 100; | ||
matrix A = random_generation(m, n); | ||
matrix B = random_generation(p, q); | ||
stp::semi_tensor_product(A, B, true, stp::stp_method::definition_1); | ||
stp::semi_tensor_product(A, B, true, stp::stp_method::definition_2); | ||
stp::semi_tensor_product(A, B, true); | ||
} | ||
|
||
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; | ||
|
||
//p % n = 0 type matrix multiplication test | ||
for(int i = 0; i < 10; i++) | ||
{ | ||
int m = 200; | ||
int n = 4; | ||
int p = 4 << i; | ||
int q = 100; | ||
matrix A = random_generation(m, n); | ||
matrix B = random_generation(p, q); | ||
stp::semi_tensor_product(A, B, true, stp::stp_method::definition_1); | ||
stp::semi_tensor_product(A, B, true, stp::stp_method::definition_2); | ||
stp::semi_tensor_product(A, B, true); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.