473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Generic matrix operators

I want to write generic operators for
matrix computation which would adapt to different types (shapes) of matrices
i.e. when
adding square matrix and lower triangle matrix it would add only elements on
and
under main diagonal and copy the rest from square matrix. Basically it would
allow adding new matrix type (shape) without writing new operators. Here is
the
code I hope could do that:
//Matrix Trait
//ret depends on matrix shape
template <int r, int c, class Matrix>
struct IsZero
{
enum { ret = false };
};

class LowerTriangMatrix;
//all elements above main diagonal in LTM are 0
template <int r, int c>
struct IsZero<r, c, LowerTriangMatrix>
{
enum { ret = (c > r) ? true : false; };
};
//expresion tree node
template <class Lhs, class OpTag, class Rhs>
struct Expression
{
typedef Type typename Lhs::T;
Expression(Lhs const& lhs, Rhs const& rhs)
: l(lhs), r(rhs)
{
}
template <int row, int col>
Type Apply(/*unsigned row, unsigned col*/) const
{
return IsZero<row, col, Lhs>::ret ?
IsZero<row, col, Rhs>::ret ?
(Type)0 : OpTag<Type>::Apply((Type)0, r(row,col))
: IsZero<row, col, Rhs>::ret ?
OpTag<Type>::Apply(l(row,col), (Type)0)
: OpTag<Type>::Apply( l(row, col), r(row,col) );
}
Lhs const& l;
Rhs const& r;
};

//OpTag
template <typename Lhs>
struct Plus
{
static Lhs Apply(Lhs& lhs, Lhs& rhs)
{
return lhs + rhs;
}
};
And the question is can this be done? And can I do it this way? I'll be
really
grateful for any suggestion/advice.
Best regards,
Zoran Stipanicev
Jan 7 '06 #1
2 2087
Stipanicev wrote:
I want to write generic operators for
matrix computation [..]


Zoran,

With all due respect to your effort, this is not a chat room,
not an IRC channel, you cannot expect answers to such a complex
topic sometimes even within a day. Have patience, please. If
somebody sees that your post has gone unanswered, perhaps they
will spend time needed to study it and to figure what to tell
you. We all are busy with our lives (however unlikely that
might seem from our participation here), and your inquiry does
require some thought. I assure you, most of regulars here do
read all the posts and do try to assist those in need.

Thank you for your trust in the community and your understanding.

V
Jan 7 '06 #2
zs
Hi!

I agree with You Victor, and I apologize for my impatience.
And as I said before I would be very grateful for any advice/suggestion
(even the short one's like "it's not possible" or "it's
possible but not meaningful").

Best regards,
Stipanicev.

Jan 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ben | last post by:
Hi, I was writing a expression template for string concatenation latetly. When writing it, I started to feel curious that why there's not any generic et lib that can save me from wring each...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.10.2004 Hello, As far as I understand, the generic programming basically consists in using templates for achieving a static polymorphism of the various code fragments, and their...
13
by: Charulatha Kalluri | last post by:
Hi, I'm implementing a Matrix class, as part of a project. This is the interface I've designed: class Matrix( )
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
0
by: Zoran Stipanicev | last post by:
Hi! The question is product of laziness. I want to write generic operators for matrix computation which would adapt to different types of matrices i.e. when adding square matrix and lower...
5
by: Anolethron | last post by:
Wrong one: void minptr (int *matrix, int rows, int columns,int *min){ int i=0,j=0; *min=*matrix; //!!!!!!!!!!!!!!!!! for (i=0; i < rows; i++) { for (j=0; j < columns; j++) { if( *min...
2
by: Encrypted | last post by:
i am working with a matrix manipulation program...consists of a matrix class and its member functions.. i have also overloaded << and >>...so dat dey can read and print d whole matrix at one...
6
by: Harinezumi | last post by:
Hello, I created a template matrix class and some appropriate binary operators like: template <typename ContainedType> Matrix<ContainedType> operator+ (const Matrix<ContainedType>& lhs,...
1
by: haderika | last post by:
Hey, I'm having trouble overloading the ~ operator (the determinant of the matrix) in a case of 2x2 matrices. So i have a matrix class, with the constructor, overloading +, += and ~ operators. the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.