Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions base_matrix/base_matrix_compiled_sparse_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,8 +2838,8 @@ template <typename T, std::size_t M, std::size_t N, std::size_t K,
std::size_t J, std::size_t Start, std::size_t End>
struct Loop {
static void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
T &sum) {

sum += B.values[Start] * A(I, RowIndices_B::list[Start]);
Expand All @@ -2854,13 +2854,13 @@ template <typename T, std::size_t M, std::size_t N, std::size_t K,
std::size_t J, std::size_t End>
struct Loop<T, M, N, K, RowIndices_B, RowPointers_B, I, J, End, End> {
static void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
T &sum) {
// End of loop, do nothing
static_cast<void>(A);
static_cast<void>(B);
static_cast<void>(sum);
// End of loop, do nothing
}
};

Expand All @@ -2870,9 +2870,9 @@ template <typename T, std::size_t M, std::size_t N, std::size_t K,
std::size_t J>
struct Core {
static void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, N, K> &Y) {
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, M, N> &Y) {

T sum = static_cast<T>(0);
Loop<T, M, N, K, RowIndices_B, RowPointers_B, I, J, RowPointers_B::list[J],
Expand All @@ -2887,9 +2887,9 @@ template <typename T, std::size_t M, std::size_t N, std::size_t K,
std::size_t J>
struct List {
static void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, N, K> &Y) {
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, M, N> &Y) {

Core<T, M, N, K, RowIndices_B, RowPointers_B, I, J>::compute(A, B, Y);
List<T, M, N, K, RowIndices_B, RowPointers_B, I - 1, J>::compute(A, B, Y);
Expand All @@ -2901,9 +2901,9 @@ template <typename T, std::size_t M, std::size_t N, std::size_t K,
typename RowIndices_B, typename RowPointers_B, std::size_t J>
struct List<T, M, N, K, RowIndices_B, RowPointers_B, 0, J> {
static void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, N, K> &Y) {
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, M, N> &Y) {

Core<T, M, N, K, RowIndices_B, RowPointers_B, 0, J>::compute(A, B, Y);
}
Expand All @@ -2914,11 +2914,11 @@ template <typename T, std::size_t M, std::size_t N, std::size_t K,
typename RowIndices_B, typename RowPointers_B, std::size_t J>
struct Column {
static void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, N, K> &Y) {
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, M, N> &Y) {

List<T, M, N, K, RowIndices_B, RowPointers_B, N - 1, J>::compute(A, B, Y);
List<T, M, N, K, RowIndices_B, RowPointers_B, M - 1, J>::compute(A, B, Y);
Column<T, M, N, K, RowIndices_B, RowPointers_B, J - 1>::compute(A, B, Y);
}
};
Expand All @@ -2928,37 +2928,37 @@ template <typename T, std::size_t M, std::size_t N, std::size_t K,
typename RowIndices_B, typename RowPointers_B>
struct Column<T, M, N, K, RowIndices_B, RowPointers_B, 0> {
static void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, N, K> &Y) {
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, M, N> &Y) {

List<T, M, N, K, RowIndices_B, RowPointers_B, N - 1, 0>::compute(A, B, Y);
List<T, M, N, K, RowIndices_B, RowPointers_B, M - 1, 0>::compute(A, B, Y);
}
};

template <typename T, std::size_t M, std::size_t N, typename RowIndices_B,
typename RowPointers_B, std::size_t K>
inline void
compute(const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, N, K> &Y) {
compute(const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B,
Matrix<T, M, N> &Y) {

Column<T, M, N, K, RowIndices_B, RowPointers_B, K - 1>::compute(A, B, Y);
Column<T, M, N, K, RowIndices_B, RowPointers_B, N - 1>::compute(A, B, Y);
}

} // namespace DenseMatrixMultiplySparseTranspose

template <typename T, std::size_t M, std::size_t N, std::size_t K,
typename RowIndices_B, typename RowPointers_B>
inline Matrix<T, N, K> matrix_multiply_A_mul_SparseBTranspose(
const Matrix<T, M, N> &A,
const CompiledSparseMatrix<T, M, K, RowIndices_B, RowPointers_B> &B) {
Matrix<T, N, K> Y;
inline Matrix<T, M, N> matrix_multiply_A_mul_SparseBTranspose(
const Matrix<T, M, K> &A,
const CompiledSparseMatrix<T, N, K, RowIndices_B, RowPointers_B> &B) {
Matrix<T, M, N> Y;

#ifdef __BASE_MATRIX_USE_FOR_LOOP_OPERATION__

for (std::size_t i = 0; i < N; ++i) {
for (std::size_t j = 0; j < K; ++j) {
for (std::size_t i = 0; i < M; ++i) {
for (std::size_t j = 0; j < N; ++j) {
T sum = static_cast<T>(0);
for (std::size_t k = RowPointers_B::list[j];
k < RowPointers_B::list[j + 1]; ++k) {
Expand Down
19 changes: 19 additions & 0 deletions test_vs/check_base_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,25 @@ void CheckBaseMatrix<T>::check_sparse_matrix(void) {
tester.expect_near(Dense_mul_SparseT.data, Dense_mul_SparseT_answer.data, NEAR_LIMIT_STRICT,
"check Matrix multiply SparseMatrix transpose.");

Matrix<T, 4, 4> Dense_44({ {1, 2, 3, 4}, {5, 4, 6, 7}, {9, 8, 7, 3}, {1, 2, 3, 4} });

CompiledSparseMatrix<T, 2, 4,
RowIndices<0, 0, 2>,
RowPointers<0, 1, 3>> Sparse_24({ 1, 3, 8 });

Matrix<T, 4, 2> Dense_44_mul_SparseT_answer = matrix_multiply_A_mul_SparseBTranspose(Dense_44, Sparse_24);

Matrix<T, 4, 2> Dense_44_mul_SparseT({
{1, 27},
{5, 63},
{9, 83},
{1, 27}
});

tester.expect_near(Dense_44_mul_SparseT.data, Dense_44_mul_SparseT_answer.data, NEAR_LIMIT_STRICT,
"check Matrix multiply SparseMatrix transpose 2.");


Matrix<T, 3, 3> DenseT_mul_Sparse = matrix_multiply_ATranspose_mul_SparseB(DenseG, SparseCc);

//std::cout << "DenseM = " << std::endl;
Expand Down