Add a New Comment (Rich Markup)
I checked in a final changeset to avoid "! isfinite" in assert.m. See http://hg.savannah.gnu.org/hgweb/octave/rev/84e8f0bf83f7. I'm going to mark this bug as "Won't Fix" since we disagree with Matlab in always converting isfinite output to a full matrix. Closing report.
I used grep to find a list of isfinite instances where the output is negated (and hence could be large if the input were sparse). The instances are
+matlab/+lang/MemoizedFunction.m:134: || ! isfinite (val)) +matlab/+lang/MemoizedFunction.m:140: if (! isscalar (val) || ! isnumeric (val) || ! isfinite (val) ... general/int2str.m:80: nan_inf = ! isfinite (n(:)); general/quadgk.m:374: if (any (! isfinite (q_subs))) general/quadgk.m:450: if (any (! isfinite (q_subs)(:))) general/quadl.m:112: elseif (any (! isfinite (q(:)))) general/quadv.m:154: elseif (any (! isfinite (q(:)))) linear-algebra/cond.m:67: elseif (any (! isfinite (A(:)))) miscellaneous/mustBeInteger.m:53: elseif (any (! isfinite (x))) optimization/glpk.m:526: if (any (! isfinite (b(:)))) optimization/glpk.m:593: || any (! isfinite (sense))) polynomial/roots.m:89: elseif (any (! isfinite (c))) set/uniquetol.m:207: eq_rows(i,1) = eq_rows(i,1) || any (! isfinite (Arow_i), 2); specfun/primes.m:55: if (! isfinite (n) && n != -Inf) testfun/assert.m:351: | ! isfinite (A_null_real) & ! isfinite (B_null_real); testfun/assert.m:362: | ! isfinite (A_null_imag) & ! isfinite (B_null_imag);
Most of these can be ignored because the input can be guaranteed to be small. I changed cond.m and mustBeInteger.m in this changeset: http://hg.savannah.gnu.org/hgweb/octave/rev/303bbdc3c536. The remaining question is whether to change the two instances in assert.m It will require introducing two new temporary variables, making their calculation dependent on whether the input is full or sparse, and then clearing those variables at the end of the block doing this calculation.
I posted this bug report because I wanted other developer opinions. My own opinion matches that of jwe: Matlab made an odd choice to have isfinite return a full matrix. Not only is this inconsistent with similar isXXX functions, but it presumes to know more than the programmer. In this case, the intermediate "isfinite (x)" will be dense but "! isfinite (x)" will be back to being pretty sparse. I think the programmer should make the decision here. If they want a full matrix they can use full(), otherwise it stays as it's original type. As another example, would you expect a function to convert a single data type to a double data type without the consent of the programmer?
the fix was related to this problem identified through the help mailing list: https://lists.gnu.org/archive/html/help-octave/2022-10/msg00011.html
I'm guessing your input to `glpk` is sparse. Line 507 of `glpk.m` uses: if (any (! isfinite (A(:)))) error ("glpk: The values in A must be finite"); endif `isfinite (A(:))` creates a sparse Boolean matrix. However, it is likely not sparsely populated which might be the cause for the memory issue. Does it work if you edit that file and change the above lines to the following? if (any (isinf (A(:))) || any (isnan(A(:)))) error ("glpk: The values in A must be finite"); endif
that turned out to solve the problem for that user, and so was pushed as a potential fix to prevent reoccurrence.
I can understand converting to full for any function that will return true for an input of 0 since that is guaranteed to turn a very sparse matrix into something that is mostly filled with non-zero entries. But the same would happen for "sparse_matrix == 0", and I don't think that operator gets the same special treatment. If I'm right about that, then maybe this is a candidate for tagging as "WTF, Matlab".
In changeset 800eb86438cc a modification was made to avoid using isfinite() on sparse input. I'm not sure what problem that was addressing, but it did lead me to find a difference between Octave and Matlab. Sample code: MATLAB
x = sparse ([Inf, 1; 2 NaN]); isfinite (x) ans = 2x2 logical array 1 0 0 1
Octave
ans = Compressed Column Sparse (rows = 2, cols = 2, nnz = 2 [50%]) (2, 1) -> 1 (1, 2) -> 1
I don't know if we want to follow Matlab or not. It seems like this is inconsistent with isinf() and isnan() functions which do return a sparse output for sparse input in Matlab. Octave is arguably being correct here by keeping that pattern.
(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)
Attach Files: Comment:
No files currently attached
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Only project members can vote.
Please enter the title of George Orwell's famous dystopian book (it's a date):
Follow 3 latest changes.
Copyright © 2023 Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. The Levitating, Meditating, Flute-playing Gnu logo is a GNU GPL'ed image provided by the Nevrax Design Team. Source Code
Powered by Savane 3.11