gnu-octave / symbolic

A Symbolic Package for Octave using SymPy
https://octave.sourceforge.io/symbolic/
GNU General Public License v3.0
151 stars 36 forks source link

isequal: failing with error: cell2mat: C must be a cell array #1221

Closed cbm755 closed 1 year ago

cbm755 commented 2 years ago

This is based on a test from @sym/and, on the Array_not_Matrix branch:

>> t = sym(true); f = sym(false);
>> w = [t t; f f]; z = [t f; t f];
>> A = w & z
pydebug: elementwise_op: returning an Array not a Matrix
pydebug: I am here with an array with shape (2, 2)
A = (sym 2×2 matrix)
  ⎡True   False⎤
  ⎢            ⎥
  ⎣False  False⎦

>> isequal (A, [t f; f f])
error: cell2mat: C must be a cell array
error: called from
    cell2mat at line 47 column 7
    uniop_bool_helper at line 62 column 11
    isnan at line 51 column 5
    isequal at line 62 column 3

Note:

>> sympy(w)
ans = MutableDenseMatrix([[true, true], [false, false]])
>> sympy(A)
ans = ImmutableDenseNDimArray(Tuple(true, false, false, false), Tuple(Integer(2), Integer(2)))

Looks like even after #1216, we're still getting Matrix from concatenate ops:

>> sympy(horzcat(t, t))
ans = MutableDenseMatrix([[true, true]])
cbm755 commented 2 years ago

Oh perhaps I misunderstand dbg_no_array as it seems nothing was making Arrays... This issue may not be valid

cbm755 commented 2 years ago

Simpler way to hit this:

>> t = sym(true)
>> w = [t t]
pydebug: make_matrix_or_array: making 2D Array...
pydebug: I am here with an array with shape (2, 1)
pydebug: make_matrix_or_array: making 2D Array...
pydebug: I am here with an array with shape (1, 2)
w = (sym) [[True  True]]  (1×2 matrix)

>> sympy(w)
ans = ImmutableDenseNDimArray(Tuple(true, true), Tuple(Integer(1), Integer(2)))

>> isequal(w, w)
error: cell2mat: C must be a cell array
error: called from
    cell2mat at line 47 column 7
    uniop_bool_helper at line 62 column 11
    isnan at line 51 column 5
    isequal at line 62 column 3

>> isequal(t, t)
ans = 1
cbm755 commented 2 years ago

In uniop_bool_helper:

              'if x is not None and x.is_Matrix:'
              '    # bool will map None to False'
              '    return [bool(sf(a, *pp)) for a in x.T],'

Maybe this should be if x is not None and isinstance(A, (MatrixBase, NDimArray)):.

Or maybe just if isinstance(A, (MatrixBase, NDimArray):. I remember some subtly about is_Matrix versus isinstance() but maybe it was just this explicit None handling...

cbm755 commented 2 years ago

This function also uses linear indexing, similar to #1222.

alexvong243f commented 1 year ago

------- Original Message ------- On Friday, September 2nd, 2022 at 5:03 PM, Colin B. Macdonald @.***> wrote:

Simpler way to hit this:

>> t = sym(true)
>> w = [t t]
pydebug: make_matrix_or_array: making 2D Array...
pydebug: I am here with an array with shape (2, 1)
pydebug: make_matrix_or_array: making 2D Array...
pydebug: I am here with an array with shape (1, 2)
w = (sym) [[True  True]]  (1×2 matrix)

>> sympy(w)
ans = ImmutableDenseNDimArray(Tuple(true, true), Tuple(Integer(1), Integer(2)))

>> isequal(w, w)
error: cell2mat: C must be a cell array
error: called from
    cell2mat at line 47 column 7
    uniop_bool_helper at line 62 column 11
    isnan at line 51 column 5
    isequal at line 62 column 3

Interestingly, this error only occurs when we are using non-Pythonic IPC. To reproduce this error, one has to disable Pythonic IPC.

>> isequal(t, t)
ans = 1

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

alexvong243f commented 1 year ago

Fixed by https://github.com/cbm755/octsympy/pull/1224

alexvong243f commented 1 year ago

------- Original Message ------- On Friday, September 2nd, 2022 at 5:03 PM, Colin B. Macdonald @.***> wrote:

Simpler way to hit this:

>> t = sym(true)
>> w = [t t]
pydebug: make_matrix_or_array: making 2D Array...
pydebug: I am here with an array with shape (2, 1)
pydebug: make_matrix_or_array: making 2D Array...
pydebug: I am here with an array with shape (1, 2)
w = (sym) [[True  True]]  (1×2 matrix)

>> sympy(w)
ans = ImmutableDenseNDimArray(Tuple(true, true), Tuple(Integer(1), Integer(2)))

>> isequal(w, w)
error: cell2mat: C must be a cell array
error: called from
    cell2mat at line 47 column 7
    uniop_bool_helper at line 62 column 11
    isnan at line 51 column 5
    isequal at line 62 column 3

Interesting, this error only occurs when we are using non-Pythonic IPC. To reproduce this error, one has to disable Pythonic IPC.

>> isequal(t, t)
ans = 1

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.