[1097] | 1 | #ifndef MXMATRIX_INCLUDED // -*- C++ -*-
|
---|
| 2 | #define MXMATRIX_INCLUDED
|
---|
| 3 | #if !defined(__GNUC__)
|
---|
| 4 | # pragma once
|
---|
| 5 | #endif
|
---|
| 6 |
|
---|
| 7 | /************************************************************************
|
---|
| 8 |
|
---|
| 9 | Generic n-dimensional matrix class
|
---|
| 10 |
|
---|
| 11 | Copyright (C) 1998 Michael Garland. See "COPYING.txt" for details.
|
---|
| 12 |
|
---|
| 13 | $Id: MxMatrix.h,v 1.1 2002/09/24 16:53:54 wimmer Exp $
|
---|
| 14 |
|
---|
| 15 | ************************************************************************/
|
---|
| 16 |
|
---|
| 17 | #include "MxVector.h"
|
---|
| 18 |
|
---|
| 19 | #define __T float
|
---|
| 20 | #include "mixmops.h"
|
---|
| 21 |
|
---|
| 22 | #define __T double
|
---|
| 23 | #include "mixmops.h"
|
---|
| 24 |
|
---|
| 25 | ////////////////////////////////////////////////////////////////////////
|
---|
| 26 | //
|
---|
| 27 | // Matrix class
|
---|
| 28 | //
|
---|
| 29 |
|
---|
| 30 | #include "MxBlock2.h"
|
---|
| 31 |
|
---|
| 32 | class MxMatrix : public MxBlock2<double>
|
---|
| 33 | {
|
---|
| 34 | public:
|
---|
| 35 | MxMatrix(unsigned int n) : MxBlock2<double>(n,n) { *this = 0.0; }
|
---|
| 36 | MxMatrix(const MxMatrix& m) : MxBlock2<double>(m.dim(),m.dim()) {copy(m);}
|
---|
| 37 |
|
---|
| 38 | MxMatrix& operator=(const MxMatrix& m) { copy(m); return *this; }
|
---|
| 39 | MxMatrix& operator=(double d) { mxm_set(*this, d, dim()); return *this; }
|
---|
| 40 |
|
---|
| 41 | unsigned int dim() const { return width(); }
|
---|
| 42 |
|
---|
| 43 | MxMatrix& operator+=(const MxMatrix& m)
|
---|
| 44 | { mxm_addinto(*this, m, dim()); return *this; }
|
---|
| 45 | MxMatrix& operator-=(const MxMatrix& m)
|
---|
| 46 | { mxm_subfrom(*this, m, dim()); return *this; }
|
---|
| 47 | MxMatrix& operator*=(double d) {mxm_scale(*this, d, dim()); return *this;}
|
---|
| 48 | MxMatrix& operator/=(double d) {mxm_invscale(*this,d,dim());return *this;}
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | MxVector operator*(const MxVector& v) const
|
---|
| 52 | { MxVector r(dim()); mxm_xform(r, *this, v, dim()); return r; }
|
---|
| 53 |
|
---|
| 54 | double invert(MxMatrix& inv) const {return mxm_invert(inv, *this, dim());}
|
---|
| 55 | };
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | inline ostream& operator<<(ostream& out, const MxMatrix& a)
|
---|
| 59 | {
|
---|
| 60 | return mxm_write(out, a, a.dim());
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | // MXMATRIX_INCLUDED
|
---|
| 64 | #endif
|
---|