[Bug] Transpose is broken for empty SparseArrays
- To: mathgroup at smc.vnet.net
- Subject: [mg49576] [Bug] Transpose is broken for empty SparseArrays
- From: Scott Morrison <scott at math.berkeley.edu>
- Date: Fri, 23 Jul 2004 06:01:48 -0400 (EDT)
- Reply-to: scott at math.berkeley.edu
- Sender: owner-wri-mathgroup at wolfram.com
I'm running $Version == 5.0 for Microsoft Windows (November 18, 2003) It seems there's a bug in Transpose, when acting on an empty SparseArray. For example, I find that Dimensions[Transpose[SparseArray[{},{1,2}]]] returns {1,2}, rather than {2,1}. For now, I'm using the following as a work-around: If[$VersionNumber\[GreaterEqual]5\[And] Dimensions[Transpose[SparseArray[{},{2,1}]]]\[Equal]{2,1}, Print["Fixing bug in Transpose"]; Unprotect[Transpose]; Transpose[ m_SparseArray]/;(Length[ArrayRules[m]]\[Equal]1\[And] ArrayDepth[m]\[GreaterEqual]2):=Module[{dim=Dimensions[m]}, SparseArray[{},{dim\[LeftDoubleBracket]2\[RightDoubleBracket], dim\[LeftDoubleBracket]1\[RightDoubleBracket]}~Join~Drop[dim,2]] ]; Protect[Transpose]; ] but hopefully someone from Wolfram will see this and let us know about a more permanent solution on it's way? :-) This bug caused some hard to track down problems while migrating a large program from 4.2 to 5.0, so I'm posting it here as a 'heads-up' for everyone else. Scott Morrison
- Follow-Ups:
- Re: [Bug] Transpose is broken for empty SparseArrays
- From: DrBob <drbob@bigfoot.com>
- Re: [Bug] Transpose is broken for empty SparseArrays