473,734 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 LowerTriangMatr ix;
//all elements above main diagonal in LTM are 0
template <int r, int c>
struct IsZero<r, c, LowerTriangMatr ix>
{
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>::Ap ply((Type)0, r(row,col))
: IsZero<row, col, Rhs>::ret ?
OpTag<Type>::Ap ply(l(row,col), (Type)0)
: OpTag<Type>::Ap ply( 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 2099
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
1703
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 different et lib from scratch. Or, maybe I was just ignorant and there is some already? matrix, string, array, vector, whatever, the idea of et is quite similar. We need a leaf node and a binary non-leaf node for expressing
4
4428
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 reuse for various template parameters. I wonder if there exist techniques for achieving a dynamic polymorphism using the generic programming. Is this possible? If yes, can anyone show me simple examples in C++
13
16723
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
3321
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 way they are. ***** Summary & Questions ***** In a nutshell, the current .NET generics & .NET framework make it sometimes difficult or even impossible to write truly generic code. For example, it seems to be impossible to write a truly generic
0
1384
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 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 (I'm to lazy
5
9638
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 *(matrix+(i*columns)+j) ) { min = (matrix+(i*columns)+j);
2
2577
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 statement.. the code of these overloaded operators is something like this.. // for >> (cin) : istream& operator >> (istream &read, matrix &mat) { for (int i = 0; i < mat.rows * mat.columns; ++i) read >> *(mat.element+i);
6
3934
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, const Matrix<ContainedType>& rhs) { ... } The first line of each such binary operator is a check, like:
1
4458
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 first two are working but I don't know how to overload the ~ one. here's what I have: matrix matrix::operator~(matrix &m) { double x; x=(m.a11*m.a22)-(m.a12*m.a21); return x; of course it's not working cause i can't return a double value...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.