7
$\begingroup$

fixed in 10.0.2


This sure looks like a bug to me (Mathematica 10.0.0, MacOS):

(Local) In[345]:= s = SparseArray[{}, {20}, 1]

(Local) Out[345]= SparseArray[< 0 >, {20}, 1]

(Local) In[346]:= s // Normal

(Local) Out[346]= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}

(Local) In[347]:= s[[All]] = 1; s

(Local) Out[347]= SparseArray[< 0 >, {20}]

(Local) In[348]:= s // Normal

(Local) Out[348]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Apparently when I assigned 1 to all elements of s, it correctly realized that everything was still equal to the default, so left everything unspecified. But it incorrectly lost the 1 default value and changed the array to have the default default value of 0.

This is a toy example, but it comes out of a more complicated example in which it is causing me a serious problem. I don't know the full scope of the problem, but it is not necessary to assign to the entire array for the default value to be lost. I guess the lesson is that non-zero defaults are fragile.

Is this really a bug, or am I missing something obvious?

$\endgroup$
  • $\begingroup$ on version 9, I get same thing. I think it has to do with the way you build it in first place. Compare to data = Table[1, {20}];s = SparseArray[data]; s[[All]] = 1; s // Normal and now it is ok. $\endgroup$ – Nasser Jul 17 '14 at 20:05
  • $\begingroup$ Yes, but in that case the default value is 0 from the start. Compare to data = Table[1, {20}]; s = SparseArray[data, Automatic, 1]; s[[All]] = 1; s // Normal, where the SparseArray is created with default 1. The same problem occurs. $\endgroup$ – Leon Avery Jul 17 '14 at 20:16
  • 1
    $\begingroup$ Looks like a bug to me $\endgroup$ – Rojo Jul 17 '14 at 20:24
  • 1
    $\begingroup$ That is a bug and I filed it as such. Thanks for bringing it up. $\endgroup$ – user21 Jul 18 '14 at 6:59
  • 3
    $\begingroup$ As a side note, once can use s["Background"] to get access to the background element. $\endgroup$ – user21 Jul 18 '14 at 7:03
3
$\begingroup$

Fixed in 10.0.2, windows 7, 64 bits

Mathematica graphics

Mathematica graphics

$\endgroup$
  • $\begingroup$ Awesome! Thanks. :-) $\endgroup$ – Leon Avery Dec 11 '14 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.