MaMiCo
1.2
Toggle main menu visibility
Loading...
Searching...
No Matches
tarch
la
Matrix.h
1
// Copyright (C) 2015 Technische Universitaet Muenchen
2
// This file is part of the Mamico project. For conditions of distribution
3
// and use, please see the copyright notice in Mamico's main folder, or at
4
// www5.in.tum.de/mamico
5
#ifndef _TARCH_LA_MATRIX_H_
6
#define _TARCH_LA_MATRIX_H_
7
#include "tarch/TarchDefinitions.h"
8
9
namespace
tarch
{
10
namespace
la
{
11
template
<
int
rows,
int
cols,
class
T>
class
Matrix
;
12
}
13
}
// namespace tarch
14
21
22
template
<
int
rows,
int
cols,
class
T>
class
tarch::la::Matrix
{
23
private
:
24
T _entries[rows][cols];
25
26
public
:
31
Matrix
() {}
32
Matrix
(
const
T& t) {
33
for
(
int
i = 0; i < rows; i++) {
34
for
(
int
j = 0; j < cols; j++) {
35
_entries[i][j] = t;
36
}
37
}
38
}
39
44
T&
operator()
(
int
i,
int
j) {
45
#if (TARCH_DEBUG == TARCH_YES)
46
if
(i < 0 || i > rows - 1) {
47
std::cout <<
"ERROR Matrix T& operator(): i out of range!"
<< std::endl;
48
exit(EXIT_FAILURE);
49
}
50
if
(j < 0 || j > cols - 1) {
51
std::cout <<
"ERROR Matrix T& operator(): j out of range!"
<< std::endl;
52
exit(EXIT_FAILURE);
53
}
54
#endif
55
return
_entries[i][j];
56
}
57
const
T&
operator()
(
int
i,
int
j)
const
{
58
#if (TARCH_DEBUG == TARCH_YES)
59
if
(i < 0 || i > rows - 1) {
60
std::cout <<
"ERROR Matrix const T& operator(): i out of range!"
<< std::endl;
61
exit(EXIT_FAILURE);
62
}
63
if
(j < 0 || j > cols - 1) {
64
std::cout <<
"ERROR Matrix const T& operator(): j out of range!"
<< std::endl;
65
exit(EXIT_FAILURE);
66
}
67
#endif
68
return
_entries[i][j];
69
}
70
};
71
72
#endif
tarch::la::Matrix
Definition
Matrix.h:22
tarch::la::Matrix::Matrix
Matrix()
Two constructors, a default one and a constructor, which initializes all elemnet of the matrix with e...
Definition
Matrix.h:31
tarch::la::Matrix::operator()
T & operator()(int i, int j)
operator(i, j) gives back the the element (i, j)
Definition
Matrix.h:44
tarch::la
Definition
Matrix.h:10
tarch
Definition
Configuration.h:11
Generated by
1.17.0