-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublematrix.cpp
More file actions
118 lines (101 loc) · 2.99 KB
/
doublematrix.cpp
File metadata and controls
118 lines (101 loc) · 2.99 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (C) 2004 - 2005 by
* Hieu Xuan Phan & Minh Le Nguyen {hieuxuan, nguyenml}@jaist.ac.jp
* Graduate School of Information Science,
* Japan Advanced Institute of Science and Technology (JAIST)
*
* doublematrix.cpp - this file is part of FlexCRFs.
*
* Begin: Dec. 15, 2004
* Last change: Sep. 09, 2005
*
* FlexCRFs is a free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* FlexCRFs is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FlexCRFs; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "doublematrix.h"
using namespace std;
// constructor with rows and cols
doublematrix::doublematrix(int rows, int cols) {
this->rows = rows;
this->cols = cols;
mtrx = new double*[rows];
for (int i = 0; i < rows; i++) {
mtrx[i] = new double[cols];
}
}
// constructor with rows, cols and matrix content
doublematrix::doublematrix(int rows, int cols, double ** mtrx) {
this->rows = rows;
this->cols = cols;
this->mtrx = new double*[rows];
for (int i = 0; i < rows; i++) {
this->mtrx[i] = new double[cols];
for (int j = 0; j < cols; j++) {
this->mtrx[i][j] = mtrx[i][j];
}
}
}
// copy constructor
doublematrix::doublematrix(doublematrix & dm) {
rows = dm.rows;
cols = dm.cols;
mtrx = new double*[rows];
for (int i = 0; i < rows; i++) {
mtrx[i] = new double[cols];
for (int j = 0; j < cols; j++) {
mtrx[i][j] = dm.mtrx[i][j];
}
}
}
// overloading assignment operator (with one value)
void doublematrix::operator=(double val) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
mtrx[i][j] = val;
}
}
}
// overloading assignment operator
void doublematrix::operator=(doublematrix & dm) {
int i, j;
if (rows != dm.rows || cols != dm.cols) {
for (i = 0; i < rows; i++) {
delete mtrx[i];
}
delete mtrx;
rows = dm.rows;
cols = dm.cols;
mtrx = new double*[rows];
for (i = 0; i < rows; i++) {
mtrx[i] = new double[cols];
}
}
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
mtrx[i][j] = dm.mtrx[i][j];
}
}
}
// assign the same value for all elements
void doublematrix::assign(double val) {
*this = val;
}
// assign values for elements from values from another matrix
void doublematrix::assign(doublematrix & dm) {
*this = dm;
}
// reference to an element
double & doublematrix::get(int i, int j) {
return mtrx[i][j];
}