Small vector and matrix proposed for phobos2 now on github

Gareth Charnock gareth.tpc at gmail.com
Mon Apr 26 14:34:10 PDT 2010


bearophile wrote:
> Gareth Charnock:
> 
>> http://github.com/gcharnock/phoboslinalgebra
> 
> I think that a single module is better. If seen fitting, some functionality can be moved inside other already present modules of Phobos.
> The module will need a good amount of unit tests.
> 
> In the code I see no point in calling functions like:
> CTFENextToken
> Just call them:
> nextToken
> Note: functions, template functions, and ctfe functions, start with a lower case letter (and templates generally with with an upper case).
> 
I should probably make this private as I don't see them being generally 
useful.

> Don't call this module and its contents matrix or vector or Vector, etc. Call them SmallVector, or SmallVec, SmallMat, ecc, because this lib is not designed to be a general purpose matrix or vector lib, it's designed for small number of items.
> You can call this module std.tinyarray :-)
> 
Good idea although I'm not sure tinyarray is a good name and I wouldn't 
look there for vectors and matrices. std.tinylinalg comes off as a mess 
of letters.

> 
>> alias Matrix!(float,3) matrix_t;
> 
> To define the sizes of a matrix you need two numbers:
> alias Matrix!(float, 3, 5) Matrix35;
> 
Fair enough.
> 
>> //Very natural initialisation
>> auto m=matrix_t(1,2,0,0,1,0,0,3,1);
> 
> A 1D initialization of a matrix is not so natural :-)

It is in emacs, which will align the statement like this:
auto m=matrix_t(1,2,0,
		0,1,0,
		0,3,1)

But point taken, there needs to be other ways of initialising.

> 
>> //No matter how big N, elements always have a canonical name (probably 
>> more important for matrices where the letters of the alphabet run out 
>> faster although I've only done this for vectors so far)
> 
> What's the point of giving names to matrix elements?

Ease of access, just in case you need it. Also stuff like:
vector3 translate = m.a30a31a32;
Most of the metaprograming is already done so it might as well be reused.
(Actually that's so common it could do with its own function.)

> 
>> 2) Set a bool. Switch between two element iteration schemes for nearly 
>> every operation (with suitable use of templates this might not be as 
>> painful as it sounds.)
> 
> The point of a transposition is sometimes to actually have data in a different position. With cache effects the position of data can be quite important (a matrix multiplication can be 2 or 3 times faster if you transpose. This is true for larger matrices).

Which is why using this design will increase the complexity of the code 
a fair bit. I'm not a fan of 2 because I'd prefer a value type. However 
I want to check I'm not alone (as I appear to be on the definition of * 
for vectors).

> 
>> Transposed:
>> 1) makes a new matrix
>> 2) creates a transposed image which is forever linked to the original 
>> matrix: A=B.Transpose() => Changes to A affect B
> 
> The semantics of transpose/transposed can be like in Python: the transpose works in-place, transposed creates a new matrix.

Sorry, should have read A=B.Transposed() => A becomes linked to B, 
changes to A affect B.

> Methods and properties like transpose have to start with a lowercase:
> auto A = B.transposed;

I'll try to be more consistent.

> Bye,
> bearophile


More information about the Digitalmars-d-announce mailing list