MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sparsearray bug?

  • To: mathgroup at
  • Subject: [mg101663] Re: sparsearray bug?
  • From: Bill Rowe <readnews at>
  • Date: Tue, 14 Jul 2009 05:32:11 -0400 (EDT)

On 7/12/09 at 5:48 AM, wicher.bergsma at (wpb) wrote:

>Dividing a SparseArray by another can be needed eg in the following
>situation: A is a sparse matrix, b and c nonsparse vectors and we
>want to compute A.(b/c). Seems to be best to numerically to put
>everything in SparseArray form I think...

Why? I very much doubt computing b/c for two non-sparse vectors
will execute faster when b and c are made into SparseArray
objects than the obvious solution.

The advantage of a SparseArray over a normal implementation
comes from not needing to specifically store the zero elements.
If all of the elements of an array are non-zero, the storage
requirements for a the SparseArray form will be higher than the
simple list form. And whether b and c are SparseArray objects or
not, each element of b and c needs to be accessed to compute
b/c. It is hard to see how having b and c as SparseArray objects
could reduce the execution time.

The only reason I can see for not mixing SparseArray objects
with normal lists would be if Mathematica did not allow this. But

In[22]:= s =
   SparseArray[Thread[Table[{n, n}, {n, 5}] -> RandomReal[1, {5}]]];
s.RandomInteger[100, {5}]

Out[23]= {24.3707,25.5166,5.77052,23.7288,15.5728}

clearly demonstrates it is acceptable to mix SparseArray objects
with normal lists.

  • Prev by Date: ParallelTable doesn't work, but Table does
  • Next by Date: Re: Plot Label at bottom with quote marks
  • Previous by thread: Re: sparsearray bug?
  • Next by thread: Manipulating list