Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when multiplying a non-square SparseMatrix with an ndarray #8495

Open
wang-mengdi opened this issue Mar 22, 2024 · 0 comments
Open

Error when multiplying a non-square SparseMatrix with an ndarray #8495

wang-mengdi opened this issue Mar 22, 2024 · 0 comments

Comments

@wang-mengdi
Copy link

Describe the bug
Cannot multiply a non-square sparse matrix with an ndarray.

To Reproduce

import taichi as ti

ti.init(arch=ti.cpu)

n_rows, n_cols = 4, 3
#n_rows, n_cols = 4, 4 # this works
sparse_matrix_builder = ti.linalg.SparseMatrixBuilder(n_rows, n_cols, max_num_triplets=12)

@ti.kernel
def fill_sparse_matrix(sparse_matrix_builder: ti.types.sparse_matrix_builder()):
    for i in range(n_rows):
        for j in range(n_cols):
            sparse_matrix_builder[i, j] += i
fill_sparse_matrix(sparse_matrix_builder)
sparse_matrix = sparse_matrix_builder.build()

#dense_vector = ti.field(dtype=ti.f32, shape=n_cols) # this works
dense_vector = ti.ndarray(dtype=ti.f32, shape=n_cols)


@ti.kernel
def initialize_vector():
    for i in range(n_cols):
        dense_vector[i] = i * 2.0

dense_vector = sparse_matrix@dense_vector

print("\nResult:")
for i in range(n_rows):
    print("Row {}: {}".format(i, dense_vector[i]))

Log

[Taichi] version 1.7.0, llvm 15.0.1, commit 2fd24490, win, python 3.11.5
[Taichi] Starting on arch=x64
Assertion failed: rows == this->rows() && cols == this->cols() && "DenseBase::resize() does not actually allow to resize.", file C:\Users\buildbot\actions-runner\_work\taichi\taichi\external\eigen\Eigen\src/Core/DenseBase.h, line 257

Additional comments
Currently the followings are OK:

  1. Multiply a square sparse matrix with a ti.ndarray (see comment 1)
  2. Multiply a non-square sparse matrix with a ti.field (see comment 2)

However, multiplying a non-square matrix with a ti.ndarray will produce errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Untriaged
Development

No branches or pull requests

1 participant