Boost logo

Ublas :

From: Garret McGraw (gmcgraw_at_[hidden])
Date: 2008-07-23 11:18:51


Nizar Khalifa Sallem wrote:
> Garret McGraw wrote:
>> Hi,
>>
>> I've looked around at the wiki and previous mailing list posts and I
>> cannot find the answer to my question there. What I need to do is
>> define a custom class and set it to be stored in a matrix such as:
>>
>> matrix<MyCustomClass> mat1(300, 300);
>>
>> And then it must be able to be multiplied by another matrix of a
>> different type.
>>
>> matrix<MyCustomClass2> mat2(300, 300);
>>
>> Then I want to be able to take the product of the two matrices have
>> have it go into another matrix of a third type:
>>
>> matrix<MyCustomClass3> mat3(300, 300);
>>
>> mat3 = prod(mat1, mat2);
>>
>> Now I have defined operators to multiply MyCustomClass*MyCustomClass2
>> and return MyCustomClass3 and also the operator MyCustomClass3 +=
>> MyCustomClass3
>>
>>
>> Is there any other operators that I must define for this to compile?
>> Is this even possible with ublas?
>>
>> Thanks in advance,
>> -Garret
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
> You need to redefine opertaor (row, col) and prod() I guess since
> there are some product that only prod can handle ot opertaor * besides
> you have to make operator (row, col) return also references on your
> matrixes elements.
> That's where I can go so far with my experience of ublas, may be
> others could help better.
>
> ----------
> Regards
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
Thanks so much for your quick response!

I think if I redefine prod(), it will mean I must program my own matrix
multiplication algorithm and that's one of the reason that I like ublas
is because of its efficient matrix multiplication algorithm.
I guess my question is: what operators must I define to accommodate
ublas prod() or how do I go about making ublas treat my types(classes)
just as if they were multipliable, addable objects just like an integer
or a double.

-Garret