-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmat.h
92 lines (77 loc) · 2.85 KB
/
mat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
*
* Copyright (c) 2010-2015 Voidware Ltd. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code as
* defined in and that are subject to the Voidware Public Source Licence version
* 1.0 (the 'Licence'). You may not use this file except in compliance with the
* Licence or with expressly written permission from Voidware. Please obtain a
* copy of the Licence at http://www.voidware.com/legal/vpsl1.txt and read it
* before using this file.
*
* The Original Code and all software distributed under the Licence are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
* OR IMPLIED, AND VOIDWARE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING
* WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Please see the Licence for the specific language governing rights and
* limitations under the Licence.
*
*/
#ifndef __mat_h__
#define __mat_h__
#include "types.h"
typedef BCD VALUE;
typedef TermRef Mat;
typedef TermRef Vec;
#define MAT(_m,_n,_r,_c) FLOAT(ARRAY(ARRAY(_m)->_at(_r))->_at(_c))->v_.asBCD()
#define VEC(_m,_i) FLOAT(ARRAY(_m)->_at(_i))->v_.asBCD()
#define VECC(_m,_i) COMPLEX(ARRAY(_m)->_at(_i))->cmf_
#define VMAT(_m,_nr,_r,_c) \
((_nr == 1) ? VEC(_m, _c) : MAT(_m,0,_r,_c))
/* because we hate templates, the string VALUE, represents the
* templated type.
*/
struct Matrix
{
// Constructors
Matrix() {}
Matrix(Term* t) : _a(t) { _init(); }
void clone(const Matrix& a)
{
_a = ARRAY(a._a)->clone();
_init();
}
friend bool mul(const Matrix& a, const Matrix& b, Matrix& c);
friend bool add(const Matrix& a, const Matrix& b, Matrix& c);
friend bool sub(const Matrix& a, const Matrix& b, Matrix& c);
friend bool div(const Matrix& a, const Matrix& b, Matrix& c);
friend void transpose(const Matrix& a, Matrix& c);
friend bool invert(const Matrix& b, Matrix& c, bool& singular);
static void _create(Matrix& a, int nRows, int nCols, bool complex = false);
bool determinant(VALUE&) const;
bool isSquare() const { return _nRows == _nCols; }
void _init()
{
_nRows = 0;
_nCols = 0;
int f = ARRAY(_a)->flags_;
if (f == Array::array_realvector)
{
_nCols = ARRAY(_a)->size_;
_nRows = 1;
}
else if (f == Array::array_realmatrix)
{
_nRows = ARRAY(_a)->size_;
_nCols = ARRAY(_a)->nCols_;
}
}
unsigned int _nRows;
unsigned int _nCols;
TermRef _a; // will be an array
};
bool prootEigen(const Matrix& a, Matrix& rmat);
#endif // __mat_h__