473,748 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

questions regarding class

Hi,

I am not sure whether I describe the subject correctly.

What I want to do is for a matrix class

---------------------------
class CMatrix
{
private:
size_t m, n;
double **nodes;

private:
bool checkSize(...); // check size and initialization if needed.

public:
CMatrix operator + (const CMatrix& m1);
CMatrix operator += (const CMatrix& m1);
......
}

CMatrix CMatrix::operat or+(const CMatrix& m1)
{
CMatrix res(m1);
for ....

return res;
}
-----------------------------

If I need to perform a lot of addition and use + (discarding += first,
since I want to write something like a+b+c-2*d...), then the program
will do a lot of memory allocation and release (for instantiation of
"res" in "+"). I want to know:

1. is the instantiation of class fast or not? (compared with some math
operations, e.g., one + between two double values).
for memory allocation, I use:
nodes = new double*[m];
for (size_t i=0; i<m; i++) nodes[i]=new double[n];

2. is it good or not to set up a global variable for the above "res" so
that I can skip the instantiation part? (suppose the memory size is not
a problem)

3. how to do (2)? I think about static member:
static CMatrix _mattmp;
do I need to put this inside the class or outside?

Thanks a lot!

Regards,
X
Sep 16 '05 #1
2 1331
xuatla wrote:
Hi,

I am not sure whether I describe the subject correctly.

What I want to do is for a matrix class

[snip]

Don't roll your own code unless you absolutely have to.

a) Numerical linear algebra is *hard*: algorithms that you might recall from
your college linear algebra class routinely run into trouble because
numbers on a computer like double simply do not obey nice mathematical
rules. (Small determinants or bad choices for pivots can completely
obliterate a matrix inversion).

b) It is difficult to get this kind of code right, and when you have it
right, it is very hard to make it efficient. The state of the art uses
heavy templating machinery to avoid unnecessary copy constructions and help
the compiler unroll those many loops that you are running into.

c) There is no need for you to reinvent the wheel. Google for C++ linear
algebra libraries or visit http://www.oonumerics.org.
Best

Kai-Uwe Bux

Sep 16 '05 #2
Kai-Uwe Bux wrote:
xuatla wrote:

Hi,

I am not sure whether I describe the subject correctly.

What I want to do is for a matrix class


[snip]

Don't roll your own code unless you absolutely have to.

a) Numerical linear algebra is *hard*: algorithms that you might recall from
your college linear algebra class routinely run into trouble because
numbers on a computer like double simply do not obey nice mathematical
rules. (Small determinants or bad choices for pivots can completely
obliterate a matrix inversion).

b) It is difficult to get this kind of code right, and when you have it
right, it is very hard to make it efficient. The state of the art uses
heavy templating machinery to avoid unnecessary copy constructions and help
the compiler unroll those many loops that you are running into.

c) There is no need for you to reinvent the wheel. Google for C++ linear
algebra libraries or visit http://www.oonumerics.org.
Best

Kai-Uwe Bux

Thank you very much for the answer!

X
Sep 16 '05 #3

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

Similar topics

4
1936
by: Robert M | last post by:
Hello, I actually have a couple of questions regarding this project. First, I have a pretty good understanding of SQL code. I use to work with dBase III and IV. I now work with Access 97 and 2000 and can do simple Query designs. I have a text file that is about 915mb and consists of records that are fixed in length of 331 characters. There are no records
2
2257
by: Daniel | last post by:
I'm a newcomer to .Net and am slowly becoming familiar with it, so I have some simple questions. Here's the situation: I created a VB.Net project for my data access layer (DAL), another VB.Net project for my business logic layer (BLL), and am using ASP.Net web forms as the front end. So I want by BLL to reference the DAL and the ASP.Net project to reference the BLL. Questions:
2
1491
by: He Shiming | last post by:
Hi, I've got a question regarding class inheritance. The following code reproduces the problem I'm dealing with: class IBase { public: virtual void Method(void)=0; };
1
4124
by: Hans-Jürgen Schönig | last post by:
hello ... i am running into a couple of questions regarding materialized view logs. my goal is to take data from an oracle database and replicate it to some remote data store (maybe some other datastore can poll the materialized view log or so). the idea is: if i could simply replicate the changes made to a materialized view it would be perfect. i have come across materialized view logs but i don't really know how to treat them...
8
5260
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is developing a web-based application, one part of which involves allowing the user the ability to page through transaction "history" information. The _summary_ history table will have the following fields: ServiceName, Date, User-Ref1, User-Ref2,...
3
1449
by: trialproduct2004 | last post by:
Hi all i am having application in c#. I want to create array of class object at runtime. I don't want to set array bound at design time. How to set array bound at runtime and how to access array element? Can some one help me. Thanks in advance.
3
1421
by: Sarika | last post by:
I have some questions regarding Modal forms and would appreciate if someone could clarify my understanding. (a) I observed that the modal form's Form_Closing event is generated if I set the modal form's Visible property to False or call its Hide method. Is this true? or is it a result of something that I am doing incorrectly? (b) The ShowDialog method halts all other execution in a single threaded program till the modal form is closed,...
13
1426
by: jcsnippets.atspace.com | last post by:
Hi everybody, A few days ago I decided to get my site validated, so I have begun to clean up the first page to get an impression of what I should and should not do. To be able to get the site validated, I have to get rid of a lot of old style layout (tables, etcetera...), but I'd very much like to keep the original look and feel of the site. I have literally spent the entire evening working on the title and menu part
6
1618
by: InvalidPointers | last post by:
Perhaps a veteran C++ programmer might be able to help me with this-- I'm basically trying to set up a linked list of objects that are templated. Now ordinarily I'd just derive from a 'master class' but here I'd like to be able to directly return one of the templated (meaning I store an object of the template aargument type, for example an integer, float or boolean) data members upon request. Could I just overload a virtualized function of...
0
8823
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
9530
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
9363
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...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
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...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.