mirror of
https://github.com/Relintai/MLPP.git
synced 2025-02-10 16:10:06 +01:00
Implemented LinAlg.kronecker_product
This commit is contained in:
parent
baae76a5e0
commit
d6e94f662b
@ -74,6 +74,39 @@ namespace MLPP{
|
||||
return C;
|
||||
}
|
||||
|
||||
std::vector<std::vector<double>> LinAlg::kronecker_product(std::vector<std::vector<double>> A, std::vector<std::vector<double>> B){
|
||||
std::vector<std::vector<double>> C;
|
||||
// C.resize(A.size() * B.size());
|
||||
// for(int i = 0; i < C.size(); i++){
|
||||
// C[i].resize(A[0].size() * B[0].size());
|
||||
// }
|
||||
|
||||
// [1,2,3,4] [1,2,3,4,5]
|
||||
// [1,1,1,1] [1,2,3,4,5]
|
||||
// [1,2,3,4,5]
|
||||
|
||||
// [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5]
|
||||
// [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5]
|
||||
// [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5]
|
||||
// [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5]
|
||||
// [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5]
|
||||
// [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5] [1,2,3,4,5]
|
||||
|
||||
// Resulting matrix: A.size() * B.size()
|
||||
// A[0].size() * B[0].size()
|
||||
|
||||
for(int k = 0; k < A.size(); k++){
|
||||
for(int j = 0; j < B.size(); j++){
|
||||
std::vector<std::vector<double>> row;
|
||||
for(int i = 0; i < A[0].size(); i++){
|
||||
row.push_back(scalarMultiply(A[k][i], B[j]));
|
||||
}
|
||||
C.push_back(flatten(row));
|
||||
}
|
||||
}
|
||||
return C;
|
||||
}
|
||||
|
||||
std::vector<std::vector<double>> LinAlg::elementWiseDivision(std::vector<std::vector<double>> A, std::vector<std::vector<double>> B){
|
||||
std::vector<std::vector<double>> C;
|
||||
C.resize(A.size());
|
||||
|
Loading…
Reference in New Issue
Block a user