daphne-eu / daphne

DAPHNE: An Open and Extensible System Infrastructure for Integrated Data Analysis Pipelines
Apache License 2.0
67 stars 62 forks source link

Wrong results using Integer Matmul Kernels after Matrix resizing #700

Closed resting-dove closed 4 months ago

resting-dove commented 7 months ago

The results of Matrix multiplications for integer value types are wrong in case that the Matrix has been resized before.

N = 3;
EWs = seq(1, N + 1, 1);
A = diagMatrix(EWs);
A = A[:N, :N];
B = A;
v = fill(1, N, 1);
print(A);

print(A@B);

print(A@t(B));

print(A@v);
DenseMatrix(3x3, int64_t)
1 0 0
0 2 0
0 0 3
DenseMatrix(3x3, int64_t)
1 0 0
0 0 0
0 0 0
DenseMatrix(3x3, int64_t)
1 0 0
0 4 0
0 0 0
DenseMatrix(3x1, int64_t)
1
2
0

Likely Explanation

Integer MatMul kernels are generated using the Eigen library. To use the library the Daphne Matrices are transformed into Eigen Matrices, assuming that the row offset in memory is the row length. When Daphne Matrices are resized they are not necessarily moved in memory, so the row offset does not equal the row length.