-
Notifications
You must be signed in to change notification settings - Fork 0
/
IdentityMatrix.hpp
68 lines (56 loc) · 1.38 KB
/
IdentityMatrix.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
60
61
62
63
64
65
66
67
68
/**
* @file mtl_test.cpp
* Implimentation file for interfacing with MTL4 and it's linear solvers.
*/
// HW3: Need to install/include Boost and MTL in Makefile
#include <boost/numeric/mtl/mtl.hpp>
#include <boost/numeric/itl/itl.hpp>
#include<iostream>
// HW3: YOUR CODE HERE
// Define a IdentityMatrix that interfaces with MTL
class IdentityMatrix{
public:
IdentityMatrix(unsigned int size):n(size){}
unsigned int get_size() const
{
return n;
}
template <typename VectorIn, typename VectorOut, typename Assign>
void mult(const VectorIn &v, VectorOut &w, Assign) const
{
Assign::apply(w, v);
}
template <typename Vector>
mtl::vec::mat_cvec_multiplier<IdentityMatrix, Vector>
operator*(const Vector &v) const
{
return {*this, v};
}
private:
unsigned int n;
};
inline std::size_t size(const IdentityMatrix A)
{
return A.get_size()*A.get_size();
}
inline std::size_t num_rows(const IdentityMatrix A)
{
return A.get_size();
}
inline std::size_t num_cols(const IdentityMatrix A)
{
return A.get_size();
}
namespace mtl{
namespace ashape{
template<>
struct ashape_aux<IdentityMatrix>{
typedef nonscal type;
};
}//
template<>
struct Collection<IdentityMatrix>{
typedef double value_type;
typedef unsigned size_type;
};
};