/
identity_matrix.hpp
59 lines (51 loc) · 1.49 KB
/
identity_matrix.hpp
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
/**
* @file identity_matrix.hpp
* @author Alex Liu (alex.liuyining@outlook.com)
* @brief Identity matrix class, derived from Matrix class
* @date 2021-12
*/
#ifndef IDENTITY_MATRIX_HPP
#define IDENTITY_MATRIX_HPP
#include <stdexcept>
#include <iostream>
#include "matrix_library.hpp"
namespace MatrixLibrary
{
template <typename TData>
class IdentityMatrix : public Matrix<TData>
{
public:
/**
* The only constructor, takes a single dimensional number
* @param size
*/
IdentityMatrix (const size_t size) : Matrix<TData> (size, size)
{
if (size <= 0)
{
throw std::invalid_argument("Dimension must be positive integer");
}
for (size_t i = 0; i < size; ++i)
{
this->m_data[i][i] = (TData) 1.0;
}
if (printMemoryInfo)
{
std::cout << "Identity Dimensions-only Constructor called" << std::endl;
}
}
Matrix<TData> operator*(const Matrix<TData> &mat) const override
{
std::cout << "Overriden function * called!" << "\n";
Matrix<TData> r(mat);
return r;
}
Matrix<TData> transpose() const override
{
std::cout << "Overriden function transpose called!" << "\n";
Matrix<TData> r(*this);
return r;
}
};
} // end namespace MatrixLibrary
#endif // #ifndef IDENTITY_MATRIX_HPP