Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_mat.h
Go to the documentation of this file.
1 /*
2  Copyright 2010-2016 Pierre SMARS (smars@yuntech.edu.tw)
3  This program is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 2 of the License, or
6  (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef _VE_MAT_H_
17 #define _VE_MAT_H_
18 
19 #include <valarray>
20 #include <iostream>
21 #include "a_mat_base.h"
22 
23 typedef unsigned int UI;
24 
32 class a_mat;
33 
34 a_mat operator+(a_mat& a, a_mat& b);
35 a_mat operator-(a_mat& a, a_mat& b);
36 a_mat operator*(a_mat& a, a_mat& b);
37 a_mat operator*(a_mat& a, const double v);
38 a_mat operator*(const double v, a_mat& a);
39 a_mat operator/(a_mat& a, const double v);
40 
41 class a_mat: public a_mat_base
42 {
43  public:
44  a_mat(UI i, UI j, double v = 0); //v : value
45  a_mat(int i, int j, double v = 0);
46  a_mat(const a_mat& m);
47  ~a_mat();
48 
49  inline UI maxi() const {return maxi_;}
50  inline UI maxj() const {return maxj_;}
51  inline UI size() const {return maxi_*maxj_;}
52 
53  inline std::valarray<double>& x() const {return (*x_);}
54 
55  inline virtual double& operator()(const UI i, const UI j) {return (*x_)[i*maxj_+j];}
56  inline virtual double operator()(const UI i, const UI j) const {return (*x_)[i*maxj_+j];}
57 
58  a_mat& operator=(const a_mat& m);
59 
60  bool operator==(const a_mat& a);
61  a_mat& operator-();
62  a_mat& operator+=(const a_mat& a);
63  a_mat operator+(const a_mat& a);
64  a_mat& operator-=(const a_mat& a);
65  a_mat operator-(const a_mat& a);
66  a_mat& operator*=(double v);
67  a_mat operator*(double v);
68  a_mat& operator/=(double v);
69  a_mat operator/(double v);
70 
71  a_mat transpose();
72  void swapc(UI c1, UI c2); //swap the columns c1 and c2
73  void swapr(UI r1, UI r2); //swap the rows r1 and r2
74  a_mat sub_matrix(const UI i, const UI j) const; //matrix formed from (*this) by suppressing row i and column j
75  //: input/output
76  virtual void read(std::istream &i);
77  virtual void write(std::ostream &o) const;
78 
79  // friend std::istream& operator>> (std::istream& i, a_mat& m);
80  // friend std::ostream& operator<< (std::ostream& o, const a_mat& m);
81 
83  class range_error {};
86 
87  protected:
90 
91  std::valarray<double> * x_;
92 };
93 
94 #endif
a_mat operator/(a_mat &a, const double v)
Definition: a_mat.cxx:305
a_mat operator-(a_mat &a, a_mat &b)
Definition: a_mat.cxx:269
a_mat operator*(a_mat &a, a_mat &b)
Definition: a_mat.cxx:275
a_mat operator+(a_mat &a, a_mat &b)
Definition: a_mat.cxx:263
unsigned int UI
Definition: a_mat.h:23
Definition: a_mat.h:42
a_mat operator*(double v)
Definition: a_mat.cxx:109
a_mat & operator*=(double v)
Definition: a_mat.cxx:103
std::valarray< double > * x_
Definition: a_mat.h:91
a_mat(UI i, UI j, double v=0)
Definition: a_mat.cxx:23
a_mat & operator=(const a_mat &m)
Definition: a_mat.cxx:52
void swapc(UI c1, UI c2)
Definition: a_mat.cxx:138
a_mat operator/(double v)
Definition: a_mat.cxx:121
UI maxj_
Definition: a_mat.h:89
a_mat operator+(const a_mat &a)
Definition: a_mat.cxx:83
std::valarray< double > & x() const
Definition: a_mat.h:53
a_mat sub_matrix(const UI i, const UI j) const
Definition: a_mat.cxx:162
virtual double operator()(const UI i, const UI j) const
Definition: a_mat.h:56
a_mat & operator/=(double v)
Definition: a_mat.cxx:115
a_mat transpose()
Definition: a_mat.cxx:127
bool operator==(const a_mat &a)
Definition: a_mat.cxx:66
UI maxi_
Definition: a_mat.h:88
a_mat & operator-=(const a_mat &a)
Definition: a_mat.cxx:89
a_mat & operator+=(const a_mat &a)
Definition: a_mat.cxx:75
virtual double & operator()(const UI i, const UI j)
Definition: a_mat.h:55
virtual void read(std::istream &i)
Definition: a_mat.cxx:211
UI size() const
Definition: a_mat.h:51
a_mat & operator-()
Definition: a_mat.cxx:60
UI maxi() const
Definition: a_mat.h:49
UI maxj() const
Definition: a_mat.h:50
virtual void write(std::ostream &o) const
Definition: a_mat.cxx:224
void swapr(UI r1, UI r2)
Definition: a_mat.cxx:149
~a_mat()
Definition: a_mat.cxx:47