EMS-TU-Ilmenau / fastmat

A library to build up lazily evaluated expressions of linear transforms for efficient scientific computing.
https://fastmat.readthedocs.io
Apache License 2.0
24 stars 8 forks source link

'Blocks' object has no attribute 'backwardC' error when calling blocks.conj.backward #84

Closed JanKirchhofTU closed 3 years ago

JanKirchhofTU commented 4 years ago

Say I do the following simple thing:

import fastmat as fm
import numpy as np

# Say I have some matrix real or complex
some_matrix = fm.Matrix(
    np.random.randn(2,2)
)
some_complex_matrix = fm.Matrix(
    np.random.randn(2,2) + 1j*np.random.randn(2,2)
)
# And i create a fastmat.Blocks out of it:
blocks = fm.Blocks([[some_matrix, some_matrix], [some_matrix, some_matrix]])
complex_blocks =\
    fm.Blocks([[some_complex_matrix, some_complex_matrix],
                     [some_complex_matrix, some_complex_matrix]]
                  )
# Works
random_calc = blocks.backward(
    np.random.randn(blocks.shape[0])
)
# Works
random_calc = complex_blocks.backward(
    np.random.randn(blocks.shape[0])
)
# Works
random_calc = blocks.conj.backward(
np.random.randn(blocks.shape[0])
)
# Leads to the above error:
random_calc = complex_blocks.conj.backward(
    np.random.randn(blocks.shape[0])
)

The exact error output is

    random_calc = complex_blocks.conj.backward(
  File "fastmat/Matrix.pyx", line 1889, in fastmat.Matrix.Matrix.backward
  File "fastmat/Matrix.pyx", line 1948, in fastmat.Matrix.Matrix.backward
  File "fastmat/Matrix.pyx", line 2340, in fastmat.Matrix.Conjugate._backwardC
AttributeError: 'fastmat.Blocks.Blocks' object has no attribute 'backwardC'
ChristophWWagner commented 4 years ago

After some code-golf this is the shortest example I could come up with that reproduces the error:

>>> x = np.random.randn(10) * 1j
>>> y = fm.Diag(x).conj.backward(x)

Some observations:

ChristophWWagner commented 4 years ago

From the current revelations around cython, it could be worth investigating if this error is also susceptible to the version different of cython 0.29.15 to 0.29.20 as suggested in #87

ChristophWWagner commented 3 years ago

Issue was found and fixed in deaa900. Closing.