Vectors and matrices

Lars Kyllingstad public at kyllingen.NOSPAMnet
Wed Apr 15 23:45:11 PDT 2009


JC wrote:
> I do a lot of linear work with economic models in D at work. For this 
> reason I created small matrix and vector package that makes use of the 
> ATLAS library. Most of the time I don't know the sizes of the matrices 
> and vectors that I am working with until runtime. Because of this and to 
> keep the memory contiguous, the backend of my package is implemented as 
> a dynamic single dimensional array.

Is your library available online? It would be helpful to be able to take 
a look at it.


> Because of this and the fact that static arrays cannot exceed 16Mb 
> (according to the D1 docs), I would suggest just working with 
> opIndex(i,j) instead of the arrays themselves.
> 
> Just my 2 cents,
> JC
> 
> Lars Kyllingstad wrote:
>> I am writing a D library based some of the stuff in SLATEC, and I've 
>> come to a point where I need to decide on a way to manipulate vectors 
>> and matrices. To that end, I have some ideas and questions I would 
>> like comments on from the community.
>>
>> Ideally, I want to restrict the user as little as possible, so I'm 
>> writing heavily templated code in which one can use both 
>> library-defined vector/matrix types and built-in arrays (both static 
>> and dynamic). My reasons for this are:
>>
>>    a) Different problems may benefit from different types. Sparse 
>> matrices, dense matrices, triangular matrices, etc. can all be 
>> represented differently based on efficiency and/or memory requirements.
>>
>>    b) I hope that, at some point, my library will be of such a quality 
>> that it may be useful to others, and in that event I will release it. 
>> Interoperability with other libraries is therefore a goal for me, and 
>> a part of this is to let the user choose other vector/matrix types 
>> than the ones provided by me.
>>
>>    c) Often, for reasons of both efficiency and simplicity, it is 
>> desirable to use arrays directly.
>>
>> My first question goes to those among you who do a lot of linear 
>> algebra in D: Do you think supporting both library  types and arrays 
>> is worth the trouble? Or should I just go with one and be done with it?
>>
>>
>> A user-defined matrix type would have opIndex(i,j) defined, and to 
>> retrieve elements one would write m[i,j]. However, the syntax for 
>> two-dimensional arrays is m[i][j], and this means I have to put a lot 
>> of static ifs around my code, in order to check the type every time I 
>> access a matrix. This leads me to my second question, which is a 
>> suggestion for a language change, so I expect a lot of resistance. :)
>>
>> Would it be problematic to define m[i,j,...] to be equivalent to 
>> m[i][j][...] for built-in arrays, so that arrays and user-defined 
>> types could be used interchangeably?
>>
>> (And, importantly, are there anyone but me who think they would 
>> benefit from this?)
>>
>>
>> -Lars



More information about the Digitalmars-d mailing list