22 #ifndef _BLAZE_MATH_DENSE_STATICMATRIX_H_
23 #define _BLAZE_MATH_DENSE_STATICMATRIX_H_
162 template<
typename Type
166 class StaticMatrix :
public DenseMatrix< StaticMatrix<Type,M,N,SO>, SO >
167 ,
private AlignedStorage<Type>
176 enum { NN = N + ( IT::size - ( N % IT::size ) ) % IT::size };
215 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3 );
216 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4 );
217 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5 );
218 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
220 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
221 const Type& v6,
const Type& v7 );
222 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
223 const Type& v6,
const Type& v7,
const Type& v8 );
224 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
225 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9 );
226 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
227 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9,
const Type& v10 );
240 inline Type*
data ();
241 inline const Type*
data ()
const;
242 inline Type*
data (
size_t i );
243 inline const Type*
data (
size_t i )
const;
264 template<
typename Other >
266 operator*=( Other rhs );
268 template<
typename Other >
270 operator/=( Other rhs );
277 inline size_t rows()
const;
281 inline size_t capacity(
size_t i )
const;
283 inline size_t nonZeros(
size_t i )
const;
285 inline void reset(
size_t i );
289 template<
typename Other >
inline StaticMatrix& scale(
const Other& scalar );
298 template<
typename MT >
299 struct VectorizedAssign {
300 enum { value = vectorizable && MT::vectorizable &&
310 template<
typename MT >
311 struct VectorizedAddAssign {
312 enum { value = vectorizable && MT::vectorizable &&
313 IsSame<Type,typename MT::ElementType>::value &&
314 IntrinsicTrait<Type>::addition &&
315 IsRowMajorMatrix<MT>::value };
323 template<
typename MT >
324 struct VectorizedSubAssign {
325 enum { value = vectorizable && MT::vectorizable &&
326 IsSame<Type,typename MT::ElementType>::value &&
327 IntrinsicTrait<Type>::subtraction &&
328 IsRowMajorMatrix<MT>::value };
337 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
338 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
341 template<
typename MT,
bool SO2 >
342 inline typename DisableIf< VectorizedAssign<MT> >::Type
343 assign(
const DenseMatrix<MT,SO2>& rhs );
345 template<
typename MT,
bool SO2 >
346 inline typename EnableIf< VectorizedAssign<MT> >::Type
347 assign(
const DenseMatrix<MT,SO2>& rhs );
349 template<
typename MT >
inline void assign(
const SparseMatrix<MT,SO>& rhs );
350 template<
typename MT >
inline void assign(
const SparseMatrix<MT,!SO>& rhs );
352 template<
typename MT,
bool SO2 >
353 inline typename DisableIf< VectorizedAddAssign<MT> >::Type
354 addAssign(
const DenseMatrix<MT,SO2>& rhs );
356 template<
typename MT,
bool SO2 >
357 inline typename EnableIf< VectorizedAddAssign<MT> >::Type
358 addAssign(
const DenseMatrix<MT,SO2>& rhs );
360 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,SO>& rhs );
361 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,!SO>& rhs );
363 template<
typename MT,
bool SO2 >
364 inline typename DisableIf< VectorizedSubAssign<MT> >::Type
365 subAssign(
const DenseMatrix<MT,SO2>& rhs );
367 template<
typename MT,
bool SO2 >
368 inline typename EnableIf< VectorizedSubAssign<MT> >::Type
369 subAssign(
const DenseMatrix<MT,SO2>& rhs );
371 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,SO>& rhs );
372 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,!SO>& rhs );
419 template<
typename Type
425 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
428 for(
size_t i=0UL; i<M*NN; ++i )
440 template<
typename Type
446 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
448 for(
size_t i=0UL; i<M; ++i ) {
449 for(
size_t j=0UL; j<N; ++j )
453 for(
size_t j=N; j<NN; ++j )
468 template<
typename Type
474 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
476 for(
size_t i=0UL; i<M*NN; ++i )
487 template<
typename Type
491 template<
typename Other
495 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
497 for(
size_t i=0UL; i<M; ++i ) {
498 for(
size_t j=0UL; j<N; ++j )
502 for(
size_t j=N; j<NN; ++j )
520 template<
typename Type
524 template<
typename MT
530 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
533 throw std::invalid_argument(
"Invalid setup of static matrix" );
536 for(
size_t i=0UL; i<M; ++i ) {
564 template<
typename Type
571 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
586 for(
size_t i=0UL; i<M; ++i ) {
587 for(
size_t j=N; j<NN; ++j )
613 template<
typename Type
620 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
637 for(
size_t i=0UL; i<M; ++i ) {
638 for(
size_t j=N; j<NN; ++j )
667 template<
typename Type
672 const Type& v3,
const Type& v4 )
675 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
686 else if( M == 2UL ) {
702 for(
size_t i=0UL; i<M; ++i ) {
703 for(
size_t j=N; j<NN; ++j )
731 template<
typename Type
736 const Type& v4,
const Type& v5 )
739 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
760 for(
size_t i=0UL; i<M; ++i ) {
761 for(
size_t j=N; j<NN; ++j )
793 template<
typename Type
798 const Type& v4,
const Type& v5,
const Type& v6 )
801 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
814 else if( M == 2UL ) {
824 else if( M == 3UL ) {
844 for(
size_t i=0UL; i<M; ++i ) {
845 for(
size_t j=N; j<NN; ++j )
875 template<
typename Type
880 const Type& v4,
const Type& v5,
const Type& v6,
884 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
909 for(
size_t i=0UL; i<M; ++i ) {
910 for(
size_t j=N; j<NN; ++j )
943 template<
typename Type
948 const Type& v4,
const Type& v5,
const Type& v6,
949 const Type& v7,
const Type& v8 )
952 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
967 else if( M == 2UL ) {
979 else if( M == 4UL ) {
1003 for(
size_t i=0UL; i<M; ++i ) {
1004 for(
size_t j=N; j<NN; ++j )
1005 v_[i*NN+j] = Type();
1039 template<
typename Type
1044 const Type& v4,
const Type& v5,
const Type& v6,
1045 const Type& v7,
const Type& v8,
const Type& v9 )
1048 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
1064 else if( M == 3UL ) {
1072 v_[2UL*NN+1UL] = v8;
1073 v_[2UL*NN+2UL] = v9;
1090 for(
size_t i=0UL; i<M; ++i ) {
1091 for(
size_t j=N; j<NN; ++j )
1092 v_[i*NN+j] = Type();
1127 template<
typename Type
1132 const Type& v4,
const Type& v5,
const Type& v6,
1133 const Type& v7,
const Type& v8,
const Type& v9,
1137 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
1154 else if( M == 2UL ) {
1168 else if( M == 5UL ) {
1174 v_[2UL*NN+1UL] = v6;
1176 v_[3UL*NN+1UL] = v8;
1178 v_[4UL*NN+1UL] = v10;
1196 for(
size_t i=0UL; i<M; ++i ) {
1197 for(
size_t j=N; j<NN; ++j )
1198 v_[i*NN+j] = Type();
1220 template<
typename Type
1241 template<
typename Type
1260 template<
typename Type
1276 template<
typename Type
1293 template<
typename Type
1311 template<
typename Type
1334 template<
typename Type
1358 template<
typename Type
1382 template<
typename Type
1406 template<
typename Type
1414 return v_ + i*NN + N;
1430 template<
typename Type
1438 return v_ + i*NN + N;
1454 template<
typename Type
1462 return v_ + i*NN + N;
1481 template<
typename Type
1487 for(
size_t i=0UL; i<M; ++i )
1488 for(
size_t j=0UL; j<N; ++j )
1504 template<
typename Type
1510 for(
size_t i=0UL; i<M; ++i )
1511 for(
size_t j=0UL; j<N; ++j )
1512 v_[i*NN+j] = rhs(i,j);
1525 template<
typename Type
1529 template<
typename Other
1534 for(
size_t i=0UL; i<M; ++i )
1535 for(
size_t j=0UL; j<N; ++j )
1536 v_[i*NN+j] = rhs(i,j);
1554 template<
typename Type
1558 template<
typename MT
1565 throw std::invalid_argument(
"Invalid assignment to static matrix" );
1567 if( (~rhs).canAlias(
this ) ) {
1592 template<
typename Type
1596 template<
typename MT
1603 throw std::invalid_argument(
"Matrix sizes do not match" );
1605 if( (~rhs).canAlias(
this ) ) {
1628 template<
typename Type
1632 template<
typename MT
1639 throw std::invalid_argument(
"Matrix sizes do not match" );
1641 if( (~rhs).canAlias(
this ) ) {
1664 template<
typename Type
1668 template<
typename MT
1672 if( M != N || (~rhs).
rows() != M || (~rhs).
columns() != M )
1673 throw std::invalid_argument(
"Matrix sizes do not match" );
1676 return this->operator=( tmp );
1688 template<
typename Type
1692 template<
typename Other >
1696 return operator=( (*
this) * rhs );
1710 template<
typename Type
1714 template<
typename Other >
1720 return operator=( (*
this) / rhs );
1738 template<
typename Type
1754 template<
typename Type
1773 template<
typename Type
1789 template<
typename Type
1811 template<
typename Type
1828 template<
typename Type
1834 size_t nonzeros( 0UL );
1836 for(
size_t i=0UL; i<M; ++i )
1837 for(
size_t j=0UL; j<N; ++j )
1857 template<
typename Type
1865 const size_t jend( (i+1UL)*NN );
1866 size_t nonzeros( 0UL );
1868 for(
size_t j=i*NN; j<jend; ++j )
1882 template<
typename Type
1890 for(
size_t i=0UL; i<M; ++i )
1891 for(
size_t j=0UL; j<N; ++j )
1892 reset( v_[i*NN+j] );
1908 template<
typename Type
1917 for(
size_t j=0UL; j<N; ++j )
1918 reset( v_[i*NN+j] );
1928 template<
typename Type
1936 for(
size_t i=1UL; i<M; ++i )
1937 for(
size_t j=0UL; j<i; ++j )
1938 swap( v_[i*NN+j], v_[j*NN+i] );
1962 template<
typename Type
1968 if( M != N )
return false;
1970 for(
size_t i=1UL; i<M; ++i ) {
1971 for(
size_t j=0UL; j<i; ++j ) {
1987 template<
typename Type
1993 if( M != N )
return false;
1995 for(
size_t i=1UL; i<M; ++i ) {
1996 for(
size_t j=0UL; j<i; ++j ) {
1997 if( !
equal( v_[i*NN+j], v_[j*NN+i] ) )
2013 template<
typename Type
2017 template<
typename Other >
2020 for(
size_t i=0UL; i<M; ++i )
2021 for(
size_t j=0UL; j<N; ++j )
2022 v_[i*NN+j] *= scalar;
2036 template<
typename Type
2044 for(
size_t i=0UL; i<M; ++i ) {
2045 for(
size_t j=0UL; j<N; ++j ) {
2046 swap( v_[i*NN+j], m(i,j) );
2071 template<
typename Type
2075 template<
typename Other >
2078 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2093 template<
typename Type
2097 template<
typename Other >
2100 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2117 template<
typename Type
2131 return load( &v_[i*NN+j] );
2147 template<
typename Type
2151 template<
typename MT
2158 for(
size_t i=0UL; i<M; ++i ) {
2159 for(
size_t j=0UL; j<N; ++j ) {
2160 v_[i*NN+j] = (~rhs)(i,j);
2178 template<
typename Type
2182 template<
typename MT
2191 for(
size_t i=0UL; i<M; ++i ) {
2192 for(
size_t j=0UL; j<N; j+=IT::size ) {
2193 store( &v_[i*NN+j], (~rhs).
get(i,j) );
2211 template<
typename Type
2215 template<
typename MT >
2222 for(
size_t i=0UL; i<M; ++i )
2223 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2224 v_[i*NN+element->index()] = element->value();
2240 template<
typename Type
2244 template<
typename MT >
2251 for(
size_t j=0UL; j<N; ++j )
2252 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2253 v_[element->index()*NN+j] = element->value();
2269 template<
typename Type
2273 template<
typename MT
2280 for(
size_t i=0UL; i<M; ++i ) {
2281 for(
size_t j=0UL; j<N; ++j ) {
2282 v_[i*NN+j] += (~rhs)(i,j);
2300 template<
typename Type
2304 template<
typename MT
2313 for(
size_t i=0UL; i<M; ++i ) {
2314 for(
size_t j=0UL; j<N; j+=IT::size ) {
2315 store( &v_[i*NN+j],
load( &v_[i*NN+j] ) + (~rhs).
get(i,j) );
2333 template<
typename Type
2337 template<
typename MT >
2344 for(
size_t i=0UL; i<M; ++i )
2345 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2346 v_[i*NN+element->index()] += element->value();
2362 template<
typename Type
2366 template<
typename MT >
2373 for(
size_t j=0UL; j<N; ++j )
2374 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2375 v_[element->index()*NN+j] += element->value();
2391 template<
typename Type
2395 template<
typename MT
2402 for(
size_t i=0UL; i<M; ++i ) {
2403 for(
size_t j=0UL; j<N; ++j ) {
2404 v_[i*NN+j] -= (~rhs)(i,j);
2422 template<
typename Type
2426 template<
typename MT
2435 for(
size_t i=0UL; i<M; ++i ) {
2436 for(
size_t j=0UL; j<N; j+=IT::size ) {
2437 store( &v_[i*NN+j],
load( &v_[i*NN+j] ) - (~rhs).
get(i,j) );
2455 template<
typename Type
2459 template<
typename MT >
2466 for(
size_t i=0UL; i<M; ++i )
2467 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2468 v_[i*NN+element->index()] -= element->value();
2484 template<
typename Type
2488 template<
typename MT >
2495 for(
size_t j=0UL; j<N; ++j )
2496 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2497 v_[element->index()*NN+j] -= element->value();
2522 template<
typename Type
2535 enum { MM = M + ( IT::size - ( M % IT::size ) ) % IT::size };
2540 typedef StaticMatrix<Type,M,N,true>
This;
2560 enum { vectorizable = IsVectorizable<Type>::value };
2570 template<
typename Other,
bool SO >
inline StaticMatrix(
const StaticMatrix<Other,M,N,SO>& m );
2571 template<
typename MT ,
bool SO >
inline StaticMatrix(
const Matrix<MT,SO>& m );
2574 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3 );
2575 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4 );
2576 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5 );
2577 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2579 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2580 const Type& v6,
const Type& v7 );
2581 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2582 const Type& v6,
const Type& v7,
const Type& v8 );
2583 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2584 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9 );
2585 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2586 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9,
const Type& v10 );
2599 inline Type*
data ();
2600 inline const Type*
data ()
const;
2601 inline Type*
data (
size_t j );
2602 inline const Type*
data (
size_t j )
const;
2617 template<
typename Other,
bool SO >
inline StaticMatrix&
operator= (
const StaticMatrix<Other,M,N,SO>& rhs );
2619 template<
typename MT ,
bool SO >
inline StaticMatrix& operator+=(
const Matrix<MT,SO>& rhs );
2620 template<
typename MT ,
bool SO >
inline StaticMatrix& operator-=(
const Matrix<MT,SO>& rhs );
2621 template<
typename MT ,
bool SO >
inline StaticMatrix& operator*=(
const Matrix<MT,SO>& rhs );
2623 template<
typename Other >
2624 inline typename EnableIf< IsNumeric<Other>,
StaticMatrix >::Type&
2625 operator*=( Other rhs );
2627 template<
typename Other >
2628 inline typename EnableIf< IsNumeric<Other>,
StaticMatrix >::Type&
2629 operator/=( Other rhs );
2636 inline size_t rows()
const;
2637 inline size_t columns()
const;
2638 inline size_t spacing()
const;
2640 inline size_t capacity(
size_t j )
const;
2642 inline size_t nonZeros(
size_t j )
const;
2643 inline void reset();
2644 inline void reset(
size_t i );
2648 template<
typename Other >
inline StaticMatrix& scale(
const Other& scalar );
2656 template<
typename MT >
2657 struct VectorizedAssign {
2658 enum { value = vectorizable && MT::vectorizable &&
2659 IsSame<Type,typename MT::ElementType>::value &&
2660 IsColumnMajorMatrix<MT>::value };
2666 template<
typename MT >
2667 struct VectorizedAddAssign {
2668 enum { value = vectorizable && MT::vectorizable &&
2669 IsSame<Type,typename MT::ElementType>::value &&
2670 IntrinsicTrait<Type>::addition &&
2671 IsColumnMajorMatrix<MT>::value };
2677 template<
typename MT >
2678 struct VectorizedSubAssign {
2679 enum { value = vectorizable && MT::vectorizable &&
2680 IsSame<Type,typename MT::ElementType>::value &&
2681 IntrinsicTrait<Type>::subtraction &&
2682 IsColumnMajorMatrix<MT>::value };
2690 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2691 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2694 template<
typename MT,
bool SO >
2695 inline typename DisableIf< VectorizedAssign<MT> >::Type
2696 assign(
const DenseMatrix<MT,SO>& rhs );
2698 template<
typename MT,
bool SO >
2699 inline typename EnableIf< VectorizedAssign<MT> >::Type
2700 assign(
const DenseMatrix<MT,SO>& rhs );
2702 template<
typename MT >
inline void assign(
const SparseMatrix<MT,true>& rhs );
2703 template<
typename MT >
inline void assign(
const SparseMatrix<MT,false>& rhs );
2705 template<
typename MT,
bool SO >
2706 inline typename DisableIf< VectorizedAddAssign<MT> >::Type
2707 addAssign(
const DenseMatrix<MT,SO>& rhs );
2709 template<
typename MT,
bool SO >
2710 inline typename EnableIf< VectorizedAddAssign<MT> >::Type
2711 addAssign(
const DenseMatrix<MT,SO>& rhs );
2713 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,true>& rhs );
2714 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,false>& rhs );
2716 template<
typename MT,
bool SO >
2717 inline typename DisableIf< VectorizedSubAssign<MT> >::Type
2718 subAssign(
const DenseMatrix<MT,SO>& rhs );
2720 template<
typename MT,
bool SO >
2721 inline typename EnableIf< VectorizedSubAssign<MT> >::Type
2722 subAssign(
const DenseMatrix<MT,SO>& rhs );
2724 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,true>& rhs );
2725 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,false>& rhs );
2765 template<
typename Type
2770 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2772 if( IsNumeric<Type>::value ) {
2773 for(
size_t i=0UL; i<MM*N; ++i )
2787 template<
typename Type
2792 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2794 for(
size_t j=0UL; j<N; ++j ) {
2795 for(
size_t i=0UL; i<M; ++i )
2798 if( IsNumeric<Type>::value ) {
2799 for(
size_t i=M; i<MM; ++i )
2800 v_[i+j*MM] = Type();
2816 template<
typename Type
2821 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2823 for(
size_t i=0UL; i<MM*N; ++i )
2836 template<
typename Type
2839 template<
typename Other
2843 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2845 for(
size_t j=0UL; j<N; ++j ) {
2846 for(
size_t i=0UL; i<M; ++i )
2847 v_[i+j*MM] = m(i,j);
2849 if( IsNumeric<Type>::value ) {
2850 for(
size_t i=M; i<MM; ++i )
2851 v_[i+j*MM] = Type();
2870 template<
typename Type
2873 template<
typename MT
2879 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2882 throw std::invalid_argument(
"Invalid setup of static matrix" );
2884 if( IsNumeric<Type>::value ) {
2885 for(
size_t j=0UL; j<N; ++j )
2886 for(
size_t i=( IsSparseMatrix<MT>::value )?( 0UL ):( M ); i<MM; ++i ) {
2887 v_[i+j*MM] = Type();
2915 template<
typename Type
2921 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2935 if( IsNumeric<Type>::value ) {
2936 for(
size_t j=0UL; j<N; ++j )
2937 for(
size_t i=M; i<MM; ++i ) {
2938 v_[i+j*MM] = Type();
2965 template<
typename Type
2971 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2987 if( IsNumeric<Type>::value ) {
2988 for(
size_t j=0UL; j<N; ++j )
2989 for(
size_t i=M; i<MM; ++i ) {
2990 v_[i+j*MM] = Type();
3020 template<
typename Type
3027 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3038 else if( N == 2UL ) {
3053 if( IsNumeric<Type>::value ) {
3054 for(
size_t j=0UL; j<N; ++j )
3055 for(
size_t i=M; i<MM; ++i ) {
3056 v_[i+j*MM] = Type();
3085 template<
typename Type
3089 const Type& v4,
const Type& v5 )
3092 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3112 if( IsNumeric<Type>::value ) {
3113 for(
size_t j=0UL; j<N; ++j )
3114 for(
size_t i=M; i<MM; ++i ) {
3115 v_[i+j*MM] = Type();
3148 template<
typename Type
3152 const Type& v4,
const Type& v5,
const Type& v6 )
3155 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3168 else if( N == 2UL ) {
3178 else if( N == 3UL ) {
3184 v_[2UL*MM+1UL] = v6;
3197 if( IsNumeric<Type>::value ) {
3198 for(
size_t j=0UL; j<N; ++j )
3199 for(
size_t i=M; i<MM; ++i ) {
3200 v_[i+j*MM] = Type();
3231 template<
typename Type
3235 const Type& v4,
const Type& v5,
const Type& v6,
3239 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3263 if( IsNumeric<Type>::value ) {
3264 for(
size_t j=0UL; j<N; ++j )
3265 for(
size_t i=M; i<MM; ++i ) {
3266 v_[i+j*MM] = Type();
3301 template<
typename Type
3305 const Type& v4,
const Type& v5,
const Type& v6,
3306 const Type& v7,
const Type& v8 )
3309 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3324 else if( N == 2UL ) {
3336 else if( N == 4UL ) {
3342 v_[2UL*MM+1UL] = v6;
3344 v_[3UL*MM+1UL] = v8;
3359 if( IsNumeric<Type>::value ) {
3360 for(
size_t j=0UL; j<N; ++j )
3361 for(
size_t i=M; i<MM; ++i ) {
3362 v_[i+j*MM] = Type();
3398 template<
typename Type
3402 const Type& v4,
const Type& v5,
const Type& v6,
3403 const Type& v7,
const Type& v8,
const Type& v9 )
3406 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3422 else if( N == 3UL ) {
3430 v_[2UL*MM+1UL] = v8;
3431 v_[2UL*MM+2UL] = v9;
3447 if( IsNumeric<Type>::value ) {
3448 for(
size_t j=0UL; j<N; ++j )
3449 for(
size_t i=M; i<MM; ++i ) {
3450 v_[i+j*MM] = Type();
3487 template<
typename Type
3491 const Type& v4,
const Type& v5,
const Type& v6,
3492 const Type& v7,
const Type& v8,
const Type& v9,
3496 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3513 else if( N == 2UL ) {
3527 else if( N == 5UL ) {
3533 v_[2UL*MM+1UL] = v6;
3535 v_[3UL*MM+1UL] = v8;
3537 v_[4UL*MM+1UL] = v10;
3554 if( IsNumeric<Type>::value ) {
3555 for(
size_t j=0UL; j<N; ++j )
3556 for(
size_t i=M; i<MM; ++i ) {
3557 v_[i+j*MM] = Type();
3581 template<
typename Type
3584 inline typename StaticMatrix<Type,M,N,true>::Reference
3603 template<
typename Type
3606 inline typename StaticMatrix<Type,M,N,true>::ConstReference
3623 template<
typename Type
3640 template<
typename Type
3658 template<
typename Type
3677 template<
typename Type
3696 template<
typename Type
3699 inline typename StaticMatrix<Type,M,N,true>::Iterator
3716 template<
typename Type
3719 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3736 template<
typename Type
3739 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3756 template<
typename Type
3759 inline typename StaticMatrix<Type,M,N,true>::Iterator
3763 return v_ + j*MM + M;
3776 template<
typename Type
3779 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3783 return v_ + j*MM + M;
3796 template<
typename Type
3799 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3803 return v_ + j*MM + M;
3824 template<
typename Type
3827 inline StaticMatrix<Type,M,N,true>&
3830 for(
size_t j=0UL; j<N; ++j )
3831 for(
size_t i=0UL; i<M; ++i )
3849 template<
typename Type
3852 inline StaticMatrix<Type,M,N,true>&
3855 for(
size_t j=0UL; j<N; ++j )
3856 for(
size_t i=0UL; i<M; ++i )
3857 v_[i+j*MM] = rhs(i,j);
3872 template<
typename Type
3875 template<
typename Other
3877 inline StaticMatrix<Type,M,N,true>&
3880 for(
size_t j=0UL; j<N; ++j )
3881 for(
size_t i=0UL; i<M; ++i )
3882 v_[i+j*MM] = rhs(i,j);
3902 template<
typename Type
3905 template<
typename MT
3912 throw std::invalid_argument(
"Invalid assignment to static matrix" );
3914 if( (~rhs).canAlias(
this ) ) {
3915 StaticMatrix tmp( ~rhs );
3919 if( IsSparseMatrix<MT>::value )
3941 template<
typename Type
3944 template<
typename MT
3946 inline StaticMatrix<Type,M,N,true>& StaticMatrix<Type,M,N,true>::operator+=(
const Matrix<MT,SO>& rhs )
3951 throw std::invalid_argument(
"Matrix sizes do not match" );
3953 if( (~rhs).canAlias(
this ) ) {
3954 StaticMatrix tmp( ~rhs );
3978 template<
typename Type
3981 template<
typename MT
3983 inline StaticMatrix<Type,M,N,true>& StaticMatrix<Type,M,N,true>::operator-=(
const Matrix<MT,SO>& rhs )
3988 throw std::invalid_argument(
"Matrix sizes do not match" );
3990 if( (~rhs).canAlias(
this ) ) {
3991 StaticMatrix tmp( ~rhs );
4015 template<
typename Type
4018 template<
typename MT
4020 inline StaticMatrix<Type,M,N,true>& StaticMatrix<Type,M,N,true>::operator*=(
const Matrix<MT,SO>& rhs )
4022 if( M != N || (~rhs).
rows() != M || (~rhs).
columns() != M )
4023 throw std::invalid_argument(
"Matrix sizes do not match" );
4025 StaticMatrix tmp( *
this * (~rhs) );
4026 return this->operator=( tmp );
4040 template<
typename Type
4043 template<
typename Other >
4044 inline typename EnableIf< IsNumeric<Other>, StaticMatrix<Type,M,N,true> >::Type&
4045 StaticMatrix<Type,M,N,true>::operator*=( Other rhs )
4047 return operator=( (*
this) * rhs );
4063 template<
typename Type
4066 template<
typename Other >
4067 inline typename EnableIf< IsNumeric<Other>, StaticMatrix<Type,M,N,true> >::Type&
4068 StaticMatrix<Type,M,N,true>::operator/=( Other rhs )
4072 return operator=( (*
this) / rhs );
4092 template<
typename Type
4109 template<
typename Type
4129 template<
typename Type
4146 template<
typename Type
4164 template<
typename Type
4182 template<
typename Type
4187 size_t nonzeros( 0UL );
4189 for(
size_t j=0UL; j<N; ++j )
4190 for(
size_t i=0UL; i<M; ++i )
4207 template<
typename Type
4214 const size_t iend( (j+1UL)*MM );
4215 size_t nonzeros( 0UL );
4217 for(
size_t i=j*MM; i<iend; ++i )
4233 template<
typename Type
4240 for(
size_t j=0UL; j<N; ++j )
4241 for(
size_t i=0UL; i<M; ++i )
4242 reset( v_[i+j*MM] );
4258 template<
typename Type
4266 for(
size_t i=0UL; i<M; ++i )
4267 reset( v_[i+j*MM] );
4279 template<
typename Type
4286 for(
size_t j=1UL; j<N; ++j )
4287 for(
size_t i=0UL; i<j; ++i )
4288 swap( v_[i+j*MM], v_[j+i*MM] );
4314 template<
typename Type
4319 if( M != N )
return false;
4321 for(
size_t j=1UL; j<N; ++j ) {
4322 for(
size_t i=0UL; i<j; ++i ) {
4340 template<
typename Type
4345 if( M != N )
return false;
4347 for(
size_t j=1; j<N; ++j ) {
4348 for(
size_t i=0; i<j; ++i ) {
4349 if( !
equal( v_[i+j*MM], v_[j+i*MM] ) )
4367 template<
typename Type
4370 template<
typename Other >
4371 inline StaticMatrix<Type,M,N,true>&
4372 StaticMatrix<Type,M,N,true>::scale(
const Other& scalar )
4374 for(
size_t j=0UL; j<N; ++j )
4375 for(
size_t i=0UL; i<M; ++i )
4376 v_[i+j*MM] *= scalar;
4392 template<
typename Type
4399 for(
size_t j=0UL; j<N; ++j ) {
4400 for(
size_t i=0UL; i<M; ++i ) {
4401 swap( v_[i+j*MM], m(i,j) );
4428 template<
typename Type
4431 template<
typename Other >
4434 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4451 template<
typename Type
4454 template<
typename Other >
4457 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4476 template<
typename Type
4479 inline typename StaticMatrix<Type,M,N,true>::IntrinsicType
4489 return load( &v_[i+j*MM] );
4507 template<
typename Type
4510 template<
typename MT
4512 inline typename DisableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4517 for(
size_t j=0UL; j<N; ++j ) {
4518 for(
size_t i=0UL; i<M; ++i ) {
4519 v_[i+j*MM] = (~rhs)(i,j);
4539 template<
typename Type
4542 template<
typename MT
4544 inline typename EnableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4551 for(
size_t j=0UL; j<N; ++j ) {
4552 for(
size_t i=0UL; i<M; i+=IT::size ) {
4553 store( &v_[i+j*MM], (~rhs).
get(i,j) );
4573 template<
typename Type
4576 template<
typename MT >
4581 typedef typename MT::ConstIterator ConstIterator;
4583 for(
size_t j=0UL; j<N; ++j )
4584 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4585 v_[element->index()+j*MM] = element->value();
4603 template<
typename Type
4606 template<
typename MT >
4611 typedef typename MT::ConstIterator ConstIterator;
4613 for(
size_t i=0UL; i<M; ++i )
4614 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4615 v_[i+element->index()*MM] = element->value();
4633 template<
typename Type
4636 template<
typename MT
4638 inline typename DisableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4643 for(
size_t j=0UL; j<N; ++j ) {
4644 for(
size_t i=0UL; i<M; ++i ) {
4645 v_[i+j*MM] += (~rhs)(i,j);
4665 template<
typename Type
4668 template<
typename MT
4670 inline typename EnableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4677 for(
size_t j=0UL; j<N; ++j ) {
4678 for(
size_t i=0UL; i<M; i+=IT::size ) {
4679 store( &v_[i+j*MM],
load( &v_[i+j*MM] ) + (~rhs).
get(i,j) );
4699 template<
typename Type
4702 template<
typename MT >
4707 typedef typename MT::ConstIterator ConstIterator;
4709 for(
size_t j=0UL; j<N; ++j )
4710 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4711 v_[element->index()+j*MM] += element->value();
4729 template<
typename Type
4732 template<
typename MT >
4737 typedef typename MT::ConstIterator ConstIterator;
4739 for(
size_t i=0UL; i<M; ++i )
4740 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4741 v_[i+element->index()*MM] += element->value();
4759 template<
typename Type
4762 template<
typename MT
4764 inline typename DisableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4769 for(
size_t j=0UL; j<N; ++j ) {
4770 for(
size_t i=0UL; i<M; ++i ) {
4771 v_[i+j*MM] -= (~rhs)(i,j);
4791 template<
typename Type
4794 template<
typename MT
4796 inline typename EnableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4803 for(
size_t j=0UL; j<N; ++j ) {
4804 for(
size_t i=0UL; i<M; i+=IT::size ) {
4805 store( &v_[i+j*MM],
load( &v_[i+j*MM] ) - (~rhs).
get(i,j) );
4825 template<
typename Type
4828 template<
typename MT >
4833 typedef typename MT::ConstIterator ConstIterator;
4835 for(
size_t j=0UL; j<N; ++j )
4836 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4837 v_[element->index()+j*MM] -= element->value();
4855 template<
typename Type
4858 template<
typename MT >
4863 typedef typename MT::ConstIterator ConstIterator;
4865 for(
size_t i=0UL; i<M; ++i )
4866 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4867 v_[i+element->index()*MM] -= element->value();
4893 template<
typename Type
4896 class StaticMatrix<Type,M,0UL,SO>;
4909 template<
typename Type
4912 class StaticMatrix<Type,0UL,N,SO>;
4925 template<
typename Type
4927 class StaticMatrix<Type,0UL,0UL,SO>;
4947 template<
typename Type,
size_t M,
size_t N,
bool SO >
4948 inline bool isnan(
const StaticMatrix<Type,M,N,SO>& m );
4950 template<
typename Type,
size_t M,
size_t N,
bool SO >
4951 inline void reset( StaticMatrix<Type,M,N,SO>& m );
4953 template<
typename Type,
size_t M,
size_t N,
bool SO >
4954 inline void clear( StaticMatrix<Type,M,N,SO>& m );
4956 template<
typename Type,
size_t M,
size_t N,
bool SO >
4957 inline bool isDefault(
const StaticMatrix<Type,M,N,SO>& m );
4959 template<
typename Type,
size_t M,
size_t N,
bool SO >
4960 inline void swap( StaticMatrix<Type,M,N,SO>& a, StaticMatrix<Type,M,N,SO>& b ) ;
4972 template<
typename Type
4978 for(
size_t i=0UL; i<M*N; ++i ) {
4995 template<
typename Type
5015 template<
typename Type
5033 template<
typename Type
5040 for(
size_t i=0UL; i<M; ++i )
5041 for(
size_t j=0UL; j<N; ++j )
5042 if( !
isDefault( m(i,j) ) )
return false;
5045 for(
size_t j=0UL; j<N; ++j )
5046 for(
size_t i=0UL; i<M; ++i )
5047 if( !
isDefault( m(i,j) ) )
return false;
5064 template<
typename Type
5085 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5086 struct AddTrait< StaticMatrix<T1,M,N,SO>, StaticMatrix<T2,M,N,SO> >
5088 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
5091 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
5092 struct AddTrait< StaticMatrix<T1,M,N,SO1>, StaticMatrix<T2,M,N,SO2> >
5094 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
5110 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5111 struct SubTrait< StaticMatrix<T1,M,N,SO>, StaticMatrix<T2,M,N,SO> >
5113 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
5116 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
5117 struct SubTrait< StaticMatrix<T1,M,N,SO1>, StaticMatrix<T2,M,N,SO2> >
5119 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
5135 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5136 struct MultTrait< StaticMatrix<T1,M,N,SO>, T2 >
5138 typedef StaticMatrix< typename MultTrait<T1,T2>::Type, M, N, SO > Type;
5142 template<
typename T1,
typename T2,
size_t M,
size_t N,
bool SO >
5143 struct MultTrait< T1, StaticMatrix<T2,M,N,SO> >
5145 typedef StaticMatrix< typename MultTrait<T1,T2>::Type, M, N, SO > Type;
5149 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5150 struct MultTrait< StaticMatrix<T1,M,N,SO>, StaticVector<T2,N,false> >
5152 typedef StaticVector< typename MultTrait<T1,T2>::Type, M,
false > Type;
5155 template<
typename T1,
size_t M,
typename T2,
size_t N,
bool SO >
5156 struct MultTrait< StaticVector<T1,M,true>, StaticMatrix<T2,M,N,SO> >
5158 typedef StaticVector< typename MultTrait<T1,T2>::Type, N,
true > Type;
5161 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5162 struct MultTrait< StaticMatrix<T1,M,N,SO>, DynamicVector<T2,false> >
5164 typedef StaticVector< typename MultTrait<T1,T2>::Type, M,
false > Type;
5167 template<
typename T1,
typename T2,
size_t M,
size_t N,
bool SO >
5168 struct MultTrait< DynamicVector<T1,true>, StaticMatrix<T2,M,N,SO> >
5170 typedef StaticVector< typename MultTrait<T1,T2>::Type, N,
true > Type;
5173 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5174 struct MultTrait< StaticMatrix<T1,M,N,SO>, CompressedVector<T2,false> >
5176 typedef StaticVector< typename MultTrait<T1,T2>::Type, M,
false > Type;
5179 template<
typename T1,
typename T2,
size_t M,
size_t N,
bool SO >
5180 struct MultTrait< CompressedVector<T1,true>, StaticMatrix<T2,M,N,SO> >
5182 typedef StaticVector< typename MultTrait<T1,T2>::Type, N,
true > Type;
5185 template<
typename T1,
size_t M,
size_t K,
bool SO1,
typename T2,
size_t N,
bool SO2 >
5186 struct MultTrait< StaticMatrix<T1,M,K,SO1>, StaticMatrix<T2,K,N,SO2> >
5188 typedef StaticMatrix< typename MultTrait<T1,T2>::Type, M, N, SO1 > Type;
5204 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5205 struct DivTrait< StaticMatrix<T1,M,N,SO>, T2 >
5207 typedef StaticMatrix< typename DivTrait<T1,T2>::Type, M, N, SO > Type;
5224 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5225 struct MathTrait< StaticMatrix<T1,M,N,SO>, StaticMatrix<T2,M,N,SO> >
5227 typedef StaticMatrix< typename MathTrait<T1,T2>::HighType, M, N, SO > HighType;
5228 typedef StaticMatrix< typename MathTrait<T1,T2>::LowType , M, N, SO > LowType;
5244 template<
typename T1,
size_t M,
size_t N,
bool SO >
5245 struct RowTrait< StaticMatrix<T1,M,N,SO> >
5247 typedef StaticVector<T1,N,true> Type;
5263 template<
typename T1,
size_t M,
size_t N,
bool SO >
5264 struct ColumnTrait< StaticMatrix<T1,M,N,SO> >
5266 typedef StaticVector<T1,M,false> Type;