30 #ifndef REMORA_KERNELS_DEFAULT_TRSV_HPP 31 #define REMORA_KERNELS_DEFAULT_TRSV_HPP 33 #include "../../expression_types.hpp" 34 #include "../../assignment.hpp" 36 #include "../../detail/vector_proxy_classes.hpp" 37 #include "../../detail/matrix_proxy_classes.hpp" 38 #include "../../detail/structure.hpp" 40 #include <type_traits> 42 namespace remora {
namespace bindings {
45 template<
bool Unit,
class MatA,
class V>
47 matrix_expression<MatA, cpu_tag>
const& A,
48 vector_expression<V, cpu_tag> &b,
49 lower, column_major, left
51 REMORA_SIZE_CHECK(A().size1() == A().size2());
52 REMORA_SIZE_CHECK(A().size2() == b().size());
54 typedef typename MatA::value_type value_type;
55 typedef matrix_transpose<typename const_expression<MatA>::type> TransA;
57 std::size_t size = b().size();
58 for (std::size_t n = 0; n != size; ++ n) {
60 if(A()(n, n) == value_type()){
61 throw std::invalid_argument(
"[TRSV] Matrix is singular!");
65 if (b()(n) != value_type()){
66 matrix_row<TransA> colA = row(transA,n);
67 vector_range<V> blower(b(),n+1,size);
68 vector_range<matrix_row<TransA> > colAlower(colA,n+1,size);
69 plus_assign(blower,colAlower,-b()(n));
74 template<
bool Unit,
class MatA,
class V>
76 matrix_expression<MatA, cpu_tag>
const& A,
77 vector_expression<V, cpu_tag> &b,
78 lower, row_major, left
80 REMORA_SIZE_CHECK(A().size1() == A().size2());
81 REMORA_SIZE_CHECK(A().size2() == b().size());
83 typedef typename MatA::value_type value_type;
85 std::size_t size = b().size();
86 for (std::size_t n = 0; n < size; ++ n) {
87 typedef matrix_row<typename const_expression<MatA>::type> RowA;
89 vector_range<V> blower(b(),0,n);
90 vector_range<RowA> matRowLower(matRow,0,n);
92 kernels::dot(blower,matRowLower,value);
95 if(A()(n, n) == value_type()){
96 throw std::invalid_argument(
"[TRSV] Matrix is singular!");
104 template<
bool Unit,
class MatA,
class V>
106 matrix_expression<MatA, cpu_tag>
const& A,
107 vector_expression<V, cpu_tag> &b,
108 upper, column_major, left
110 REMORA_SIZE_CHECK(A().size1() == A().size2());
111 REMORA_SIZE_CHECK(A().size2() == b().size());
113 typedef typename MatA::value_type value_type;
114 typedef matrix_transpose<typename const_expression<MatA>::type> TransA;
116 std::size_t size = b().size();
117 for (std::size_t i = 0; i < size; ++ i) {
118 std::size_t n = size-i-1;
120 if(A()(n, n) == value_type()){
121 throw std::invalid_argument(
"[TRSV] Matrix is singular!");
125 if (b()(n) != value_type()) {
126 matrix_row<TransA> colA = row(transA,n);
127 vector_range<V> blower(b(),0,n);
128 vector_range<matrix_row<TransA> > colAlower(colA,0,n);
129 plus_assign(blower,colAlower, -b()(n));
134 template<
bool Unit,
class MatA,
class V>
136 matrix_expression<MatA, cpu_tag>
const& A,
137 vector_expression<V, cpu_tag> &b,
138 upper, row_major, left
140 REMORA_SIZE_CHECK(A().size1() == A().size2());
141 REMORA_SIZE_CHECK(A().size2() == b().size());
143 typedef typename MatA::value_type value_type;
145 std::size_t size = A().size1();
146 for (std::size_t i = 0; i < size; ++ i) {
147 std::size_t n = size-i-1;
148 typedef matrix_row<typename const_expression<MatA>::type> RowA;
150 vector_range<V> blower(b(),n+1,size);
151 vector_range<RowA> matRowLower(matRow,n+1,size);
153 kernels::dot(blower,matRowLower,value);
156 if(A()(n, n) == value_type()){
157 throw std::invalid_argument(
"[TRSV] Matrix is singular!");
166 template<
bool Unit,
class Triangular,
class Orientation,
class MatA,
class V>
168 matrix_expression<MatA, cpu_tag>
const& A,
169 vector_expression<V, cpu_tag> &b,
170 Triangular, Orientation, right
172 matrix_transpose<typename const_expression<MatA>::type> transA(A());
175 typename Triangular::transposed_orientation(),
176 typename Orientation::transposed_orientation(),
182 template <
class Triangular,
class S
ide,
typename MatA,
typename V>
184 matrix_expression<MatA, cpu_tag>
const& A,
185 vector_expression<V, cpu_tag> & b,
188 trsv_impl<Triangular::is_unit>(
190 triangular_tag<Triangular::is_upper,false>(),
191 typename MatA::orientation(), Side());