MathGroup Archive 2009

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

Search the Archive

Re: sparsearray bug?

  • To: mathgroup at
  • Subject: [mg101497] Re: [mg101477] sparsearray bug?
  • From: Leonid Shifrin <lshifr at>
  • Date: Thu, 9 Jul 2009 01:52:27 -0400 (EDT)
  • References: <>


This seems indeed to be a bug. Here is what I think is the reason.

In[1] = SparseArray[{1}] // FullForm

Out[1] =

Look at the third element (zero). This is a default element, which is filled
for any position missed in explicit rules (when SparseArray is defined from
a set of rules position->value).

Now, in that latter case (when at least one default element is present),
it makes sense to apply whatever Listable operation is applied to an entire
array (Power[x,-1] in this case) also to the default element - but this
not be done in cases when all elements are indicated explicitly (and so the
default element substitution  does not actually take place). Let us change a
default element to 1 in the FullForm:

In[2] =

Out[2] = SparseArray[<1>,{1},1]

In this case, no error message:

In[3] =

Out[3] = SparseArray[<1>,{1},1]

In[4] = Normal[%]

Out[4] ={1}

Now, we can convince ourselves that the bug is indeed related to applying
an inverse (in this case, but this may be a more general problem)  to the
default element:

In[5]:= Normal[1/SparseArray[{1->1,2->2,4->5}]]

During evaluation of In[5]:= Power::infy: Infinite expression 1/0
encountered. >>

Out[5]= {1,1/2,ComplexInfinity,1/5}

Here the behavior was correct, since the default is present. However, I
would bet that the actual place where this message was generated isn't
correct - I am almost certain that it was generated before default element
substitution actually took place (but this only WRI could confirm). Now:

In[6]:= Normal[1/SparseArray[{1->1,2->2,3->4,4->5}]]

During evaluation of In[6]:= Power::infy: Infinite expression 1/0
encountered. >>

Out[6]= {1,1/2,1/4,1/5}

Here it was incorrect (in terms of error message generation at least), since
the default wasn't ever used.

Now we change the default to 1:

In[7]:= Normal[1/SparseArray[{1->1,2->2,3->4,4->5,{_}->1}]]

Out[7]= {1,1/2,1/4,1/5}

and get no error message. Here also the default wasn't actually used.
This seems to support my conjecture.

Hope this helps.


On Wed, Jul 8, 2009 at 4:11 AM, wpb <w.p.bergsma at> wrote:

> In[494]:= SparseArray[{1}]/SparseArray[{1}]
> During evaluation of In[494]:= Power::infy: Infinite expression 1/0
> encountered. >>
> During evaluation of In[494]:= \[Infinity]::indet: Indeterminate expression
> 0 ComplexInfinity encountered. >>
> Out[494]= SparseArray[<1>,{1},Indeterminate]

  • Prev by Date: Jens-Peer Kuska
  • Next by Date: Re: Jens-Peer Kuska passed away
  • Previous by thread: sparsearray bug?
  • Next by thread: Re: sparsearray bug?