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: Thu, 27 Oct 2022 14:16:12 -0400 (EDT)

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

                 Summary: bsxfun fails to preserve sparse output for some
functions
                 Project: GNU Octave
               Submitter: nrjank
               Submitted: Thu 27 Oct 2022 02:16:10 PM EDT
                Category: Octave Function
                Severity: 2 - Minor
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: Nicholas Jankowski
        Originator Email: 
             Open/Closed: Open
                 Release: dev
         Discussion Lock: Any
        Operating System: Any


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Thu 27 Oct 2022 02:16:10 PM EDT By: Nicholas Jankowski <nrjank>
noticed in center.m (from bug #51249) that bsxfun was used to prevent sparse
inputs from triggering nonconformance errors from automatic broadcasting (see
bug #41441). It appears that change results in center.m always outputting a
full matrix with sparse inputs, due to bsxfun using @minus. It seems whether
or not bsxfun preserves sparseness depends on the underlying operation, but
not sure how/why. checking with other functions:

plus:

>> bsxfun(@plus, sparse([0 1 0 1 0 1]), 1)
ans =
   1   2   1   2   1   2

>> bsxfun(@plus, sparse([0 1 0 1 0 1]), sparse(1))
ans =
   1   2   1   2   1   2

>> bsxfun(@plus, sparse([0 1 0 1 0 1]), sparse([0 1 0 1 0 1]))
ans =
   0   2   0   2   0   2

>> plus(sparse([0 1 0 1 0 1]), sparse([0 1 0 1 0 1]))
ans =
Compressed Column Sparse (rows = 1, cols = 6, nnz = 3 [50%])

  (1, 2) -> 2
  (1, 4) -> 2
  (1, 6) -> 2

>> plus(sparse([0 1 0 1 0 1]), sparse([1]))
ans =
Compressed Column Sparse (rows = 1, cols = 6, nnz = 6 [100%])

  (1, 1) -> 1
  (1, 2) -> 2
  (1, 3) -> 1
  (1, 4) -> 2
  (1, 5) -> 1
  (1, 6) -> 2


but an anonymous addition function seems fine:


>> bsxfun(@(x,y) x+y, sparse([0 1 0 1 0 1]), sparse([0 1 0 1 0 1]))
ans =
Compressed Column Sparse (rows = 1, cols = 6, nnz = 3 [50%])

  (1, 2) -> 2
  (1, 4) -> 2
  (1, 6) -> 2



While AND seems to have no issues:

bsxfun(@and,sparse([0 1 0]), 1)
ans =

Compressed Column Sparse (rows = 1, cols = 3, nnz = 1 [33%])

  (1, 2) -> 1

>> bsxfun(@and,sparse([0 1 0]), [1 1 1])
ans =
Compressed Column Sparse (rows = 1, cols = 3, nnz = 1 [33%])

  (1, 2) -> 1

>> bsxfun(@and,sparse([0 1 0]), sparse([1 1 1]))
ans =
Compressed Column Sparse (rows = 1, cols = 3, nnz = 1 [33%])

  (1, 2) -> 1

>> and(sparse([0 1 0]),1)
ans =
Compressed Column Sparse (rows = 1, cols = 3, nnz = 1 [33%])

  (1, 2) -> 1

>> and(sparse([0 1 0]),sparse(1))
ans =
Compressed Column Sparse (rows = 1, cols = 3, nnz = 1 [33%])

  (1, 2) -> 1

>> and(sparse([0 1 0]),sparse([1 1 1]))
ans =
Compressed Column Sparse (rows = 1, cols = 3, nnz = 1 [33%])

  (1, 2) -> 1


ran into this specifically with @minus and @rdivide.  realize there are
thousands of potential functions that could behave either way. I recognize
that automatic broadcasting and sparse/diag arrays are a known issue, but does
anyone familiar with bsxfun have an idea of why it's so inconsistent?







    _______________________________________________________

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]