From ad38db03cda6727090cf092c557b1e988a728303 Mon Sep 17 00:00:00 2001 From: novak_99 Date: Sat, 29 May 2021 21:40:43 -0700 Subject: [PATCH] Cleaned up code for LinAlg.kronecker_product --- MLPP/LinAlg/LinAlg.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/MLPP/LinAlg/LinAlg.cpp b/MLPP/LinAlg/LinAlg.cpp index f95bb01..8377b4f 100644 --- a/MLPP/LinAlg/LinAlg.cpp +++ b/MLPP/LinAlg/LinAlg.cpp @@ -76,12 +76,8 @@ namespace MLPP{ std::vector> LinAlg::kronecker_product(std::vector> A, std::vector> B){ std::vector> 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,1,1,1] [1,2,3,4,5] // [1,2,3,4,5] @@ -95,11 +91,11 @@ namespace MLPP{ // Resulting matrix: A.size() * B.size() // A[0].size() * B[0].size() - for(int k = 0; k < A.size(); k++){ + for(int i = 0; i < A.size(); i++){ for(int j = 0; j < B.size(); j++){ std::vector> row; - for(int i = 0; i < A[0].size(); i++){ - row.push_back(scalarMultiply(A[k][i], B[j])); + for(int k = 0; k < A[0].size(); k++){ + row.push_back(scalarMultiply(A[i][k], B[j])); } C.push_back(flatten(row)); }