Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Bug introduced in 5.2 or earlier and fixed in 10.1.0


This is another question on the design choices in Mathematica. I understand that without direct reply from the developers it may not be possible to give a definitive and exhaustive answer to "why" questions but such topics have often been fruitful.


Why does list assignment of the form {a, b, c} = tensor where tensor is packed result in unpacked values for a, b, and c?

To illustrate:

packedQ = Developer`PackedArrayQ;

tensor = RandomReal[99, {3, 5, 7}];

tensor // packedQ

True

{a, b, c} = tensor;

packedQ /@ {a, b, c}

{False, False, False}

It is possible to make the assignments without unpacking the sub-arrays of tensor by manually unpacking the outer list using Apply:

{a, b, c} = List @@ tensor;

packedQ /@ {a, b, c}

{True, True, True}

Why doesn't Set operate like this by default?

That is, why doesn't Set only unpack the right-hand-side as far as necessary, to the level of the left-hand-side?

share|improve this question
    
Your question raises another in my mind: since tensor already has the head List, why does List @@ tensor have any effect on Set at all, considering it's evaluated before Set even sees it? –  m_goldberg Jul 22 '13 at 19:58
2  
@m_goldberg Because Apply does unpack the top level of the packed array. It does it always, even if the head to be applied is also a List. –  Leonid Shifrin Jul 22 '13 at 22:59
    
@LeonidShifrin. So, although it's not his main point, one thing Mr.Wizard is telling us is that when Set is given tensor with its top-level unpacked, the lower levels will not be disturbed. –  m_goldberg Jul 23 '13 at 2:16
    
@m_goldberg Yes, that is what I tried to express that with the final example given. Another way to look at this problem is that apparently when Set gets a packed array on the RHS and a list on the LHS, it fully unpacks the RHS rather that only unpacking it to the level of the LHS. This seems like an unfortunate choice, but I have often learned that there are good reasons for such choices once I asked about them. –  Mr.Wizard Jul 23 '13 at 3:19
1  
@MichaelE2 I would agree that the special case of List was probably considered not important. In fact, the only reason one would want to do List @@ packed would be if one wants to unpack one level. It also seems to be the only way to do this (i.e. using Apply), if one wants to only unpack one level. –  Leonid Shifrin Jul 23 '13 at 9:10

1 Answer 1

up vote 7 down vote accepted

Thanks Mr.Wizard. I've filed a bug for this, #288440 if you have future correspondence with people inside the company about it...

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  m_goldberg Feb 9 at 19:23
    
@m_goldberg Do you think it is reasonable to make an exception for the developers of Mathematica? Given at least some implied authority here this is a form of answer. –  Mr.Wizard Feb 9 at 20:04
4  
@m_goldberg, since Taliesin has filed a bug one might argue that the question has been answered, albeit indirectly. Why does Mathematica do this? Because it has a bug. (As opposed to it being a deliberate design choice). –  Simon Woods Feb 9 at 22:22
3  
Aside from these meta comments, this has been fixed. Should be in the next release. –  Taliesin Beynon Feb 10 at 4:15
1  
@Mr.Wizard unless we want to decide how many angels can dance on the head of a pin, let's just call it a bug :) –  Taliesin Beynon Apr 22 at 5:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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