Skip to content

AttributeError in pxo.kron: `'SquaredOp' object has no attribute 'shape' #67

Description

@NinoHerve

Hello Pyxu Team,

I’ve been enjoying using the library for some M/EEG inverse modeling, but I think I’ve stumbled upon a small bug in the Kronecker product implementation.

Description: It appears that pxo.kron still relies on the .shape attribute internally, which causes a failure when used with operators like IdentityOp which have .codim_shape and .dim_shape instead.

Minimal Reproducible Example:

import pyxu.abc as pxa
import pyxu.operator as pxo

ones = pxa.LinOp.from_array(np.ones((2,2)))
eye = pxo.IdentityOp(dim_shape=2)
kron = pxo.kron(eye, ones)

Environment:

  • Pyxu version: 2.0.3
  • Python version: 3.11

Traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[75], [line 6](vscode-notebook-cell:?execution_count=75&line=6)
      4 ones = pxa.LinOp.from_array(np.ones((2,2)))
      5 eye = pxo.IdentityOp(dim_shape=2)
----> [6](vscode-notebook-cell:?execution_count=75&line=6) kron = pxo.kron(eye, ones)

File ~/miniconda3/envs/mindmap/lib/python3.11/site-packages/pyxu/operator/linop/kron.py:188, in kron(A, B)
    186 _A = A.squeeze()
    187 _B = B.squeeze()
--> [188](https://file+.vscode-resource.vscode-cdn.net/home/nino/Code/mindmap/tutorials/analysis/inverse/~/miniconda3/envs/mindmap/lib/python3.11/site-packages/pyxu/operator/linop/kron.py:188) assert (klass := _infer_op_klass(_A, _B)).has(pxa.Property.LINEAR)
    189 is_scalar = lambda _: _.shape == (1, 1)
    190 if is_scalar(_A) and is_scalar(_B):

File ~/miniconda3/envs/mindmap/lib/python3.11/site-packages/pyxu/operator/linop/kron.py:78, in kron.<locals>._infer_op_klass(A, B)
     68 def _infer_op_klass(A: pxt.OpT, B: pxt.OpT) -> pxt.OpC:
     69     # linear \kron linear -> linear
     70     # square (if output square)
   (...)     75     # idemp \kron idemp -> idemp
     76     # func \kron func -> func
     77     properties = set(A.properties() & B.properties())
---> [78](https://file+.vscode-resource.vscode-cdn.net/home/nino/Code/mindmap/tutorials/analysis/inverse/~/miniconda3/envs/mindmap/lib/python3.11/site-packages/pyxu/operator/linop/kron.py:78)     sh = _infer_op_shape(A.shape, B.shape)
     79     if sh[0] == sh[1]:
     80         properties.add(pxa.Property.LINEAR_SQUARE)

AttributeError: 'SquareOp' object has no attribute 'shape'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions