1 #ifndef VIENNACL_MATRIX_OPERATIONS_HPP_
2 #define VIENNACL_MATRIX_OPERATIONS_HPP_
64 template<
class TYPE,
typename F,
unsigned int ALIGNMENT>
78 &&
"Operands must have same dimension and memory layout in this version of ViennaCL!");
91 template <
typename M1,
typename M2>
102 size_t block_size = 15;
188 template<
class TYPE,
typename F,
unsigned int ALIGNMENT>
202 &&
"Operands must have same dimension and memory layout in this version of ViennaCL!");
215 template<
class TYPE,
typename F,
unsigned int ALIGNMENT>
226 &&
"Operands must have same dimension and memory layout in this version of ViennaCL!");
239 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT>
257 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT>
276 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT>
296 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT,
unsigned int VECTOR_ALIGNMENT>
315 template<
class TYPE,
typename F,
unsigned int ALIGNMENT,
unsigned int VECTOR_ALIGNMENT>
322 assert(vec.
handle() != result.
handle() &&
"No direct inplace matrix-vector product possible. Introduce a temporary!");
329 k(mat, cl_uint(mat.
size1()), cl_uint(mat.
size2()),
343 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT,
unsigned int VECTOR_ALIGNMENT>
357 op_prod >(proxy, vec);
368 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT,
unsigned int VECTOR_ALIGNMENT>
375 assert(vec.
handle() != result.
handle() &&
"No direct inplace matrix-vector product possible. Introduce a temporary!");
388 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT,
unsigned int VECTOR_ALIGNMENT>
405 template<
class TYPE,
typename F1,
typename F2,
typename F3,
unsigned int ALIGNMENT>
417 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
438 k(A, cl_uint(0), cl_uint(0),
441 B, cl_uint(0), cl_uint(0),
444 C, cl_uint(0), cl_uint(0),
457 template<
typename T1,
typename T2,
typename T3>
463 typedef typename T1::value_type::value_type value_type;
469 assert(C.
get().handle() != A.
get().handle()
470 && C.
get().handle() != B.
get().handle()
471 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
492 cl_uint(A.
get().internal_size1()), cl_uint(A.
get().internal_size2()),
495 cl_uint(B.
get().internal_size1()), cl_uint(B.
get().internal_size2()),
498 cl_uint(C.
get().internal_size1()), cl_uint(C.
get().internal_size2()),
510 template<
class TYPE,
typename F1,
typename F2,
typename F3,
unsigned int ALIGNMENT>
517 assert(A.size2() == C.
size1());
518 assert(A.size1() == B.
size1());
523 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
540 k(A.lhs(), cl_uint(0), cl_uint(0),
541 cl_uint(A.lhs().size1()), cl_uint(A.lhs().size2()),
542 cl_uint(A.lhs().internal_size1()), cl_uint(A.lhs().internal_size2()),
543 B, cl_uint(0), cl_uint(0),
546 C, cl_uint(0), cl_uint(0),
560 template <
typename M1,
typename M2,
typename M3>
567 typedef typename M1::value_type::value_type value_type;
568 assert(A_trans.size2() == C.
size1());
569 assert(A_trans.size1() == B.
size1());
572 assert(C.
get().handle() != A_trans.lhs().get().handle()
573 && C.
get().handle() != B.
get().handle()
574 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
593 cl_uint(A.
get().internal_size1()), cl_uint(A.
get().internal_size2()),
596 cl_uint(B.
get().internal_size1()), cl_uint(B.
get().internal_size2()),
599 cl_uint(C.
get().internal_size1()), cl_uint(C.
get().internal_size2()),
613 template<
class TYPE,
typename F1,
typename F2,
typename F3,
unsigned int ALIGNMENT>
621 assert(A.
size2() == B.size2());
622 assert(B.size1() == C.
size2());
626 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
643 k(A, cl_uint(0), cl_uint(0),
646 B.lhs(), cl_uint(0), cl_uint(0),
647 cl_uint(B.lhs().size1()), cl_uint(B.lhs().size2()),
648 cl_uint(B.lhs().internal_size1()), cl_uint(B.lhs().internal_size2()),
649 C, cl_uint(0), cl_uint(0),
663 template <
typename M1,
typename M2,
typename M3>
670 typedef typename M1::value_type::value_type value_type;
672 assert(A.
size2() == B_trans.size2());
673 assert(B_trans.size1() == C.
size2());
675 assert(C.
get().handle() != A.
get().handle()
676 && C.
get().handle() != B_trans.lhs().get().handle()
677 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
695 cl_uint(A.
get().internal_size1()), cl_uint(A.
get().internal_size2()),
698 cl_uint(B.
get().internal_size1()), cl_uint(B.
get().internal_size2()),
701 cl_uint(C.
get().internal_size1()), cl_uint(C.
get().internal_size2()),
720 template<
class TYPE,
typename F1,
typename F2,
typename F3,
unsigned int ALIGNMENT>
729 assert(A.size2() == C.
size1());
730 assert(A.size1() == B.size2());
731 assert(B.size1() == C.
size2());
735 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
752 k(A.lhs(), cl_uint(0), cl_uint(0),
753 cl_uint(A.lhs().size1()), cl_uint(A.lhs().size2()),
754 cl_uint(A.lhs().internal_size1()), cl_uint(A.lhs().internal_size2()),
755 B.lhs(), cl_uint(0), cl_uint(0),
756 cl_uint(B.lhs().size1()), cl_uint(B.lhs().size2()),
757 cl_uint(B.lhs().internal_size1()), cl_uint(B.lhs().internal_size2()),
758 C, cl_uint(0), cl_uint(0),
772 template <
typename M1,
typename M2,
typename M3>
781 typedef typename M1::value_type::value_type value_type;
782 assert(A_trans.size2() == C.
size1());
783 assert(A_trans.size1() == B_trans.size2());
784 assert(B_trans.size1() == C.
size2());
786 assert(C.
get().handle() != A_trans.lhs().get().handle()
787 && C.
get().handle() != B_trans.lhs().get().handle()
788 &&
"No direct inplace matrix-matrix product possible. Introduce a temporary!");
807 cl_uint(A.
get().internal_size1()), cl_uint(A.
get().internal_size2()),
810 cl_uint(B.
get().internal_size1()), cl_uint(B.
get().internal_size2()),
813 cl_uint(C.
get().internal_size1()), cl_uint(C.
get().internal_size2()),
832 template<
class SCALARTYPE,
unsigned int VA1,
unsigned int VA2>
840 op_prod>(vec1, vec2);
853 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT>
879 template<
class SCALARTYPE,
typename F,
unsigned int ALIGNMENT>
905 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
906 template <
typename F,
unsigned int MAT_ALIGNMENT>
910 viennacl::op_prod> & proxy)
913 if (proxy.rhs().handle() == this->
handle())
933 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
934 template <
typename F,
unsigned int MAT_ALIGNMENT>
950 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
951 template <
typename F,
unsigned int MAT_ALIGNMENT>
969 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
970 template <
typename F,
unsigned int MAT_ALIGNMENT>
976 assert(proxy.lhs().size1() ==
size());
987 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
988 template <
typename F,
unsigned int MAT_ALIGNMENT>
994 assert(proxy.lhs().size1() ==
size());
997 result = *
this - result;
1010 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1011 template <
typename F,
unsigned int MAT_ALIGNMENT>
1017 viennacl::op_prod> & proxy)
1020 if (proxy.rhs().handle() == this->
handle())
1040 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1041 template <
typename F,
unsigned int MAT_ALIGNMENT>
1059 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1060 template <
typename F,
unsigned int MAT_ALIGNMENT>
1080 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1081 template <
typename F,
unsigned int MAT_ALIGNMENT>
1089 assert(proxy.lhs().size1() ==
size());
1100 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1101 template <
typename F,
unsigned int MAT_ALIGNMENT>
1109 assert(proxy.lhs().size1() ==
size());
1112 result = *
this - result;