>>>>Hello - Unfortunately vfp software doesn't let me create a square sparse matrix (as is doing - for example Matlab software); because I need to overcome the limit of 65,000 memory variables (even double ...) , I'm looking for a solution - anyone has a idea - it is welcome. Thanks in advance for your help, bye, Sorin
>>>
>>>
>>>(1) Use Collections - the key would be the string of the index
>>>For mulitdimension you'll need to add other collecttions
>>>
>>>This becomes a bit messy
>>>
>>>(2) If all elements are the same type, use SafeArray
>>>SafeArrays are allocated by windows
>>>
>>>
http://msdn.microsoft.com/en-us/library/ms221145(v=VS.85).aspx>>>
>>>- SaveArrayCreate() or SafeArrayCreateEx() for structures
>>>You can specify the number of dimensions and the lower/upperbounds for each dimension
>>>
>>>- SafeArrayCreateVector() for one dimensional arrays
>>>
>>>- SafeArrayDestroy() when you no longer need it
>>>
>>>
>>>- SafeArrayPutElement () to assign a value to an element
>>>- SafeArrayGetElement() to get the contents fo an element
>>>
>>>
>>>
>>>(3) a Cursor may be the simplest way
>>
>>I like the cursor idea:
>>
>>PrimaryKey XSubscript YSubscript (ZSubscript...) Value
>>
>> 1 1 1 ... 42
>> ...
>>
>>Completely sparse "array" with up to about 250 "dimensions", if you want. Easy to insert/remove elements as needed.
>
>
>I think you don't need a primary key field like you wrote
Strictly speaking, you don't, for this example, but I threw it in from force of habit :) If it's just access to elements you want, then you don't need it. But, having elements in a cursor invites use of SELECT - SQL and advanced data munging. Much more often than not, I've had to retrofit data processing cursors/tables to add a primary key, when munging requirements got (inevitably) more complex.
>You need direct access given - say - x[1, 2, 3, 4, 5], ie you need to transform (1,2,3,4,5) into a (unique) key
>max key length = 240
>Max dimensions. If you bintoc(XSubscript , 2) = 120
>Max dimensions. If you bintoc(XSubscript , 4) = 60
If you're willing to accept those restrictions that's probably the highest performance. Another option would be to create individual index tags per subscript column. Then you could access elements:
FUNCTION GetElement
LPARAMETERS ;
tcCursorName ;
, tnSubscript1 ;
, tnSubscript2 ;
, ...
SELECT ;
Value ;
FROM Elements ;
WHERE Elements.XSubscript = tnSubScript1 ;
AND Elements.YSubscript = tnSubScript2 ;
... ;
INTO CURSOR ( tcCursorName )
Requires Rushmore to do one index lookup per subscript column. However, avoids any overhead with BINTOC() conversion(s) you would need for a single-lookup SEEK.
>
>Same philosophy as the cursor - you could use one collection with keys eg bintoc(i) + bintoc(j) + bintoc(k) + bintoc(l) + ......
>I do not think there's a limit on the key size of a collection
>
>Downside - to modify an existing element, either
> - remove and re add it
>- work with objects - their properties can be modified directly - but you have one extra object per element
Regards. Al
"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov
Neither a despot, nor a doormat, be
Every app wants to be a database app when it grows up