Math Libraries (and vectors, matrices, etc)

sclytrack sclytrack at hotmail.com
Tue Mar 13 13:30:46 PDT 2012


On 03/13/2012 09:06 PM, Dmitry Olshansky wrote:
> On 14.03.2012 0:03, H. S. Teoh wrote:
>> On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote:
>>> Does D have a math library that defines, points, vectors and
>>> matrices including the appropriate functions(addition, dot product,
>>> cross product, etc)?
>>
>> I'd like to know too.
>>
>> I have a medium-sized D project in the works, but right now I'm stuck at
>> deciding how best to represent matrices and vectors in a generic way. My


struct CMatrix(T)			//CMatrix
{
	T [] data;
	size_t rows;
	size_t cols;
	size_t rowStep;

	Stride(T) row()
	{
	}

	T [] rowArray()
	{
	
	}
	
	//no colArray

}


struct LMatrix(T)			//Lapack Matrix
{
	T [] data;
	size_t rows;
	size_t cols;
	size_t colStep;
}


Above are "storage types" of the matrix. They can be rectangular or 
triangular.

I'd move the "matrix shape" to the operation. Because most of the time
you already know the shape.

aadd_upperTriangular_upperTraingular( result, a, b);


So the operation for the upperTriangular "shape" can be applied to the 
generic rectangular "storage" type. I know nobody likes the underscore 
syntax but I can't come up with anything else.

Also separate the Lapack Matrix from the conventional CMatrix in other 
modules.

I'd stick to conventional routines for adding subtracting and not the 
build in binary operators like +.

-----

In scid the colStep or leading address of a is an alias. I think this 
should not be so.



>> usage will be significantly different from game programming, though,
>> 'cos I'll be dealing with arbitrary-dimensioned vectors and matrices,
>> not just your typical 2D/3D vector (or 4D homogenous).
>>
>> But it'd be nice if both can be handled generically without crippling
>> performance losses in the 2D/3D case for game dev.
>>
>>
>> T
>>
>
> SciD worths a look, though never used nor had the need to:
> https://github.com/kyllingstad/scid
>



More information about the Digitalmars-d-learn mailing list