MathGroup Archive 2008

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

Search the Archive

Re: Implementing a array assignment for custom data structure

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88909] Re: Implementing a array assignment for custom data structure
  • From: Salvatore Mangano <smangano at into-technology.com>
  • Date: Wed, 21 May 2008 14:48:54 -0400 (EDT)

Thanks, but that is not my problem. Think of my problem like this. Imagine Mathematica did not have SparseArray and someone wanted to implement it themselves. It is clear that you could get array access to work for your custom implementation using UpValues:

SparseArray /: Part[SparseArray[a___], index_Integer] := sparseGetFunction(a, index)

However it is not obvious how to get this to work for Set using either Up or Down values. If you try:


Set[Part[SparseArray[a___], index_Integer], value_] := 
	sparseSetFunction(a, index,value)

It will not work with:

myArray = SparseArray[{{1} -> 10, {30} -> 15}]

myArray[[2]] = 15

because Set (=) does not evaluate its first argument so Mathematica will not match the pattern and invoke sparseSetFunction.


  • Prev by Date: Help with find root needed
  • Next by Date: Plotting a series of piecewise functions
  • Previous by thread: Re: Implementing a array assignment for custom data structure
  • Next by thread: Re: Implementing a array assignment for custom data structure