octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #63281] bsxfun fails to preserve sparse output


From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #63281] bsxfun fails to preserve sparse output for some functions
Date: Mon, 31 Oct 2022 00:40:16 -0400 (EDT)

Follow-up Comment #16, bug #63281 (project octave):

in the interest of restoring some performance gain of avoiding bsxfun and
maybe preserving the sparseness:

looking for example at center.m, instead of the current:

## FIXME: Use bsxfun, rather than broadcasting, until broadcasting
##        supports diagonal and sparse matrices (Bugs #41441, #35787).
y = bsxfun (@minus, x, mean (x, dim));
## y = x - mean (x, dim);   # automatic broadcasting


would something like this be acceptable?: 


try
  y = x - mean (x, dim);   # automatic broadcasting
catch err
  if any (strcmp (typeinfo (sparse (x)), ...
                  {"sparse matrix", "diagonal matrix"}))
    ##  y = bsxfun (@minus, x, mean (x, dim)); faster, but loses sparseness
    y = bsxfun(@(x,y) x-y, x, mean(x, dim)); # preserves sparseness
  else
    rethrow(err);
  endif
end_try_catch



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63281>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]