1 #ifndef VIENNACL_MATRIX_HPP_
2 #define VIENNACL_MATRIX_HPP_
53 template<
typename LHS,
typename RHS,
typename OP>
54 class matrix_expression
56 typedef typename viennacl::result_of::reference_if_nonscalar<LHS>::type lhs_reference_type;
57 typedef typename viennacl::result_of::reference_if_nonscalar<RHS>::type rhs_reference_type;
66 LHS &
lhs()
const {
return lhs_; }
69 RHS &
rhs()
const {
return rhs_; }
77 lhs_reference_type lhs_;
79 rhs_reference_type rhs_;
91 template<
typename ROWCOL,
typename MatrixT>
100 vcl_size_t start_col) : mat_(mat), row_(start_row), col_(start_col) {}
126 template<
class NumericT,
typename SizeT,
typename DistanceT>
128 : size1_(rows), size2_(columns), start1_(0), start2_(0), stride1_(1), stride2_(1),
131 row_major_fixed_(true), row_major_(is_row_major)
133 if (rows > 0 && columns > 0)
142 template<
class NumericT,
typename SizeT,
typename DistanceT>
143 template<
typename LHS,
typename RHS,
typename OP>
145 size1_(viennacl::traits::
size1(proxy)), size2_(viennacl::traits::
size2(proxy)), start1_(0), start2_(0), stride1_(1), stride2_(1),
148 row_major_fixed_(true), row_major_(viennacl::traits::
row_major(proxy))
160 template<
class NumericT,
typename SizeT,
typename DistanceT>
165 : size1_(mat_size1), size2_(mat_size2),
166 start1_(mat_start1), start2_(mat_start2),
167 stride1_(mat_stride1), stride2_(mat_stride2),
168 internal_size1_(mat_internal_size1), internal_size2_(mat_internal_size2),
169 row_major_fixed_(true), row_major_(is_row_major)
173 #ifdef VIENNACL_WITH_CUDA
175 elements_.cuda_handle().reset(reinterpret_cast<char*>(ptr_to_mem));
176 elements_.cuda_handle().inc();
191 #ifdef VIENNACL_WITH_OPENCL
192 template<
class NumericT,
typename SizeT,
typename DistanceT>
194 : size1_(rows), size2_(columns),
195 start1_(0), start2_(0),
196 stride1_(1), stride2_(1),
197 internal_size1_(rows), internal_size2_(columns),
198 row_major_fixed_(true), row_major_(is_row_major)
201 elements_.opencl_handle() = mem;
202 elements_.opencl_handle().inc();
203 elements_.opencl_handle().context(ctx.opencl_context());
207 template<
class NumericT,
typename SizeT,
typename DistanceT>
209 size_type mat_size1, size_type mat_start1, size_type mat_stride1, size_type mat_internal_size1,
210 size_type mat_size2, size_type mat_start2, size_type mat_stride2, size_type mat_internal_size2,
212 : size1_(mat_size1), size2_(mat_size2),
213 start1_(mat_start1), start2_(mat_start2),
214 stride1_(mat_stride1), stride2_(mat_stride2),
215 internal_size1_(mat_internal_size1), internal_size2_(mat_internal_size2),
216 row_major_fixed_(true), row_major_(is_row_major)
219 elements_.opencl_handle() = mem;
220 elements_.opencl_handle().inc();
221 elements_.opencl_handle().context(ctx.opencl_context());
226 template<
class NumericT,
typename SizeT,
typename DistanceT>
228 size1_(other.
size1()), size2_(other.
size2()), start1_(0), start2_(0), stride1_(1), stride2_(1),
231 row_major_fixed_(true), row_major_(other.
row_major())
242 template<
class NumericT,
typename SizeT,
typename DistanceT>
252 if (!row_major_fixed_)
266 template<
class NumericT,
typename SizeT,
typename DistanceT>
267 template<
typename LHS,
typename RHS,
typename OP>
272 &&
bool(
"Incompatible matrix sizes!"));
277 internal_size1_ = viennacl::tools::align_to_multiple<size_type>(size1_, dense_padding_size);
278 internal_size2_ = viennacl::tools::align_to_multiple<size_type>(size2_, dense_padding_size);
279 if (!row_major_fixed_)
282 if (size1_ != internal_size1_ || size2_ != internal_size2_)
294 template<
class NumericT,
typename SizeT,
typename DistanceT>
301 internal_size1_ = viennacl::tools::align_to_multiple<size_type>(size1_, dense_padding_size);
302 internal_size2_ = viennacl::tools::align_to_multiple<size_type>(size2_, dense_padding_size);
303 if (!row_major_fixed_)
307 if (
handle() == proxy.lhs().handle() )
311 if ( proxy.lhs().size1() != proxy.lhs().size2() )
312 this->
resize(proxy.lhs().size2(), proxy.lhs().size1());
313 elements_ = temp.handle();
317 if ( proxy.lhs().size1() != proxy.lhs().size2() )
318 this->
resize(proxy.lhs().size2(), proxy.lhs().size1());
324 template<
class NumericT,
typename SizeT,
typename DistanceT>
325 template<
typename LHS,
typename RHS,
typename OP>
330 &&
bool(
"Incompatible matrix sizes!"));
331 assert( (
size1() > 0) &&
bool(
"Vector not yet initialized!") );
332 assert( (
size2() > 0) &&
bool(
"Vector not yet initialized!") );
339 template<
class NumericT,
typename SizeT,
typename DistanceT>
340 template<
typename LHS,
typename RHS,
typename OP>
345 &&
bool(
"Incompatible matrix sizes!"));
346 assert( (
size1() > 0) &&
bool(
"Vector not yet initialized!") );
347 assert( (
size2() > 0) &&
bool(
"Vector not yet initialized!") );
355 template<
class NumericT,
typename SizeT,
typename DistanceT>
358 assert( (m.
size1() == size1_ || size1_ == 0) &&
bool(
"Size mismatch!") );
359 assert( (m.
size2() == size2_ || size2_ == 0) &&
bool(
"Size mismatch!") );
365 internal_size1_ = viennacl::tools::align_to_multiple<size_type>(size1_, dense_padding_size);
366 internal_size2_ = viennacl::tools::align_to_multiple<size_type>(size2_, dense_padding_size);
383 template<
class NumericT,
typename SizeT,
typename DistanceT>
386 assert( (m.
size1() == size1_ || size1_ == 0) &&
bool(
"Size mismatch!") );
387 assert( (m.
size2() == size2_ || size2_ == 0) &&
bool(
"Size mismatch!") );
393 internal_size1_ = viennacl::tools::align_to_multiple<size_type>(size1_, dense_padding_size);
394 internal_size2_ = viennacl::tools::align_to_multiple<size_type>(size2_, dense_padding_size);
408 template<
class NumericT,
typename SizeT,
typename DistanceT>
411 assert( (m.
size1() == size1_ || size1_ == 0) &&
bool(
"Size mismatch!") );
412 assert( (m.
size2() == size2_ || size2_ == 0) &&
bool(
"Size mismatch!") );
418 internal_size1_ = viennacl::tools::align_to_multiple<size_type>(size1_, dense_padding_size);
419 internal_size2_ = viennacl::tools::align_to_multiple<size_type>(size2_, dense_padding_size);
439 template<
class NumericT,
typename SizeT,
typename DistanceT>
449 template<
class NumericT,
typename SizeT,
typename DistanceT>
460 template<
class NumericT,
typename SizeT,
typename DistanceT>
464 *
this, NumericT(1.0), 1,
false,
false,
465 other, NumericT(1.0), 1,
false,
false);
469 template<
class NumericT,
typename SizeT,
typename DistanceT>
473 *
this, NumericT(1.0), 1,
false,
false,
474 other, NumericT(1.0), 1,
false,
true);
479 template<
class NumericT,
typename SizeT,
typename DistanceT>
483 *
this, NumericT(val), 1,
false,
false);
488 template<
class NumericT,
typename SizeT,
typename DistanceT>
492 *
this, NumericT(val), 1,
false,
false);
497 template<
class NumericT,
typename SizeT,
typename DistanceT>
501 *
this, NumericT(val), 1,
false,
false);
506 template<
class NumericT,
typename SizeT,
typename DistanceT>
510 *
this, NumericT(val), 1,
false,
false);
515 template<
class NumericT,
typename SizeT,
typename DistanceT>
519 *
this, NumericT(val), 1,
false,
false);
524 template<
class NumericT,
typename SizeT,
typename DistanceT>
528 *
this, NumericT(val), 1,
false,
false);
535 template<
class NumericT,
typename SizeT,
typename DistanceT>
539 *
this, NumericT(val), 1,
true,
false);
544 template<
class NumericT,
typename SizeT,
typename DistanceT>
548 *
this, NumericT(val), 1,
true,
false);
553 template<
class NumericT,
typename SizeT,
typename DistanceT>
557 *
this, NumericT(val), 1,
true,
false);
562 template<
class NumericT,
typename SizeT,
typename DistanceT>
566 *
this, NumericT(val), 1,
true,
false);
571 template<
class NumericT,
typename SizeT,
typename DistanceT>
575 *
this, NumericT(val), 1,
true,
false);
580 template<
class NumericT,
typename SizeT,
typename DistanceT>
584 *
this, NumericT(val), 1,
true,
false);
590 template<
class NumericT,
typename SizeT,
typename DistanceT>
596 template<
class NumericT,
typename SizeT,
typename DistanceT>
600 template<
class NumericT,
typename SizeT,
typename DistanceT>
603 assert( (rows > 0 && columns > 0) &&
bool(
"Check failed in matrix::resize(): Number of rows and columns must be positive!"));
612 std::vector< NumericT > new_entries( viennacl::tools::align_to_multiple<vcl_size_t>(rows, dense_padding_size)
613 * viennacl::tools::align_to_multiple<vcl_size_t>(columns, dense_padding_size));
624 new_entries[
row_major::mem_index(i, j, viennacl::tools::align_to_multiple<vcl_size_t>(rows, dense_padding_size), viennacl::tools::align_to_multiple<vcl_size_t>(columns, dense_padding_size))]
627 new_entries[
column_major::mem_index(i, j, viennacl::tools::align_to_multiple<vcl_size_t>(rows, dense_padding_size), viennacl::tools::align_to_multiple<vcl_size_t>(columns, dense_padding_size))]
635 internal_size1_ = viennacl::tools::align_to_multiple<size_type>(size1_, dense_padding_size);
636 internal_size2_ = viennacl::tools::align_to_multiple<size_type>(size2_, dense_padding_size);
643 internal_size1_ = viennacl::tools::align_to_multiple<size_type>(size1_, dense_padding_size);
644 internal_size2_ = viennacl::tools::align_to_multiple<size_type>(size2_, dense_padding_size);
658 template<
class NumericT,
typename F,
unsigned int AlignmentV>
688 viennacl::is_row_major<F>::value) {}
704 rows, 0, 1, internal_row_count,
705 cols, 0, 1, internal_col_count,
706 true, viennacl::is_row_major<F>::value) {}
708 #ifdef VIENNACL_WITH_OPENCL
709 explicit matrix(cl_mem mem,
size_type rows,
size_type columns) : base_type(mem, rows, columns, viennacl::is_row_major<F>::value) {}
712 template<
typename LHS,
typename RHS,
typename OP>
757 using base_type::operator=;
780 template<
class NumericT>
781 std::ostream & operator<<(std::ostream & s, const matrix_base<NumericT> & gpu_matrix)
785 std::vector<NumericT> tmp(gpu_matrix.internal_size());
788 s <<
"[" << gpu_matrix.size1() <<
"," << gpu_matrix.size2() <<
"]";
791 for (size_type i = 0; i < gpu_matrix.size1(); ++i)
794 for (size_type j = 0; j < gpu_matrix.size2(); ++j)
796 if (gpu_matrix.row_major())
797 s << tmp[
row_major::mem_index(i * gpu_matrix.stride1() + gpu_matrix.start1(), j * gpu_matrix.stride2() + gpu_matrix.start2(), gpu_matrix.internal_size1(), gpu_matrix.internal_size2())];
799 s << tmp[
column_major::mem_index(i * gpu_matrix.stride1() + gpu_matrix.start1(), j * gpu_matrix.stride2() + gpu_matrix.start2(), gpu_matrix.internal_size1(), gpu_matrix.internal_size2())];
801 if (j < gpu_matrix.size2() - 1)
805 if (i < gpu_matrix.size1() - 1)
817 template<
typename LHS,
typename RHS,
typename OP>
818 std::ostream & operator<<(std::ostream & s, const matrix_expression<LHS, RHS, OP> & expr)
828 template<
typename NumericT>
829 matrix_expression< const matrix_base<NumericT>,
const matrix_base<NumericT>, op_trans>
836 template<
typename NumericT>
837 vector_expression< const matrix_base<NumericT>,
const int, op_matrix_diag>
843 template<
typename NumericT>
844 matrix_expression< const vector_base<NumericT>,
const int, op_vector_diag>
851 template<
typename NumericT,
typename F>
852 vector_expression< const matrix_base<NumericT, F>,
const unsigned int, op_row>
859 template<
typename NumericT,
typename F>
860 vector_expression< const matrix_base<NumericT, F>,
const unsigned int, op_column>
876 template<
typename CPUMatrixT,
typename NumericT,
typename F,
unsigned int AlignmentV>
877 void copy(
const CPUMatrixT & cpu_matrix,
884 if (gpu_matrix.
size1() == 0 || gpu_matrix.
size2() == 0)
886 gpu_matrix.
resize(cpu_matrix.size1(),
887 cpu_matrix.size2(),
false);
890 assert( (gpu_matrix.
size1() == cpu_matrix.size1()) && (gpu_matrix.
size2() == cpu_matrix.size2()) &&
bool(
"Matrix dimensions mismatch.") );
893 for (size_type i = 0; i < gpu_matrix.
size1(); ++i)
895 for (size_type j = 0; j < gpu_matrix.
size2(); ++j)
912 template<
typename NumericT,
typename A1,
typename A2,
typename F,
unsigned int AlignmentV>
913 void copy(
const std::vector< std::vector<NumericT, A1>, A2> & cpu_matrix,
918 if (gpu_matrix.
size1() == 0 || gpu_matrix.
size2() == 0)
920 gpu_matrix.
resize(cpu_matrix.size(),
921 cpu_matrix[0].size(),
925 assert( (gpu_matrix.
size1() == cpu_matrix.size()) &&
bool(
"Matrix dimensions mismatch.") );
928 for (size_type i = 0; i < gpu_matrix.
size1(); ++i)
930 assert( (gpu_matrix.
size2() == cpu_matrix[i].size()) &&
bool(
"Matrix dimensions mismatch.") );
932 for (size_type j = 0; j < gpu_matrix.
size2(); ++j)
952 template<
typename NumericT,
typename F,
unsigned int AlignmentV>
954 NumericT * cpu_matrix_end,
961 assert( (gpu_matrix.
internal_size() >=
static_cast<vcl_size_t>(cpu_matrix_end - cpu_matrix_begin)) && bool(
"fast_copy(): Matrix not large enough to fit data!"));
967 #ifdef VIENNACL_WITH_EIGEN
973 template<
typename F,
unsigned int AlignmentV>
974 void copy(
const Eigen::MatrixXf & cpu_matrix,
975 matrix<float, F, AlignmentV> & gpu_matrix)
977 typedef typename matrix<float, F, AlignmentV>::size_type size_type;
979 if (gpu_matrix.size1() == 0 || gpu_matrix.size2() == 0)
981 gpu_matrix.resize(cpu_matrix.rows(),
987 assert( (gpu_matrix.size1() ==
static_cast<vcl_size_t>(cpu_matrix.rows()))
988 && (gpu_matrix.size2() ==
static_cast<vcl_size_t>(cpu_matrix.cols()))
989 && bool(
"matrix size mismatch")
993 std::vector<float> data(gpu_matrix.internal_size());
994 for (size_type i = 0; i < gpu_matrix.size1(); ++i)
996 for (size_type j = 0; j < gpu_matrix.size2(); ++j)
997 data[F::mem_index(i, j, gpu_matrix.internal_size1(), gpu_matrix.internal_size2())] = cpu_matrix(i,j);
1009 template<
typename F,
unsigned int AlignmentV>
1010 void copy(
const Eigen::MatrixXd & cpu_matrix,
1011 matrix<double, F, AlignmentV> & gpu_matrix)
1013 typedef typename matrix<double, F, AlignmentV>::size_type size_type;
1015 if (gpu_matrix.size1() == 0 || gpu_matrix.size2() == 0)
1017 gpu_matrix.resize(cpu_matrix.rows(),
1023 assert( (gpu_matrix.size1() ==
static_cast<vcl_size_t>(cpu_matrix.rows()))
1024 && (gpu_matrix.size2() ==
static_cast<vcl_size_t>(cpu_matrix.cols()))
1025 && bool(
"matrix size mismatch")
1029 std::vector<double> data(gpu_matrix.internal_size());
1030 for (size_type i = 0; i < gpu_matrix.size1(); ++i)
1032 for (size_type j = 0; j < gpu_matrix.size2(); ++j)
1033 data[F::mem_index(i, j, gpu_matrix.internal_size1(), gpu_matrix.internal_size2())] = cpu_matrix(i,j);
1041 #ifdef VIENNACL_WITH_MTL4
1047 template<
typename NumericT,
typename T,
typename F,
unsigned int AlignmentV>
1048 void copy(
const mtl::dense2D<NumericT, T>& cpu_matrix,
1049 matrix<NumericT, F, AlignmentV> & gpu_matrix)
1051 typedef typename matrix<NumericT, F, AlignmentV>::size_type size_type;
1053 if (gpu_matrix.size1() == 0 || gpu_matrix.size2() == 0)
1055 gpu_matrix.resize(cpu_matrix.num_rows(),
1056 cpu_matrix.num_cols(),
1061 assert( (gpu_matrix.size1() == cpu_matrix.num_rows())
1062 && (gpu_matrix.size2() == cpu_matrix.num_cols())
1063 &&
bool(
"matrix size mismatch")
1067 std::vector<NumericT> data(gpu_matrix.internal_size());
1068 for (size_type i = 0; i < gpu_matrix.size1(); ++i)
1070 for (size_type j = 0; j < gpu_matrix.size2(); ++j)
1071 data[F::mem_index(i, j, gpu_matrix.internal_size1(), gpu_matrix.internal_size2())] = cpu_matrix[i][j];
1090 template<
typename CPUMatrixT,
typename NumericT,
typename F,
unsigned int AlignmentV>
1092 CPUMatrixT & cpu_matrix )
1096 if ( (gpu_matrix.
size1() > 0) && (gpu_matrix.
size2() > 0) )
1100 std::vector<NumericT> temp_buffer(gpu_matrix.
internal_size());
1104 for (size_type i = 0; i < gpu_matrix.
size1(); ++i)
1107 for (size_type j = 0; j < gpu_matrix.
size2(); ++j)
1119 template<
typename NumericT,
typename A1,
typename A2,
typename F,
unsigned int AlignmentV>
1121 std::vector< std::vector<NumericT, A1>, A2> & cpu_matrix)
1125 if ( (gpu_matrix.
size1() > 0) && (gpu_matrix.
size2() > 0) )
1127 assert( (cpu_matrix.size() == gpu_matrix.
size1()) &&
bool(
"Matrix dimensions mismatch: rows"));
1129 std::vector<NumericT> temp_buffer(gpu_matrix.
internal_size());
1133 for (size_type i = 0; i < gpu_matrix.
size1(); ++i)
1135 assert( (cpu_matrix[i].
size() == gpu_matrix.
size2()) &&
bool(
"Matrix dimensions mismatch: columns"));
1137 for (size_type j = 0; j < gpu_matrix.
size2(); ++j)
1151 template<
typename NumericT,
typename F,
unsigned int AlignmentV>
1153 NumericT * cpu_matrix_begin)
1165 template<
typename LHS1,
typename RHS1,
typename OP1,
1166 typename LHS2,
typename RHS2,
typename OP2>
1167 matrix_expression< const matrix_expression<const LHS1, const RHS1, OP1>,
1168 const matrix_expression<const LHS2, const RHS2, OP2>,
1175 &&
bool(
"Incompatible matrix sizes!"));
1181 template<
typename LHS1,
typename RHS1,
typename OP1,
1183 matrix_expression< const matrix_expression<const LHS1, const RHS1, OP1>,
1184 const matrix_base<NumericT>,
1191 &&
bool(
"Incompatible matrix sizes!"));
1197 template<
typename NumericT,
1198 typename LHS2,
typename RHS2,
typename OP2>
1199 matrix_expression< const matrix_base<NumericT>,
1200 const matrix_expression<const LHS2, const RHS2, OP2>,
1207 &&
bool(
"Incompatible matrix sizes!"));
1214 template<
typename NumericT>
1215 matrix_expression< const matrix_base<NumericT>,
const matrix_base<NumericT>, op_add >
1225 template<
typename LHS1,
typename RHS1,
typename OP1,
1226 typename LHS2,
typename RHS2,
typename OP2>
1227 matrix_expression< const matrix_expression<const LHS1, const RHS1, OP1>,
1228 const matrix_expression<const LHS2, const RHS2, OP2>,
1235 &&
bool(
"Incompatible matrix sizes!"));
1241 template<
typename LHS1,
typename RHS1,
typename OP1,
1243 matrix_expression< const matrix_expression<const LHS1, const RHS1, OP1>,
1244 const matrix_base<NumericT>,
1251 &&
bool(
"Incompatible matrix sizes!"));
1257 template<
typename NumericT,
1258 typename LHS2,
typename RHS2,
typename OP2>
1259 matrix_expression< const matrix_base<NumericT>,
1260 const matrix_expression<const LHS2, const RHS2, OP2>,
1267 &&
bool(
"Incompatible matrix sizes!"));
1274 template<
typename NumericT>
1275 matrix_expression< const matrix_base<NumericT>,
const matrix_base<NumericT>, op_sub >
1291 template<
typename S1,
typename NumericT>
1293 matrix_expression< const matrix_base<NumericT>,
const S1, op_mult>
1301 template<
typename NumericT>
1302 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1309 template<
typename NumericT>
1310 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1317 template<
typename NumericT>
1318 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1325 template<
typename NumericT>
1326 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1333 template<
typename NumericT>
1334 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1341 template<
typename NumericT>
1342 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1355 template<
typename LHS,
typename RHS,
typename OP,
typename S1>
1357 matrix_expression< const matrix_expression< LHS, RHS, OP>,
const S1, op_mult> >::type
1370 template<
typename S1,
typename LHS,
typename RHS,
typename OP>
1372 matrix_expression< const matrix_expression< LHS, RHS, OP>,
const S1, op_mult> >::type
1381 template<
typename NumericT,
typename S1>
1383 matrix_expression< const matrix_base<NumericT>,
const S1, op_mult> >::type
1390 template<
typename NumericT>
1391 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1398 template<
typename NumericT>
1399 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1406 template<
typename NumericT>
1407 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1414 template<
typename NumericT>
1415 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1422 template<
typename NumericT>
1423 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1430 template<
typename NumericT>
1431 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_mult>
1441 template<
typename NumericT,
typename S1>
1447 m1, gpu_val, 1,
false, is_sign_flip ?
true :
false);
1452 template<
typename NumericT>
1453 matrix_base<NumericT> &
1457 m1, NumericT(gpu_val), 1,
false,
false);
1462 template<
typename NumericT>
1463 matrix_base<NumericT> &
1467 m1, NumericT(gpu_val), 1,
false,
false);
1472 template<
typename NumericT>
1473 matrix_base<NumericT> &
1477 m1, NumericT(gpu_val), 1,
false,
false);
1482 template<
typename NumericT>
1483 matrix_base<NumericT> &
1487 m1, NumericT(gpu_val), 1,
false,
false);
1492 template<
typename NumericT>
1493 matrix_base<NumericT> &
1497 m1, NumericT(gpu_val), 1,
false,
false);
1502 template<
typename NumericT>
1503 matrix_base<NumericT> &
1507 m1, NumericT(gpu_val), 1,
false,
false);
1521 template<
typename LHS,
typename RHS,
typename OP,
typename S1>
1523 matrix_expression< const matrix_expression<const LHS, const RHS, OP>,
const S1, op_div> >::type
1532 template<
typename NumericT,
typename S1>
1534 matrix_expression< const matrix_base<NumericT>,
const S1, op_div> >::type
1541 template<
typename NumericT>
1542 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_div>
1549 template<
typename NumericT>
1550 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_div>
1557 template<
typename NumericT>
1558 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_div>
1565 template<
typename NumericT>
1566 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_div>
1573 template<
typename NumericT>
1574 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_div>
1581 template<
typename NumericT>
1582 matrix_expression< const matrix_base<NumericT>,
const NumericT, op_div>
1593 template<
typename NumericT,
typename S1>
1598 m1, gpu_val, 1,
true,
false);
1603 template<
typename NumericT>
1604 matrix_base<NumericT> &
1608 m1, NumericT(gpu_val), 1,
true,
false);
1613 template<
typename NumericT>
1614 matrix_base<NumericT> &
1618 m1, gpu_val, 1,
true,
false);
1623 template<
typename NumericT>
1624 matrix_base<NumericT> &
1628 m1, gpu_val, 1,
true,
false);
1633 template<
typename NumericT>
1634 matrix_base<NumericT> &
1638 m1, gpu_val, 1,
true,
false);
1643 template<
typename NumericT>
1644 matrix_base<NumericT> &
1648 m1, gpu_val, 1,
true,
false);
1653 template<
typename NumericT>
1654 matrix_base<NumericT> &
1658 m1, gpu_val, 1,
true,
false);
1667 template<
typename NumericT,
typename S1>
1681 template<
typename NumericT,
typename S1>
1692 op_mult>(proxy, NumericT(val));
1696 template<
typename NumericT,
typename S1>
1710 template<
typename NumericT,
typename S1>
1721 op_mult>(proxy, NumericT(val));
1738 template<
typename T>
1739 struct op_executor<matrix_base<T>, op_assign, matrix_base<T> >
1741 static void apply(matrix_base<T> & lhs, matrix_base<T>
const & rhs)
1748 template<
typename T>
1749 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans> >
1751 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>
const & rhs)
1753 matrix_base<T> temp(rhs);
1760 template<
typename T>
1761 struct op_executor<matrix_base<T>, op_inplace_add, matrix_base<T> >
1763 static void apply(matrix_base<T> & lhs, matrix_base<T>
const & rhs)
1765 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
false);
1770 template<
typename T>
1771 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans> >
1773 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>
const & rhs)
1775 matrix_base<T> temp(rhs);
1776 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, temp, T(1), 1,
false,
false);
1781 template<
typename T>
1782 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_base<T> >
1784 static void apply(matrix_base<T> & lhs, matrix_base<T>
const & rhs)
1786 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
true);
1791 template<
typename T>
1792 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans> >
1794 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>
const & rhs)
1796 matrix_base<T> temp(rhs);
1797 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, temp, T(1), 1,
false,
true);
1805 template<
typename T,
typename ScalarType>
1806 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_base<T>, const
ScalarType, op_mult> >
1808 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>
const & proxy)
1815 template<
typename T,
typename ScalarType>
1816 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_base<T>, const
ScalarType, op_mult> >
1818 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>
const & proxy)
1820 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
1825 template<
typename T,
typename ScalarType>
1826 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_base<T>, const
ScalarType, op_mult> >
1828 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>
const & proxy)
1830 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
1838 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
1839 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
1841 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
1843 if (lhs.row_major())
1845 matrix<T> temp(proxy.lhs());
1846 lhs = temp * proxy.rhs();
1850 matrix<T, column_major> temp(proxy.lhs());
1851 lhs = temp * proxy.rhs();
1857 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
1858 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
1860 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
1862 if (lhs.row_major())
1864 matrix<T> temp(proxy.lhs());
1865 lhs += temp * proxy.rhs();
1869 matrix<T, column_major> temp(proxy.lhs());
1870 lhs += temp * proxy.rhs();
1876 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
1877 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
1879 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
1881 if (lhs.row_major())
1883 matrix<T> temp(proxy.lhs());
1884 lhs -= temp * proxy.rhs();
1888 matrix<T, column_major> temp(proxy.lhs());
1889 lhs -= temp * proxy.rhs();
1898 template<
typename T,
typename ScalarType>
1899 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_base<T>, const
ScalarType, op_div> >
1901 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>
const & proxy)
1908 template<
typename T,
typename ScalarType>
1909 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_base<T>, const
ScalarType, op_div> >
1911 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>
const & proxy)
1913 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
false);
1918 template<
typename T,
typename ScalarType>
1919 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_base<T>, const
ScalarType, op_div> >
1921 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>
const & proxy)
1923 viennacl::linalg::ambm(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
true);
1931 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
1932 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
1934 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
1936 if (lhs.row_major())
1938 matrix<T> temp(proxy.lhs());
1939 lhs = temp / proxy.rhs();
1943 matrix<T, column_major> temp(proxy.lhs());
1944 lhs = temp / proxy.rhs();
1950 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
1951 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
1953 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
1955 if (lhs.row_major())
1957 matrix<T> temp(proxy.lhs());
1958 lhs += temp / proxy.rhs();
1962 matrix<T, column_major> temp(proxy.lhs());
1963 lhs += temp / proxy.rhs();
1969 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
1970 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
1972 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
1974 if (lhs.row_major())
1976 matrix<T, row_major> temp(proxy.lhs());
1977 lhs -= temp / proxy.rhs();
1981 matrix<T, column_major> temp(proxy.lhs());
1982 lhs -= temp / proxy.rhs();
1990 template<
typename T,
typename LHS,
typename RHS>
1991 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const LHS, const RHS, op_add> >
1994 template<
typename LHS1,
typename RHS1>
1995 static void apply(matrix_base<T> & lhs, matrix_expression<const LHS1, const RHS1, op_add>
const & proxy)
1997 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
1998 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2000 if (op_aliasing_lhs || op_aliasing_rhs)
2002 matrix_base<T> temp(proxy.lhs());
2003 op_executor<matrix_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2008 op_executor<matrix_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2009 op_executor<matrix_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2014 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_add>
const & proxy)
2017 proxy.lhs(), T(1), 1,
false,
false,
2018 proxy.rhs(), T(1), 1,
false,
false);
2022 template<
typename ScalarType>
2023 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2024 const matrix_base<T>,
2025 op_add>
const & proxy)
2028 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2029 proxy.rhs(), T(1), 1,
false,
false);
2033 template<
typename ScalarType>
2034 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2035 const matrix_base<T>,
2036 op_add>
const & proxy)
2039 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2040 proxy.rhs(), T(1), 1,
false,
false);
2044 template<
typename ScalarType>
2045 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2046 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2047 op_add>
const & proxy)
2050 proxy.lhs(), T(1), 1,
false,
false,
2051 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2055 template<
typename ScalarType>
2056 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2057 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2058 op_add>
const & proxy)
2061 proxy.lhs(), T(1), 1,
false,
false,
2062 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2066 template<
typename ScalarType1,
typename ScalarType2>
2067 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2068 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2069 op_add>
const & proxy)
2072 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2073 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2077 template<
typename ScalarType1,
typename ScalarType2>
2078 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2079 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2080 op_add>
const & proxy)
2083 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2084 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2088 template<
typename ScalarType1,
typename ScalarType2>
2089 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2090 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2091 op_add>
const & proxy)
2094 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2095 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2099 template<
typename ScalarType1,
typename ScalarType2>
2100 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2101 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2102 op_add>
const & proxy)
2105 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2106 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2111 template<
typename T,
typename LHS,
typename RHS>
2112 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const LHS, const RHS, op_prod> >
2114 template<
typename SparseMatrixType>
2115 static void apply(matrix_base<T> & lhs, matrix_expression<
const SparseMatrixType,
2123 template<
typename SparseMatrixType >
2124 static void apply(matrix_base<T> & lhs, matrix_expression<
const SparseMatrixType,
2136 template<
typename T,
typename LHS,
typename RHS>
2137 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const LHS, const RHS, op_add> >
2140 template<
typename LHS1,
typename RHS1>
2141 static void apply(matrix_base<T> & lhs, matrix_expression<const LHS1, const RHS1, op_add>
const & proxy)
2143 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2144 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2146 if (op_aliasing_lhs || op_aliasing_rhs)
2148 matrix_base<T> temp(proxy.lhs());
2149 op_executor<matrix_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2154 op_executor<matrix_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2155 op_executor<matrix_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2160 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_add>
const & proxy)
2163 proxy.lhs(), T(1), 1,
false,
false,
2164 proxy.rhs(), T(1), 1,
false,
false);
2168 template<
typename ScalarType>
2169 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2170 const matrix_base<T>,
2171 op_add>
const & proxy)
2174 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2175 proxy.rhs(), T(1), 1,
false,
false);
2179 template<
typename ScalarType>
2180 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2181 const matrix_base<T>,
2182 op_add>
const & proxy)
2185 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2186 proxy.rhs(), T(1), 1,
false,
false);
2190 template<
typename ScalarType>
2191 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2192 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2193 op_add>
const & proxy)
2196 proxy.lhs(), T(1), 1,
false,
false,
2197 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2201 template<
typename ScalarType>
2202 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2203 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2204 op_add>
const & proxy)
2207 proxy.lhs(), T(1), 1,
false,
false,
2208 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2212 template<
typename ScalarType1,
typename ScalarType2>
2213 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2214 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2215 op_add>
const & proxy)
2218 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2219 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2223 template<
typename ScalarType1,
typename ScalarType2>
2224 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2225 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2226 op_add>
const & proxy)
2229 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2230 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2234 template<
typename ScalarType1,
typename ScalarType2>
2235 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2236 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2237 op_add>
const & proxy)
2240 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2241 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2245 template<
typename ScalarType1,
typename ScalarType2>
2246 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2247 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2248 op_add>
const & proxy)
2251 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2252 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2259 template<
typename T,
typename LHS,
typename RHS>
2260 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const LHS, const RHS, op_add> >
2263 template<
typename LHS1,
typename RHS1>
2264 static void apply(matrix_base<T> & lhs, matrix_expression<const LHS1, const RHS1, op_add>
const & proxy)
2266 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2267 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2269 if (op_aliasing_lhs || op_aliasing_rhs)
2271 matrix_base<T> temp(proxy.lhs());
2272 op_executor<matrix_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2277 op_executor<matrix_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2278 op_executor<matrix_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2283 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_add>
const & proxy)
2286 proxy.lhs(), T(1), 1,
false,
true,
2287 proxy.rhs(), T(1), 1,
false,
true);
2291 template<
typename ScalarType>
2292 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2293 const matrix_base<T>,
2294 op_add>
const & proxy)
2297 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2298 proxy.rhs(), T(1), 1,
false,
true);
2302 template<
typename ScalarType>
2303 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2304 const matrix_base<T>,
2305 op_add>
const & proxy)
2308 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2309 proxy.rhs(), T(1), 1,
false,
true);
2313 template<
typename ScalarType>
2314 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2315 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2316 op_add>
const & proxy)
2319 proxy.lhs(), T(1), 1,
false,
true,
2320 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2324 template<
typename ScalarType>
2325 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2326 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2327 op_add>
const & proxy)
2330 proxy.lhs(), T(1), 1,
false,
true,
2331 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2335 template<
typename ScalarType1,
typename ScalarType2>
2336 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2337 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2338 op_add>
const & proxy)
2341 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2342 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2346 template<
typename ScalarType1,
typename ScalarType2>
2347 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2348 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2349 op_add>
const & proxy)
2352 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2353 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2357 template<
typename ScalarType1,
typename ScalarType2>
2358 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2359 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2360 op_add>
const & proxy)
2363 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2364 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2368 template<
typename ScalarType1,
typename ScalarType2>
2369 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2370 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2371 op_add>
const & proxy)
2374 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2375 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2386 template<
typename T,
typename LHS,
typename RHS>
2387 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const LHS, const RHS, op_sub> >
2390 template<
typename LHS1,
typename RHS1>
2391 static void apply(matrix_base<T> & lhs, matrix_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2393 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2394 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2396 if (op_aliasing_lhs || op_aliasing_rhs)
2398 matrix_base<T> temp(proxy.lhs());
2399 op_executor<matrix_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2404 op_executor<matrix_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2405 op_executor<matrix_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2410 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_sub>
const & proxy)
2413 proxy.lhs(), T(1), 1,
false,
false,
2414 proxy.rhs(), T(1), 1,
false,
true);
2418 template<
typename ScalarType>
2419 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2420 const matrix_base<T>,
2421 op_sub>
const & proxy)
2424 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2425 proxy.rhs(), T(1), 1,
false,
true);
2429 template<
typename ScalarType>
2430 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2431 const matrix_base<T>,
2432 op_sub>
const & proxy)
2435 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2436 proxy.rhs(), T(1), 1,
false,
true);
2440 template<
typename ScalarType>
2441 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2442 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2443 op_sub>
const & proxy)
2446 proxy.lhs(), T(1), 1,
false,
false,
2447 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2451 template<
typename ScalarType>
2452 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2453 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2454 op_sub>
const & proxy)
2457 proxy.lhs(), T(1), 1,
false,
false,
2458 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2462 template<
typename ScalarType1,
typename ScalarType2>
2463 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2464 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2465 op_sub>
const & proxy)
2468 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2469 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2473 template<
typename ScalarType1,
typename ScalarType2>
2474 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2475 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2476 op_sub>
const & proxy)
2479 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2480 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2484 template<
typename ScalarType1,
typename ScalarType2>
2485 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2486 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2487 op_sub>
const & proxy)
2490 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2491 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2495 template<
typename ScalarType1,
typename ScalarType2>
2496 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2497 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2498 op_sub>
const & proxy)
2501 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2502 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2508 template<
typename T,
typename LHS,
typename RHS>
2509 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const LHS, const RHS, op_sub> >
2512 template<
typename LHS1,
typename RHS1>
2513 static void apply(matrix_base<T> & lhs, matrix_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2515 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2516 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2518 if (op_aliasing_lhs || op_aliasing_rhs)
2520 matrix_base<T> temp(proxy.lhs());
2521 op_executor<matrix_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2526 op_executor<matrix_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2527 op_executor<matrix_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2532 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_sub>
const & proxy)
2535 proxy.lhs(), T(1), 1,
false,
false,
2536 proxy.rhs(), T(1), 1,
false,
true);
2540 template<
typename ScalarType>
2541 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2542 const matrix_base<T>,
2543 op_sub>
const & proxy)
2546 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2547 proxy.rhs(), T(1), 1,
false,
true);
2551 template<
typename ScalarType>
2552 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2553 const matrix_base<T>,
2554 op_sub>
const & proxy)
2557 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2558 proxy.rhs(), T(1), 1,
false,
true);
2562 template<
typename ScalarType>
2563 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2564 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2565 op_sub>
const & proxy)
2568 proxy.lhs(), T(1), 1,
false,
false,
2569 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2573 template<
typename ScalarType>
2574 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2575 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2576 op_sub>
const & proxy)
2579 proxy.lhs(), T(1), 1,
false,
false,
2580 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2584 template<
typename ScalarType1,
typename ScalarType2>
2585 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2586 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2587 op_sub>
const & proxy)
2590 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2591 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2595 template<
typename ScalarType1,
typename ScalarType2>
2596 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2597 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2598 op_sub>
const & proxy)
2601 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2602 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2606 template<
typename ScalarType1,
typename ScalarType2>
2607 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2608 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2609 op_sub>
const & proxy)
2612 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2613 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2617 template<
typename ScalarType1,
typename ScalarType2>
2618 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2619 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2620 op_sub>
const & proxy)
2623 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2624 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2631 template<
typename T,
typename LHS,
typename RHS>
2632 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const LHS, const RHS, op_sub> >
2635 template<
typename LHS1,
typename RHS1>
2636 static void apply(matrix_base<T> & lhs, matrix_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2638 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2639 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2641 if (op_aliasing_lhs || op_aliasing_rhs)
2643 matrix_base<T> temp(proxy.lhs());
2644 op_executor<matrix_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2649 op_executor<matrix_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2650 op_executor<matrix_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2655 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_sub>
const & proxy)
2658 proxy.lhs(), T(1), 1,
false,
true,
2659 proxy.rhs(), T(1), 1,
false,
false);
2663 template<
typename ScalarType>
2664 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2665 const matrix_base<T>,
2666 op_sub>
const & proxy)
2669 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2670 proxy.rhs(), T(1), 1,
false,
false);
2674 template<
typename ScalarType>
2675 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2676 const matrix_base<T>,
2677 op_sub>
const & proxy)
2680 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2681 proxy.rhs(), T(1), 1,
false,
false);
2685 template<
typename ScalarType>
2686 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2687 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_mult>,
2688 op_sub>
const & proxy)
2691 proxy.lhs(), T(1), 1,
false,
true,
2692 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2696 template<
typename ScalarType>
2697 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
2698 const matrix_expression<
const matrix_base<T>,
const ScalarType, op_div>,
2699 op_sub>
const & proxy)
2702 proxy.lhs(), T(1), 1,
false,
true,
2703 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2707 template<
typename ScalarType1,
typename ScalarType2>
2708 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2709 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2710 op_sub>
const & proxy)
2713 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2714 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2718 template<
typename ScalarType1,
typename ScalarType2>
2719 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_mult>,
2720 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2721 op_sub>
const & proxy)
2724 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2725 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2729 template<
typename ScalarType1,
typename ScalarType2>
2730 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2731 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_mult>,
2732 op_sub>
const & proxy)
2735 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2736 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2740 template<
typename ScalarType1,
typename ScalarType2>
2741 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const ScalarType1, op_div>,
2742 const matrix_expression<
const matrix_base<T>,
const ScalarType2, op_div>,
2743 op_sub>
const & proxy)
2746 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2747 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2754 template<
typename T,
typename LHS>
2755 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const LHS, const int, op_vector_diag> >
2757 static void apply(matrix_base<T> & lhs, matrix_expression<
const vector_base<T>,
const int, op_vector_diag>
const & proxy)
2764 template<
typename T,
typename LHS>
2765 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const int, op_matrix_diag> >
2767 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_base<T>,
const int, op_matrix_diag>
const & proxy)
2773 template<
typename T,
typename LHS>
2774 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const unsigned int, op_row> >
2776 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_base<T>,
const unsigned int, op_row>
const & proxy)
2783 template<
typename T,
typename LHS>
2784 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const unsigned int, op_column> >
2786 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_base<T>,
const unsigned int, op_column>
const & proxy)
2796 template<
typename T,
typename LHS,
typename RHS,
typename OP>
2797 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const LHS, const RHS, op_element_binary<OP> > >
2800 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_element_binary<OP> >
const & proxy)
2806 template<
typename LHS2,
typename RHS2,
typename OP2>
2807 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_expression<const LHS2, const RHS2, OP2>, op_element_binary<OP> >
const & proxy)
2809 matrix_base<T> temp(proxy.rhs());
2814 template<
typename LHS1,
typename RHS1,
typename OP1>
2815 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS1, const RHS1, OP1>,
const matrix_base<T>, op_element_binary<OP> >
const & proxy)
2817 matrix_base<T> temp(proxy.lhs());
2822 template<
typename LHS1,
typename RHS1,
typename OP1,
2823 typename LHS2,
typename RHS2,
typename OP2>
2824 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS1, const RHS1, OP1>,
2825 const matrix_expression<const LHS2, const RHS2, OP2>,
2826 op_element_binary<OP> >
const & proxy)
2828 matrix_base<T> temp1(proxy.lhs());
2829 matrix_base<T> temp2(proxy.rhs());
2835 template<
typename T,
typename LHS,
typename RHS,
typename OP>
2836 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const LHS, const RHS, op_element_binary<OP> > >
2839 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_element_binary<OP> >
const & proxy)
2841 matrix_base<T> temp(proxy);
2846 template<
typename LHS2,
typename RHS2,
typename OP2>
2847 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_expression<const LHS2, const RHS2, OP2>, op_element_binary<OP> >
const & proxy)
2849 matrix_base<T> temp(proxy.rhs());
2856 template<
typename LHS1,
typename RHS1,
typename OP1>
2857 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS1, const RHS1, OP1>,
const matrix_base<T>, op_element_binary<OP> >
const & proxy)
2859 matrix_base<T> temp(proxy.lhs());
2866 template<
typename LHS1,
typename RHS1,
typename OP1,
2867 typename LHS2,
typename RHS2,
typename OP2>
2868 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS1, const RHS1, OP1>,
2869 const matrix_expression<const LHS2, const RHS2, OP2>,
2870 op_element_binary<OP> >
const & proxy)
2872 matrix_base<T> temp1(proxy.lhs());
2873 matrix_base<T> temp2(proxy.rhs());
2881 template<
typename T,
typename LHS,
typename RHS,
typename OP>
2882 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const LHS, const RHS, op_element_binary<OP> > >
2886 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_element_binary<OP> >
const & proxy)
2888 matrix_base<T> temp(proxy);
2893 template<
typename LHS2,
typename RHS2,
typename OP2>
2894 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_expression<const LHS2, const RHS2, OP2>, op_element_binary<OP> >
const & proxy)
2896 matrix_base<T> temp(proxy.rhs());
2903 template<
typename LHS1,
typename RHS1,
typename OP1>
2904 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS1, const RHS1, OP1>,
const matrix_base<T>, op_element_binary<OP> >
const & proxy)
2906 matrix_base<T> temp(proxy.lhs());
2913 template<
typename LHS1,
typename RHS1,
typename OP1,
2914 typename LHS2,
typename RHS2,
typename OP2>
2915 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS1, const RHS1, OP1>,
2916 const matrix_expression<const LHS2, const RHS2, OP2>,
2917 op_element_binary<OP> >
const & proxy)
2919 matrix_base<T> temp1(proxy.lhs());
2920 matrix_base<T> temp2(proxy.rhs());
2929 template<
typename T,
typename LHS,
typename RHS,
typename OP>
2930 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const LHS, const RHS, op_element_unary<OP> > >
2933 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_element_unary<OP> >
const & proxy)
2939 template<
typename LHS2,
typename RHS2,
typename OP2>
2940 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS2, const RHS2, OP2>,
2941 const matrix_expression<const LHS2, const RHS2, OP2>,
2942 op_element_unary<OP> >
const & proxy)
2944 matrix_base<T> temp(proxy.rhs());
2949 template<
typename T,
typename LHS,
typename RHS,
typename OP>
2950 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const LHS, const RHS, op_element_unary<OP> > >
2953 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_element_unary<OP> >
const & proxy)
2955 matrix_base<T> temp(proxy);
2960 template<
typename LHS2,
typename RHS2,
typename OP2>
2961 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS2, const RHS2, OP2>,
2962 const matrix_expression<const LHS2, const RHS2, OP2>,
2963 op_element_unary<OP> >
const & proxy)
2965 matrix_base<T> temp(proxy.rhs());
2971 template<
typename T,
typename LHS,
typename RHS,
typename OP>
2972 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const LHS, const RHS, op_element_unary<OP> > >
2975 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_element_unary<OP> >
const & proxy)
2977 matrix_base<T> temp(proxy);
2982 template<
typename LHS2,
typename RHS2,
typename OP2>
2983 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<const LHS2, const RHS2, OP2>,
2984 const matrix_expression<const LHS2, const RHS2, OP2>,
2985 op_element_unary<OP> >
const & proxy)
2987 matrix_base<T> temp(proxy.rhs());
2998 template<
typename T>
2999 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_base<T>, const matrix_base<T>, op_mat_mat_prod> >
3001 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_mat_mat_prod>
const & rhs)
3008 template<
typename T>
3009 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_base<T>,
3010 const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3013 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
3014 const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3015 op_mat_mat_prod>
const & rhs)
3022 template<
typename T>
3023 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3024 const matrix_base<T>,
3027 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3028 const matrix_base<T>,
3029 op_mat_mat_prod>
const & rhs)
3036 template<
typename T>
3037 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3038 const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3041 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3042 const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3043 op_mat_mat_prod>
const & rhs)
3051 template<
typename T>
3052 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_base<T>, const matrix_base<T>, op_mat_mat_prod> >
3054 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_mat_mat_prod>
const & rhs)
3061 template<
typename T>
3062 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_base<T>,
3063 const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3066 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
3067 const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3068 op_mat_mat_prod>
const & rhs)
3075 template<
typename T>
3076 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3077 const matrix_base<T>,
3080 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3081 const matrix_base<T>,
3082 op_mat_mat_prod>
const & rhs)
3089 template<
typename T>
3090 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3091 const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3094 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3095 const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3096 op_mat_mat_prod>
const & rhs)
3104 template<
typename T>
3105 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_base<T>, const matrix_base<T>, op_mat_mat_prod> >
3107 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_mat_mat_prod>
const & rhs)
3114 template<
typename T>
3115 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_base<T>,
3116 const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3119 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_base<T>,
3120 const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3121 op_mat_mat_prod>
const & rhs)
3128 template<
typename T>
3129 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3130 const matrix_base<T>,
3133 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3134 const matrix_base<T>,
3135 op_mat_mat_prod>
const & rhs)
3142 template<
typename T>
3143 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3144 const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3147 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3148 const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3149 op_mat_mat_prod>
const & rhs)
3158 template<
typename T>
3159 struct op_executor<vector_base<T>, op_assign, vector_expression<const matrix_base<T>, const vector_base<T>, op_prod> >
3161 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_base<T>,
const vector_base<T>, op_prod>
const & rhs)
3166 vector_base<T> temp(rhs);
3175 template<
typename T>
3176 struct op_executor<vector_base<T>, op_assign, vector_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3177 const vector_base<T>,
3180 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3181 const vector_base<T>,
3182 op_prod>
const & rhs)
3187 vector_base<T> temp(rhs);
3197 template<
typename T>
3198 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const matrix_base<T>, const vector_base<T>, op_prod> >
3200 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_base<T>,
const vector_base<T>, op_prod>
const & rhs)
3202 vector_base<T> temp(rhs);
3208 template<
typename T>
3209 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3210 const vector_base<T>,
3213 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3214 const vector_base<T>,
3215 op_prod>
const & rhs)
3217 vector_base<T> temp(rhs);
3224 template<
typename T>
3225 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const matrix_base<T>, const vector_base<T>, op_prod> >
3227 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_base<T>,
const vector_base<T>, op_prod>
const & rhs)
3229 vector_base<T> temp(rhs);
3235 template<
typename T>
3236 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const matrix_expression<const matrix_base<T>, const matrix_base<T>, op_trans>,
3237 const vector_base<T>,
3240 static void apply(vector_base<T> & lhs, vector_expression<
const matrix_expression<
const matrix_base<T>,
const matrix_base<T>, op_trans>,
3241 const vector_base<T>,
3242 op_prod>
const & rhs)
3244 vector_base<T> temp(rhs);
3254 template<
typename T>
3255 struct op_executor<matrix_base<T>, op_assign, matrix_expression<const vector_base<T>, const vector_base<T>, op_prod> >
3257 static void apply(matrix_base<T> & lhs, matrix_expression<
const vector_base<T>,
const vector_base<T>, op_prod>
const & rhs)
3265 template<
typename T,
typename ScalarType>
3266 struct op_executor<matrix_base<T>, op_assign, matrix_expression< const matrix_expression<const vector_base<T>, const vector_base<T>, op_prod>,
3270 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const vector_base<T>,
const vector_base<T>, op_prod>,
3272 op_mult>
const & rhs)
3280 template<
typename T>
3281 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression<const vector_base<T>, const vector_base<T>, op_prod> >
3283 static void apply(matrix_base<T> & lhs, matrix_expression<
const vector_base<T>,
const vector_base<T>, op_prod>
const & rhs)
3290 template<
typename T,
typename ScalarType>
3291 struct op_executor<matrix_base<T>, op_inplace_add, matrix_expression< const matrix_expression<const vector_base<T>, const vector_base<T>, op_prod>,
3295 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const vector_base<T>,
const vector_base<T>, op_prod>,
3297 op_mult>
const & rhs)
3304 template<
typename T>
3305 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression<const vector_base<T>, const vector_base<T>, op_prod> >
3307 static void apply(matrix_base<T> & lhs, matrix_expression<
const vector_base<T>,
const vector_base<T>, op_prod>
const & rhs)
3314 template<
typename T,
typename ScalarType>
3315 struct op_executor<matrix_base<T>, op_inplace_sub, matrix_expression< const matrix_expression<const vector_base<T>, const vector_base<T>, op_prod>,
3319 static void apply(matrix_base<T> & lhs, matrix_expression<
const matrix_expression<
const vector_base<T>,
const vector_base<T>, op_prod>,
3321 op_mult>
const & rhs)
Simple enable-if variant that uses the SFINAE pattern.
bool operator==(self_type const &other)
A tag class representing multiplication by a scalar.
matrix(NumericT *ptr_to_mem, viennacl::memory_types mem_type, size_type rows, size_type cols)
Wraps a CUDA or host buffer provided by the user.
void matrix_diag_to_vector(const matrix_base< NumericT > &A, int k, vector_base< NumericT > &v)
Dispatcher interface for v = diag(A, k)
static vcl_size_t mem_index(vcl_size_t i, vcl_size_t j, vcl_size_t, vcl_size_t num_cols)
Returns the memory offset for entry (i,j) of a dense matrix.
void memory_write(mem_handle &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_write, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.
viennacl::enable_if< viennacl::is_any_sparse_matrix< M1 >::value, matrix_expression< const M1, const M1, op_trans > >::type trans(const M1 &mat)
Returns an expression template class representing a transposed matrix.
Worker class for decomposing expression templates.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Implementations of dense matrix related operations including matrix-vector products.
size_type internal_size() const
Returns the total amount of allocated memory in multiples of sizeof(NumericT)
self_type & operator=(const self_type &other)
matrix(zero_matrix< NumericT > const &m)
Creates the matrix from the supplied zero matrix.
Helper class for checking whether a matrix has a row-major layout.
Helper struct for checking whether a type represents a sign flip on a viennacl::scalar<> ...
void matrix_assign(matrix_base< NumericT > &mat, NumericT s, bool clear=false)
matrix_expression< const self_type, const NumericT, op_mult > operator-() const
Sign flip for the matrix. Emulated to be equivalent to -1.0 * matrix.
A tag class representing the extraction of a matrix column to a vector.
vcl_size_t internal_size1(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
A tag class representing a matrix given by a vector placed on a certain (off-)diagonal.
A tag class representing subtraction.
void am(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
viennacl::context context() const
vcl_size_t internal_size2(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
A tag indicating iteration along increasing row index of a matrix.
Expression template class for representing a tree of expressions which ultimately result in a matrix...
void ambm(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
void clear(VectorType &vec)
Generic routine for setting all entries of a vector to zero. This is the version for non-ViennaCL obj...
This file provides the forward declarations for the main types used within ViennaCL.
A tag class representing division.
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM.
entry_proxy< NumericT > operator()(size_type row_index, size_type col_index)
Read-write access to a single element of the matrix/matrix_range/matrix_slice.
Represents a vector consisting of 1 at a given index and zeros otherwise. To be used as an initialize...
viennacl::enable_if< viennacl::is_scalar< S1 >::value, matrix_base< NumericT > & >::type operator/=(matrix_base< NumericT > &m1, S1 const &gpu_val)
Scales a matrix by a GPU scalar value.
viennacl::enable_if< viennacl::is_any_scalar< S1 >::value, matrix_expression< const matrix_base< NumericT >, const S1, op_mult >>::type operator*(S1 const &value, matrix_base< NumericT > const &m1)
Operator overload for the expression alpha * m1, where alpha is a host scalar (float or double) and m...
viennacl::scalar< float > s1
vcl_size_t internal_size(vector_base< NumericT > const &vec)
Helper routine for obtaining the buffer length of a ViennaCL vector.
An expression template class that represents a binary operation that yields a vector.
void element_op(matrix_base< T > &A, matrix_expression< const matrix_base< T >, const matrix_base< T >, OP > const &proxy)
Implementation of the element-wise operation A = B .* C and A = B ./ C for matrices (using MATLAB syn...
Forward declaration of dense matrix classes.
bool op_aliasing(vector_base< NumericT > const &, B const &)
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
bool operator!=(self_type const &other)
matrix(scalar_matrix< NumericT > const &m)
Creates the matrix from the supplied scalar matrix.
vcl_size_t size1() const
Returns the size of the result vector.
self_type operator++(int)
viennacl::vector< NumericT > operator-(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 - A * v2', where A is a matrix.
A tag class representing the (off-)diagonal of a matrix.
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
void resize(size_type rows, size_type columns, bool preserve=true)
Resizes the matrix. Existing entries can optionally be preserved.
viennacl::enable_if< viennacl::is_scalar< S1 >::value, matrix_base< NumericT > & >::type operator*=(matrix_base< NumericT > &m1, S1 const &gpu_val)
Scales a matrix by a GPU scalar value.
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
matrix_base()
The default constructor. Does not allocate any memory.
void matrix_row(const matrix_base< NumericT > &A, unsigned int i, vector_base< NumericT > &v)
matrix(matrix_expression< LHS, RHS, OP > const &proxy)
void resize(MatrixType &matrix, vcl_size_t rows, vcl_size_t cols)
Generic resize routine for resizing a matrix (ViennaCL, uBLAS, etc.) to a new size/dimension.
MatrixT::value_type value_type
void clear()
Resets all entries to zero.
MatrixT & operator()(void) const
Implementations of operations using sparse matrices.
A tag class representing addition.
matrix(const self_type &other)
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
matrix_expression(LHS &lhs, RHS &rhs)
void scaled_rank_1_update(matrix_base< NumericT > &mat1, S1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, const vector_base< NumericT > &vec1, const vector_base< NumericT > &vec2)
The implementation of the operation mat += alpha * vec1 * vec2^T, i.e. a scaled rank 1 update...
viennacl::enable_if< viennacl::is_any_scalar< S1 >::value, matrix_expression< const matrix_expression< const LHS, const RHS, OP >, const S1, op_div > >::type operator/(matrix_expression< const LHS, const RHS, OP > const &proxy, S1 const &val)
Operator overload for the division of a matrix expression by a scalar from the right, e.g. (beta * m1) / alpha. Here, beta * m1 is wrapped into a matrix_expression and then divided by alpha.
Determines whether a given expression has a row-major matrix layout.
size_type size2() const
Returns the number of columns.
matrix()
The default constructor. Does not allocate any memory.
handle_type & handle()
Returns the OpenCL handle, non-const-version.
matrix(identity_matrix< NumericT > const &m)
Creates the matrix from the supplied identity matrix.
void trans(const matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > &proxy, matrix_base< NumericT > &temp_trans)
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
viennacl::memory_types active_handle_id(T const &obj)
Returns an ID for the currently active memory domain of an object.
Represents a vector consisting of zeros only. To be used as an initializer for viennacl::vector, vector_range, or vector_slize only.
void matrix_column(const matrix_base< NumericT > &A, unsigned int j, vector_base< NumericT > &v)
size_type size1() const
Returns the number of rows.
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
base_type::size_type size_type
matrix(const base_type &other)
RHS & rhs() const
Get right hand side operand.
viennacl::vector< NumericT > operator+(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 + A * v2', where A is a matrix.
matrix_iterator(MatrixT &mat, vcl_size_t start_row, vcl_size_t start_col)
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
A tag class representing matrix-vector products and element-wise multiplications. ...
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
bool row_major(T const &)
value_type operator*(void)
A tag class representing transposed matrices.
Helper implementations that deduce the dimensions of the supplied matrix-valued expressions.
matrix(NumericT *ptr_to_mem, viennacl::memory_types mem_type, size_type rows, size_type internal_row_count, size_type cols, size_type internal_col_count)
Wraps a CUDA or host buffer provided by the user including padding of rows and columns.
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
size_type internal_size2() const
Returns the internal number of columns. Usually required for launching OpenCL kernels only...
self_type & operator*=(char val)
Scales the matrix by a char (8-bit integer)
void memory_create(mem_handle &handle, vcl_size_t size_in_bytes, viennacl::context const &ctx, const void *host_ptr=NULL)
Creates an array of the specified size. If the second argument is provided, the buffer is initialized...
viennacl::matrix< float > m1
void matrix_diagonal_assign(matrix_base< NumericT > &mat, NumericT s)
size_type internal_size1() const
Returns the internal number of rows. Usually required for launching OpenCL kernels only...
matrix(size_type rows, size_type columns, viennacl::context ctx=viennacl::context())
Creates the matrix with the given dimensions.
static vcl_size_t mem_index(vcl_size_t i, vcl_size_t j, vcl_size_t num_rows, vcl_size_t)
Returns the memory offset for entry (i,j) of a dense matrix.
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_column > column(const matrix_base< NumericT, F > &A, unsigned int j)
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
self_type & operator+=(const matrix_expression< const LHS, const RHS, OP > &proxy)
self_type & operator/=(char val)
Scales the matrix by a char (8-bit integer)
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
void resize(size_type rows, size_type columns, bool preserve=true)
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
void matrix_diag_from_vector(const vector_base< NumericT > &v, int k, matrix_base< NumericT > &A)
Dispatcher interface for A = diag(v, k)
LHS & lhs() const
Get left hand side operand.
A tag class representing the extraction of a matrix row to a vector.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
void ambm_m(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Implementation of the ViennaCL scalar class.
A collection of compile time type deductions.
A tag for row-major storage of a dense matrix.
self_type & operator++(void)
ram_handle_type & ram_handle()
Returns the handle to a buffer in CPU RAM. NULL is returned if no such buffer has been allocated...
A tag indicating iteration along increasing columns index of a matrix.
Simple enable-if variant that uses the SFINAE pattern.
self_type & operator-=(const matrix_expression< const LHS, const RHS, OP > &proxy)
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)