Skip to main content
Email Password   helpLost your password?

Overview

Matrices, do you hate them? I do, and they turn up all over the place in the projects I work with. So over time I have developed a class CMatrix to handle all the things we need, and some I expect to need in the future.

How the data is handled

First lets take an overview of how the class handles the data. The matrix data is allocated in a flat array of doubles with an integer reference counter at the end of the array. As the matrix is dynamic, we use a reference count system to avoid efficiency hits when assigning/copying one matrix into another. Two object can point to the same data, and they only diverge when one of them changes the data, getting its own copy of the data at that point. The data is only deleted when the last reference to it is being deleted. This has advantages for objects returned by function calls by value, and which are assigned by operator=, as there is little penalty in assigning a pointer compared to a new/copy operation.

Serialization

The CMatrix class inherits directly from CObject and is full serialization compatible.

CMatrixHelper

A small helper class has been added to allow a simulated CMatrix::operator[][] to work. I stole this idea shamelessly from Alex Chirokov's article 2D Matrix Container with [][] indexing. A nice way of doing it. Note also that you should not be creating any objects of this type in your own code. It is used for this purpose only.

Robustness

In DEBUG mode, the code compiles with 0 warnings/errors and has extensive ASSERTion checking through out, so it should catch any problems that you have (or I have) in code. Most of the functionality has been thoroughly checked, but I would recommend checking your results, just in case!

Constructors

You can construct a matrix object using the following methods:

As a note, any non-initialized matrix elements will be set to 0 on construction.

Operators overloaded

The following operators have been overloaded:

Arithmatic

Comparison

Element access

Get/Set functions

Two standard access function are provided.:

Other matrix functions

Transposition

Inversion

Covariant (A' * A)

Normalisation

Concatenation

Extraction/substitution

Other notes

All the code to handle the allocation/deallocation of matrix data and the reference counting is not covered here in the class interface as they are all private functions. You can see the documentation in the source code comments. (wow comments....:-D)

If you find any bugs or have some enhancements for the class, I would be happy if you would pass them along, and I will endeavour to keep the class fully up to date here.

Updates

13th August 2002

2nd July 2002

Enjoy!

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Questioncompile error Pin
MaryamR
2:03 22 Apr '09  
Generalhelp me Pin
cooljeff
21:45 31 Mar '08  
Generalhi Pin
sujithkumarsl
21:36 4 Jun '07  
GeneralA better version of serialization Pin
cristitomi
0:56 15 Feb '07  
GeneralHow to use this class in Visual C++ 6.0 Pin
cristitomi
6:32 14 Feb '07  
GeneralRe: How to use this class in Visual C++ 6.0 Pin
whynot123456
21:54 31 Oct '09  
GeneralQuite slow for 8x8 inverse. Pin
chueh8
9:08 21 Sep '06  
GeneralEliminating the helper class Pin
cwbenson
5:15 14 Jul '06  
Generallink errors Pin
cwbenson
4:44 14 Jul '06  
GeneralError with creating CMatrix objects Pin
kimyuan81
23:39 9 Mar '06  
Generalsomebody help! Pin
gampalu
5:41 14 Feb '06  
JokeJokes Pin
wepy888
20:09 8 Dec '05  
GeneralI need introduce the values in matrix Pin
rubenss
7:06 18 Oct '05  
Generalsome thing is wrong Pin
chen1000
6:17 13 Oct '05  
Generalto build cmatric Pin
zairee
23:17 6 Sep '05  
Generalhelp..#include "stdafx.h" Pin
mohamed radwan
22:21 21 Jun '05  
GeneralComplile Error Pin
terrenzhong
2:14 6 Jan '05  
GeneralRe: Complile Error Pin
phanduchuynh
17:19 6 Jan '05  
GeneralProblem in compiling... plz help Pin
Nagarajan S.
8:46 31 Aug '04  
GeneralRe: Problem in compiling... plz help Pin
Nagarajan S.
9:20 31 Aug '04  
Generaloperator* fix? Pin
Jonny Gould
23:58 12 Jul '04  
GeneralRe: operator* fix? Pin
Jonny Gould
18:46 13 Jul '04  
GeneralRe: operator* fix? Pin
Bill Lim
22:02 7 Nov '04  
Generalcan't compile source Pin
milan08
18:13 24 Mar '04  
GeneralRow Reduction, Gaussian elimination, row echelon form, matrix inverse Pin
James Reilly
17:17 6 Feb '04  


Last Updated 12 Aug 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009