lenskit / lenskit/csr

Multiplying a complex matrix with a complex vector raises an error

Open
#19 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
15
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Hi, I was playing with CSR as a prospect tool for using sparse matrices in Numba. In my use case, multiplication of a complex matrix and a complex vector is common, e.g.,

import numpy as np, scipy as sp
import csr

# Complex matrix
A_ = sp.sparse.random(5, 5, density=0.1, format='csr') + 1j*sp.sparse.random(5, 5, density=0.1, format='csr')
A = csr.create(A_.shape[0], A_.shape[1], A_.nnz, A_.indptr, A_.indices, A_.data)

# Complex vector
b = np.random.random(5) + 1j*np.random.random(5)

# Expected output is a complex vector
A.mult_vec(b)

However, the last line in the above snippet raises a TypingError, i.e.,

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function setitem>) found for signature:
 
 >>> setitem(array(float64, 1d, C), int64, complex128)
 
There are 16 candidate implementations:
      - Of which 16 did not match due to:
      Overload of function 'setitem': File: <numerous>: Line N/A.
        With argument(s): '(array(float64, 1d, C), int64, complex128)':
       No match.

During: typing of setitem at absolute\path\to\my\conda-env\lib\site-packages\csr\kernels\numba\__init__.py (62)

File "relative\path\to\my\conda-env\lib\site-packages\csr\kernels\numba\__init__.py", line 62:
def mult_vec(h: CSR, v):
    <source elided>
        col = h.colinds[i]
        res[row] += v[col] * h._e_value(i)
        ^

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in the issue, then inspect csr/kernels/numba/init.py around line 62, where mult_vec assigns the multiplication result. Done means multiplying a complex CSR matrix by a complex vector returns the expected complex vector without a Numba TypingError, with a regression test for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.