22 #ifndef _BLAZE_MATH_DENSE_STATICMATRIX_H_
23 #define _BLAZE_MATH_DENSE_STATICMATRIX_H_
163 template<
typename Type
167 class StaticMatrix :
public DenseMatrix< StaticMatrix<Type,M,N,SO>, SO >
168 ,
private AlignedStorage<Type>
177 enum { NN = N + ( IT::size - ( N % IT::size ) ) % IT::size };
216 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3 );
217 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4 );
218 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5 );
219 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
221 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
222 const Type& v6,
const Type& v7 );
223 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
224 const Type& v6,
const Type& v7,
const Type& v8 );
225 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
226 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9 );
227 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
228 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9,
const Type& v10 );
241 inline Type*
data ();
242 inline const Type*
data ()
const;
243 inline Type*
data (
size_t i );
244 inline const Type*
data (
size_t i )
const;
265 template<
typename Other >
267 operator*=( Other rhs );
269 template<
typename Other >
271 operator/=( Other rhs );
278 inline size_t rows()
const;
282 inline size_t capacity(
size_t i )
const;
284 inline size_t nonZeros(
size_t i )
const;
286 inline void reset(
size_t i );
290 template<
typename Other >
inline StaticMatrix& scale(
const Other& scalar );
299 template<
typename MT >
300 struct VectorizedAssign {
301 enum { value = vectorizable && MT::vectorizable &&
311 template<
typename MT >
312 struct VectorizedAddAssign {
313 enum { value = vectorizable && MT::vectorizable &&
314 IsSame<Type,typename MT::ElementType>::value &&
315 IntrinsicTrait<Type>::addition &&
316 IsRowMajorMatrix<MT>::value };
324 template<
typename MT >
325 struct VectorizedSubAssign {
326 enum { value = vectorizable && MT::vectorizable &&
327 IsSame<Type,typename MT::ElementType>::value &&
328 IntrinsicTrait<Type>::subtraction &&
329 IsRowMajorMatrix<MT>::value };
338 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
339 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
342 template<
typename MT,
bool SO2 >
343 inline typename DisableIf< VectorizedAssign<MT> >::Type
344 assign(
const DenseMatrix<MT,SO2>& rhs );
346 template<
typename MT,
bool SO2 >
347 inline typename EnableIf< VectorizedAssign<MT> >::Type
348 assign(
const DenseMatrix<MT,SO2>& rhs );
350 template<
typename MT >
inline void assign(
const SparseMatrix<MT,SO>& rhs );
351 template<
typename MT >
inline void assign(
const SparseMatrix<MT,!SO>& rhs );
353 template<
typename MT,
bool SO2 >
354 inline typename DisableIf< VectorizedAddAssign<MT> >::Type
355 addAssign(
const DenseMatrix<MT,SO2>& rhs );
357 template<
typename MT,
bool SO2 >
358 inline typename EnableIf< VectorizedAddAssign<MT> >::Type
359 addAssign(
const DenseMatrix<MT,SO2>& rhs );
361 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,SO>& rhs );
362 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,!SO>& rhs );
364 template<
typename MT,
bool SO2 >
365 inline typename DisableIf< VectorizedSubAssign<MT> >::Type
366 subAssign(
const DenseMatrix<MT,SO2>& rhs );
368 template<
typename MT,
bool SO2 >
369 inline typename EnableIf< VectorizedSubAssign<MT> >::Type
370 subAssign(
const DenseMatrix<MT,SO2>& rhs );
372 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,SO>& rhs );
373 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,!SO>& rhs );
420 template<
typename Type
426 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
429 for(
size_t i=0UL; i<M*NN; ++i )
441 template<
typename Type
447 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
449 for(
size_t i=0UL; i<M; ++i ) {
450 for(
size_t j=0UL; j<N; ++j )
454 for(
size_t j=N; j<NN; ++j )
469 template<
typename Type
475 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
477 for(
size_t i=0UL; i<M*NN; ++i )
488 template<
typename Type
492 template<
typename Other
496 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
498 for(
size_t i=0UL; i<M; ++i ) {
499 for(
size_t j=0UL; j<N; ++j )
503 for(
size_t j=N; j<NN; ++j )
521 template<
typename Type
525 template<
typename MT
531 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
534 throw std::invalid_argument(
"Invalid setup of static matrix" );
537 for(
size_t i=0UL; i<M; ++i ) {
565 template<
typename Type
572 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
587 for(
size_t i=0UL; i<M; ++i ) {
588 for(
size_t j=N; j<NN; ++j )
614 template<
typename Type
621 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
638 for(
size_t i=0UL; i<M; ++i ) {
639 for(
size_t j=N; j<NN; ++j )
668 template<
typename Type
673 const Type& v3,
const Type& v4 )
676 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
687 else if( M == 2UL ) {
703 for(
size_t i=0UL; i<M; ++i ) {
704 for(
size_t j=N; j<NN; ++j )
732 template<
typename Type
737 const Type& v4,
const Type& v5 )
740 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
761 for(
size_t i=0UL; i<M; ++i ) {
762 for(
size_t j=N; j<NN; ++j )
794 template<
typename Type
799 const Type& v4,
const Type& v5,
const Type& v6 )
802 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
815 else if( M == 2UL ) {
825 else if( M == 3UL ) {
845 for(
size_t i=0UL; i<M; ++i ) {
846 for(
size_t j=N; j<NN; ++j )
876 template<
typename Type
881 const Type& v4,
const Type& v5,
const Type& v6,
885 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
910 for(
size_t i=0UL; i<M; ++i ) {
911 for(
size_t j=N; j<NN; ++j )
944 template<
typename Type
949 const Type& v4,
const Type& v5,
const Type& v6,
950 const Type& v7,
const Type& v8 )
953 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
968 else if( M == 2UL ) {
980 else if( M == 4UL ) {
1004 for(
size_t i=0UL; i<M; ++i ) {
1005 for(
size_t j=N; j<NN; ++j )
1006 v_[i*NN+j] = Type();
1040 template<
typename Type
1045 const Type& v4,
const Type& v5,
const Type& v6,
1046 const Type& v7,
const Type& v8,
const Type& v9 )
1049 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
1065 else if( M == 3UL ) {
1073 v_[2UL*NN+1UL] = v8;
1074 v_[2UL*NN+2UL] = v9;
1091 for(
size_t i=0UL; i<M; ++i ) {
1092 for(
size_t j=N; j<NN; ++j )
1093 v_[i*NN+j] = Type();
1128 template<
typename Type
1133 const Type& v4,
const Type& v5,
const Type& v6,
1134 const Type& v7,
const Type& v8,
const Type& v9,
1138 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
1155 else if( M == 2UL ) {
1169 else if( M == 5UL ) {
1175 v_[2UL*NN+1UL] = v6;
1177 v_[3UL*NN+1UL] = v8;
1179 v_[4UL*NN+1UL] = v10;
1197 for(
size_t i=0UL; i<M; ++i ) {
1198 for(
size_t j=N; j<NN; ++j )
1199 v_[i*NN+j] = Type();
1221 template<
typename Type
1242 template<
typename Type
1261 template<
typename Type
1277 template<
typename Type
1294 template<
typename Type
1312 template<
typename Type
1335 template<
typename Type
1359 template<
typename Type
1383 template<
typename Type
1407 template<
typename Type
1415 return v_ + i*NN + N;
1431 template<
typename Type
1439 return v_ + i*NN + N;
1455 template<
typename Type
1463 return v_ + i*NN + N;
1482 template<
typename Type
1488 for(
size_t i=0UL; i<M; ++i )
1489 for(
size_t j=0UL; j<N; ++j )
1505 template<
typename Type
1511 for(
size_t i=0UL; i<M; ++i )
1512 for(
size_t j=0UL; j<N; ++j )
1513 v_[i*NN+j] = rhs(i,j);
1526 template<
typename Type
1530 template<
typename Other
1535 for(
size_t i=0UL; i<M; ++i )
1536 for(
size_t j=0UL; j<N; ++j )
1537 v_[i*NN+j] = rhs(i,j);
1555 template<
typename Type
1559 template<
typename MT
1566 throw std::invalid_argument(
"Invalid assignment to static matrix" );
1568 if( (~rhs).canAlias(
this ) ) {
1593 template<
typename Type
1597 template<
typename MT
1604 throw std::invalid_argument(
"Matrix sizes do not match" );
1606 if( (~rhs).canAlias(
this ) ) {
1629 template<
typename Type
1633 template<
typename MT
1640 throw std::invalid_argument(
"Matrix sizes do not match" );
1642 if( (~rhs).canAlias(
this ) ) {
1665 template<
typename Type
1669 template<
typename MT
1673 if( M != N || (~rhs).
rows() != M || (~rhs).
columns() != M )
1674 throw std::invalid_argument(
"Matrix sizes do not match" );
1677 return this->operator=( tmp );
1689 template<
typename Type
1693 template<
typename Other >
1697 return operator=( (*
this) * rhs );
1711 template<
typename Type
1715 template<
typename Other >
1721 return operator=( (*
this) / rhs );
1739 template<
typename Type
1755 template<
typename Type
1774 template<
typename Type
1790 template<
typename Type
1812 template<
typename Type
1829 template<
typename Type
1835 size_t nonzeros( 0UL );
1837 for(
size_t i=0UL; i<M; ++i )
1838 for(
size_t j=0UL; j<N; ++j )
1858 template<
typename Type
1866 const size_t jend( (i+1UL)*NN );
1867 size_t nonzeros( 0UL );
1869 for(
size_t j=i*NN; j<jend; ++j )
1883 template<
typename Type
1891 for(
size_t i=0UL; i<M; ++i )
1892 for(
size_t j=0UL; j<N; ++j )
1893 reset( v_[i*NN+j] );
1909 template<
typename Type
1918 for(
size_t j=0UL; j<N; ++j )
1919 reset( v_[i*NN+j] );
1929 template<
typename Type
1937 for(
size_t i=1UL; i<M; ++i )
1938 for(
size_t j=0UL; j<i; ++j )
1939 swap( v_[i*NN+j], v_[j*NN+i] );
1963 template<
typename Type
1969 if( M != N )
return false;
1971 for(
size_t i=1UL; i<M; ++i ) {
1972 for(
size_t j=0UL; j<i; ++j ) {
1988 template<
typename Type
1994 if( M != N )
return false;
1996 for(
size_t i=1UL; i<M; ++i ) {
1997 for(
size_t j=0UL; j<i; ++j ) {
1998 if( !
equal( v_[i*NN+j], v_[j*NN+i] ) )
2014 template<
typename Type
2018 template<
typename Other >
2021 for(
size_t i=0UL; i<M; ++i )
2022 for(
size_t j=0UL; j<N; ++j )
2023 v_[i*NN+j] *= scalar;
2037 template<
typename Type
2045 for(
size_t i=0UL; i<M; ++i ) {
2046 for(
size_t j=0UL; j<N; ++j ) {
2047 swap( v_[i*NN+j], m(i,j) );
2072 template<
typename Type
2076 template<
typename Other >
2079 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2094 template<
typename Type
2098 template<
typename Other >
2101 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2118 template<
typename Type
2132 return load( &v_[i*NN+j] );
2148 template<
typename Type
2152 template<
typename MT
2159 for(
size_t i=0UL; i<M; ++i ) {
2160 for(
size_t j=0UL; j<N; ++j ) {
2161 v_[i*NN+j] = (~rhs)(i,j);
2179 template<
typename Type
2183 template<
typename MT
2192 for(
size_t i=0UL; i<M; ++i ) {
2193 for(
size_t j=0UL; j<N; j+=IT::size ) {
2194 store( &v_[i*NN+j], (~rhs).
get(i,j) );
2212 template<
typename Type
2216 template<
typename MT >
2223 for(
size_t i=0UL; i<M; ++i )
2224 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2225 v_[i*NN+element->index()] = element->value();
2241 template<
typename Type
2245 template<
typename MT >
2252 for(
size_t j=0UL; j<N; ++j )
2253 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2254 v_[element->index()*NN+j] = element->value();
2270 template<
typename Type
2274 template<
typename MT
2281 for(
size_t i=0UL; i<M; ++i ) {
2282 for(
size_t j=0UL; j<N; ++j ) {
2283 v_[i*NN+j] += (~rhs)(i,j);
2301 template<
typename Type
2305 template<
typename MT
2314 for(
size_t i=0UL; i<M; ++i ) {
2315 for(
size_t j=0UL; j<N; j+=IT::size ) {
2316 store( &v_[i*NN+j],
load( &v_[i*NN+j] ) + (~rhs).
get(i,j) );
2334 template<
typename Type
2338 template<
typename MT >
2345 for(
size_t i=0UL; i<M; ++i )
2346 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2347 v_[i*NN+element->index()] += element->value();
2363 template<
typename Type
2367 template<
typename MT >
2374 for(
size_t j=0UL; j<N; ++j )
2375 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2376 v_[element->index()*NN+j] += element->value();
2392 template<
typename Type
2396 template<
typename MT
2403 for(
size_t i=0UL; i<M; ++i ) {
2404 for(
size_t j=0UL; j<N; ++j ) {
2405 v_[i*NN+j] -= (~rhs)(i,j);
2423 template<
typename Type
2427 template<
typename MT
2436 for(
size_t i=0UL; i<M; ++i ) {
2437 for(
size_t j=0UL; j<N; j+=IT::size ) {
2438 store( &v_[i*NN+j],
load( &v_[i*NN+j] ) - (~rhs).
get(i,j) );
2456 template<
typename Type
2460 template<
typename MT >
2467 for(
size_t i=0UL; i<M; ++i )
2468 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2469 v_[i*NN+element->index()] -= element->value();
2485 template<
typename Type
2489 template<
typename MT >
2496 for(
size_t j=0UL; j<N; ++j )
2497 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2498 v_[element->index()*NN+j] -= element->value();
2523 template<
typename Type
2536 enum { MM = M + ( IT::size - ( M % IT::size ) ) % IT::size };
2541 typedef StaticMatrix<Type,M,N,true>
This;
2561 enum { vectorizable = IsVectorizable<Type>::value };
2571 template<
typename Other,
bool SO >
inline StaticMatrix(
const StaticMatrix<Other,M,N,SO>& m );
2572 template<
typename MT ,
bool SO >
inline StaticMatrix(
const Matrix<MT,SO>& m );
2575 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3 );
2576 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4 );
2577 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5 );
2578 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2580 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2581 const Type& v6,
const Type& v7 );
2582 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2583 const Type& v6,
const Type& v7,
const Type& v8 );
2584 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2585 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9 );
2586 inline StaticMatrix(
const Type& v1,
const Type& v2,
const Type& v3,
const Type& v4,
const Type& v5,
2587 const Type& v6,
const Type& v7,
const Type& v8,
const Type& v9,
const Type& v10 );
2600 inline Type*
data ();
2601 inline const Type*
data ()
const;
2602 inline Type*
data (
size_t j );
2603 inline const Type*
data (
size_t j )
const;
2618 template<
typename Other,
bool SO >
inline StaticMatrix&
operator= (
const StaticMatrix<Other,M,N,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 );
2622 template<
typename MT ,
bool SO >
inline StaticMatrix& operator*=(
const Matrix<MT,SO>& rhs );
2624 template<
typename Other >
2625 inline typename EnableIf< IsNumeric<Other>,
StaticMatrix >::Type&
2626 operator*=( Other rhs );
2628 template<
typename Other >
2629 inline typename EnableIf< IsNumeric<Other>,
StaticMatrix >::Type&
2630 operator/=( Other rhs );
2637 inline size_t rows()
const;
2638 inline size_t columns()
const;
2639 inline size_t spacing()
const;
2641 inline size_t capacity(
size_t j )
const;
2643 inline size_t nonZeros(
size_t j )
const;
2644 inline void reset();
2645 inline void reset(
size_t i );
2649 template<
typename Other >
inline StaticMatrix& scale(
const Other& scalar );
2657 template<
typename MT >
2658 struct VectorizedAssign {
2659 enum { value = vectorizable && MT::vectorizable &&
2660 IsSame<Type,typename MT::ElementType>::value &&
2661 IsColumnMajorMatrix<MT>::value };
2667 template<
typename MT >
2668 struct VectorizedAddAssign {
2669 enum { value = vectorizable && MT::vectorizable &&
2670 IsSame<Type,typename MT::ElementType>::value &&
2671 IntrinsicTrait<Type>::addition &&
2672 IsColumnMajorMatrix<MT>::value };
2678 template<
typename MT >
2679 struct VectorizedSubAssign {
2680 enum { value = vectorizable && MT::vectorizable &&
2681 IsSame<Type,typename MT::ElementType>::value &&
2682 IntrinsicTrait<Type>::subtraction &&
2683 IsColumnMajorMatrix<MT>::value };
2691 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2692 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2695 template<
typename MT,
bool SO >
2696 inline typename DisableIf< VectorizedAssign<MT> >::Type
2697 assign(
const DenseMatrix<MT,SO>& rhs );
2699 template<
typename MT,
bool SO >
2700 inline typename EnableIf< VectorizedAssign<MT> >::Type
2701 assign(
const DenseMatrix<MT,SO>& rhs );
2703 template<
typename MT >
inline void assign(
const SparseMatrix<MT,true>& rhs );
2704 template<
typename MT >
inline void assign(
const SparseMatrix<MT,false>& rhs );
2706 template<
typename MT,
bool SO >
2707 inline typename DisableIf< VectorizedAddAssign<MT> >::Type
2708 addAssign(
const DenseMatrix<MT,SO>& rhs );
2710 template<
typename MT,
bool SO >
2711 inline typename EnableIf< VectorizedAddAssign<MT> >::Type
2712 addAssign(
const DenseMatrix<MT,SO>& rhs );
2714 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,true>& rhs );
2715 template<
typename MT >
inline void addAssign(
const SparseMatrix<MT,false>& rhs );
2717 template<
typename MT,
bool SO >
2718 inline typename DisableIf< VectorizedSubAssign<MT> >::Type
2719 subAssign(
const DenseMatrix<MT,SO>& rhs );
2721 template<
typename MT,
bool SO >
2722 inline typename EnableIf< VectorizedSubAssign<MT> >::Type
2723 subAssign(
const DenseMatrix<MT,SO>& rhs );
2725 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,true>& rhs );
2726 template<
typename MT >
inline void subAssign(
const SparseMatrix<MT,false>& rhs );
2766 template<
typename Type
2771 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2773 if( IsBuiltin<Type>::value ) {
2774 for(
size_t i=0UL; i<MM*N; ++i )
2788 template<
typename Type
2793 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2795 for(
size_t j=0UL; j<N; ++j ) {
2796 for(
size_t i=0UL; i<M; ++i )
2799 if( IsBuiltin<Type>::value ) {
2800 for(
size_t i=M; i<MM; ++i )
2801 v_[i+j*MM] = Type();
2817 template<
typename Type
2822 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2824 for(
size_t i=0UL; i<MM*N; ++i )
2837 template<
typename Type
2840 template<
typename Other
2844 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2846 for(
size_t j=0UL; j<N; ++j ) {
2847 for(
size_t i=0UL; i<M; ++i )
2848 v_[i+j*MM] = m(i,j);
2850 if( IsBuiltin<Type>::value ) {
2851 for(
size_t i=M; i<MM; ++i )
2852 v_[i+j*MM] = Type();
2871 template<
typename Type
2874 template<
typename MT
2880 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2883 throw std::invalid_argument(
"Invalid setup of static matrix" );
2885 if( IsBuiltin<Type>::value ) {
2886 for(
size_t j=0UL; j<N; ++j )
2887 for(
size_t i=( IsSparseMatrix<MT>::value )?( 0UL ):( M ); i<MM; ++i ) {
2888 v_[i+j*MM] = Type();
2916 template<
typename Type
2922 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2936 if( IsBuiltin<Type>::value ) {
2937 for(
size_t j=0UL; j<N; ++j )
2938 for(
size_t i=M; i<MM; ++i ) {
2939 v_[i+j*MM] = Type();
2966 template<
typename Type
2972 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
2988 if( IsBuiltin<Type>::value ) {
2989 for(
size_t j=0UL; j<N; ++j )
2990 for(
size_t i=M; i<MM; ++i ) {
2991 v_[i+j*MM] = Type();
3021 template<
typename Type
3028 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3039 else if( N == 2UL ) {
3054 if( IsBuiltin<Type>::value ) {
3055 for(
size_t j=0UL; j<N; ++j )
3056 for(
size_t i=M; i<MM; ++i ) {
3057 v_[i+j*MM] = Type();
3086 template<
typename Type
3090 const Type& v4,
const Type& v5 )
3093 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3113 if( IsBuiltin<Type>::value ) {
3114 for(
size_t j=0UL; j<N; ++j )
3115 for(
size_t i=M; i<MM; ++i ) {
3116 v_[i+j*MM] = Type();
3149 template<
typename Type
3153 const Type& v4,
const Type& v5,
const Type& v6 )
3156 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3169 else if( N == 2UL ) {
3179 else if( N == 3UL ) {
3185 v_[2UL*MM+1UL] = v6;
3198 if( IsBuiltin<Type>::value ) {
3199 for(
size_t j=0UL; j<N; ++j )
3200 for(
size_t i=M; i<MM; ++i ) {
3201 v_[i+j*MM] = Type();
3232 template<
typename Type
3236 const Type& v4,
const Type& v5,
const Type& v6,
3240 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3264 if( IsBuiltin<Type>::value ) {
3265 for(
size_t j=0UL; j<N; ++j )
3266 for(
size_t i=M; i<MM; ++i ) {
3267 v_[i+j*MM] = Type();
3302 template<
typename Type
3306 const Type& v4,
const Type& v5,
const Type& v6,
3307 const Type& v7,
const Type& v8 )
3310 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3325 else if( N == 2UL ) {
3337 else if( N == 4UL ) {
3343 v_[2UL*MM+1UL] = v6;
3345 v_[3UL*MM+1UL] = v8;
3360 if( IsBuiltin<Type>::value ) {
3361 for(
size_t j=0UL; j<N; ++j )
3362 for(
size_t i=M; i<MM; ++i ) {
3363 v_[i+j*MM] = Type();
3399 template<
typename Type
3403 const Type& v4,
const Type& v5,
const Type& v6,
3404 const Type& v7,
const Type& v8,
const Type& v9 )
3407 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3423 else if( N == 3UL ) {
3431 v_[2UL*MM+1UL] = v8;
3432 v_[2UL*MM+2UL] = v9;
3448 if( IsBuiltin<Type>::value ) {
3449 for(
size_t j=0UL; j<N; ++j )
3450 for(
size_t i=M; i<MM; ++i ) {
3451 v_[i+j*MM] = Type();
3488 template<
typename Type
3492 const Type& v4,
const Type& v5,
const Type& v6,
3493 const Type& v7,
const Type& v8,
const Type& v9,
3497 BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( v_ ) % IT::alignment ),
"Invalid alignment detected" );
3514 else if( N == 2UL ) {
3528 else if( N == 5UL ) {
3534 v_[2UL*MM+1UL] = v6;
3536 v_[3UL*MM+1UL] = v8;
3538 v_[4UL*MM+1UL] = v10;
3555 if( IsBuiltin<Type>::value ) {
3556 for(
size_t j=0UL; j<N; ++j )
3557 for(
size_t i=M; i<MM; ++i ) {
3558 v_[i+j*MM] = Type();
3582 template<
typename Type
3585 inline typename StaticMatrix<Type,M,N,true>::Reference
3604 template<
typename Type
3607 inline typename StaticMatrix<Type,M,N,true>::ConstReference
3624 template<
typename Type
3641 template<
typename Type
3659 template<
typename Type
3678 template<
typename Type
3697 template<
typename Type
3700 inline typename StaticMatrix<Type,M,N,true>::Iterator
3717 template<
typename Type
3720 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3737 template<
typename Type
3740 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3757 template<
typename Type
3760 inline typename StaticMatrix<Type,M,N,true>::Iterator
3764 return v_ + j*MM + M;
3777 template<
typename Type
3780 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3784 return v_ + j*MM + M;
3797 template<
typename Type
3800 inline typename StaticMatrix<Type,M,N,true>::ConstIterator
3804 return v_ + j*MM + M;
3825 template<
typename Type
3828 inline StaticMatrix<Type,M,N,true>&
3831 for(
size_t j=0UL; j<N; ++j )
3832 for(
size_t i=0UL; i<M; ++i )
3850 template<
typename Type
3853 inline StaticMatrix<Type,M,N,true>&
3856 for(
size_t j=0UL; j<N; ++j )
3857 for(
size_t i=0UL; i<M; ++i )
3858 v_[i+j*MM] = rhs(i,j);
3873 template<
typename Type
3876 template<
typename Other
3878 inline StaticMatrix<Type,M,N,true>&
3881 for(
size_t j=0UL; j<N; ++j )
3882 for(
size_t i=0UL; i<M; ++i )
3883 v_[i+j*MM] = rhs(i,j);
3903 template<
typename Type
3906 template<
typename MT
3913 throw std::invalid_argument(
"Invalid assignment to static matrix" );
3915 if( (~rhs).canAlias(
this ) ) {
3916 StaticMatrix tmp( ~rhs );
3920 if( IsSparseMatrix<MT>::value )
3942 template<
typename Type
3945 template<
typename MT
3947 inline StaticMatrix<Type,M,N,true>& StaticMatrix<Type,M,N,true>::operator+=(
const Matrix<MT,SO>& rhs )
3952 throw std::invalid_argument(
"Matrix sizes do not match" );
3954 if( (~rhs).canAlias(
this ) ) {
3955 StaticMatrix tmp( ~rhs );
3979 template<
typename Type
3982 template<
typename MT
3984 inline StaticMatrix<Type,M,N,true>& StaticMatrix<Type,M,N,true>::operator-=(
const Matrix<MT,SO>& rhs )
3989 throw std::invalid_argument(
"Matrix sizes do not match" );
3991 if( (~rhs).canAlias(
this ) ) {
3992 StaticMatrix tmp( ~rhs );
4016 template<
typename Type
4019 template<
typename MT
4021 inline StaticMatrix<Type,M,N,true>& StaticMatrix<Type,M,N,true>::operator*=(
const Matrix<MT,SO>& rhs )
4023 if( M != N || (~rhs).
rows() != M || (~rhs).
columns() != M )
4024 throw std::invalid_argument(
"Matrix sizes do not match" );
4026 StaticMatrix tmp( *
this * (~rhs) );
4027 return this->operator=( tmp );
4041 template<
typename Type
4044 template<
typename Other >
4045 inline typename EnableIf< IsNumeric<Other>, StaticMatrix<Type,M,N,true> >::Type&
4046 StaticMatrix<Type,M,N,true>::operator*=( Other rhs )
4048 return operator=( (*
this) * rhs );
4064 template<
typename Type
4067 template<
typename Other >
4068 inline typename EnableIf< IsNumeric<Other>, StaticMatrix<Type,M,N,true> >::Type&
4069 StaticMatrix<Type,M,N,true>::operator/=( Other rhs )
4073 return operator=( (*
this) / rhs );
4093 template<
typename Type
4110 template<
typename Type
4130 template<
typename Type
4147 template<
typename Type
4165 template<
typename Type
4183 template<
typename Type
4188 size_t nonzeros( 0UL );
4190 for(
size_t j=0UL; j<N; ++j )
4191 for(
size_t i=0UL; i<M; ++i )
4208 template<
typename Type
4215 const size_t iend( (j+1UL)*MM );
4216 size_t nonzeros( 0UL );
4218 for(
size_t i=j*MM; i<iend; ++i )
4234 template<
typename Type
4241 for(
size_t j=0UL; j<N; ++j )
4242 for(
size_t i=0UL; i<M; ++i )
4243 reset( v_[i+j*MM] );
4259 template<
typename Type
4267 for(
size_t i=0UL; i<M; ++i )
4268 reset( v_[i+j*MM] );
4280 template<
typename Type
4287 for(
size_t j=1UL; j<N; ++j )
4288 for(
size_t i=0UL; i<j; ++i )
4289 swap( v_[i+j*MM], v_[j+i*MM] );
4315 template<
typename Type
4320 if( M != N )
return false;
4322 for(
size_t j=1UL; j<N; ++j ) {
4323 for(
size_t i=0UL; i<j; ++i ) {
4341 template<
typename Type
4346 if( M != N )
return false;
4348 for(
size_t j=1; j<N; ++j ) {
4349 for(
size_t i=0; i<j; ++i ) {
4350 if( !
equal( v_[i+j*MM], v_[j+i*MM] ) )
4368 template<
typename Type
4371 template<
typename Other >
4372 inline StaticMatrix<Type,M,N,true>&
4373 StaticMatrix<Type,M,N,true>::scale(
const Other& scalar )
4375 for(
size_t j=0UL; j<N; ++j )
4376 for(
size_t i=0UL; i<M; ++i )
4377 v_[i+j*MM] *= scalar;
4393 template<
typename Type
4400 for(
size_t j=0UL; j<N; ++j ) {
4401 for(
size_t i=0UL; i<M; ++i ) {
4402 swap( v_[i+j*MM], m(i,j) );
4429 template<
typename Type
4432 template<
typename Other >
4435 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4452 template<
typename Type
4455 template<
typename Other >
4458 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4477 template<
typename Type
4480 inline typename StaticMatrix<Type,M,N,true>::IntrinsicType
4490 return load( &v_[i+j*MM] );
4508 template<
typename Type
4511 template<
typename MT
4513 inline typename DisableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4518 for(
size_t j=0UL; j<N; ++j ) {
4519 for(
size_t i=0UL; i<M; ++i ) {
4520 v_[i+j*MM] = (~rhs)(i,j);
4540 template<
typename Type
4543 template<
typename MT
4545 inline typename EnableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4552 for(
size_t j=0UL; j<N; ++j ) {
4553 for(
size_t i=0UL; i<M; i+=IT::size ) {
4554 store( &v_[i+j*MM], (~rhs).
get(i,j) );
4574 template<
typename Type
4577 template<
typename MT >
4582 typedef typename MT::ConstIterator ConstIterator;
4584 for(
size_t j=0UL; j<N; ++j )
4585 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4586 v_[element->index()+j*MM] = element->value();
4604 template<
typename Type
4607 template<
typename MT >
4612 typedef typename MT::ConstIterator ConstIterator;
4614 for(
size_t i=0UL; i<M; ++i )
4615 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4616 v_[i+element->index()*MM] = element->value();
4634 template<
typename Type
4637 template<
typename MT
4639 inline typename DisableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4644 for(
size_t j=0UL; j<N; ++j ) {
4645 for(
size_t i=0UL; i<M; ++i ) {
4646 v_[i+j*MM] += (~rhs)(i,j);
4666 template<
typename Type
4669 template<
typename MT
4671 inline typename EnableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4678 for(
size_t j=0UL; j<N; ++j ) {
4679 for(
size_t i=0UL; i<M; i+=IT::size ) {
4680 store( &v_[i+j*MM],
load( &v_[i+j*MM] ) + (~rhs).
get(i,j) );
4700 template<
typename Type
4703 template<
typename MT >
4708 typedef typename MT::ConstIterator ConstIterator;
4710 for(
size_t j=0UL; j<N; ++j )
4711 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4712 v_[element->index()+j*MM] += element->value();
4730 template<
typename Type
4733 template<
typename MT >
4738 typedef typename MT::ConstIterator ConstIterator;
4740 for(
size_t i=0UL; i<M; ++i )
4741 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4742 v_[i+element->index()*MM] += element->value();
4760 template<
typename Type
4763 template<
typename MT
4765 inline typename DisableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4770 for(
size_t j=0UL; j<N; ++j ) {
4771 for(
size_t i=0UL; i<M; ++i ) {
4772 v_[i+j*MM] -= (~rhs)(i,j);
4792 template<
typename Type
4795 template<
typename MT
4797 inline typename EnableIf< typename StaticMatrix<Type,M,N,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4804 for(
size_t j=0UL; j<N; ++j ) {
4805 for(
size_t i=0UL; i<M; i+=IT::size ) {
4806 store( &v_[i+j*MM],
load( &v_[i+j*MM] ) - (~rhs).
get(i,j) );
4826 template<
typename Type
4829 template<
typename MT >
4834 typedef typename MT::ConstIterator ConstIterator;
4836 for(
size_t j=0UL; j<N; ++j )
4837 for( ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4838 v_[element->index()+j*MM] -= element->value();
4856 template<
typename Type
4859 template<
typename MT >
4864 typedef typename MT::ConstIterator ConstIterator;
4866 for(
size_t i=0UL; i<M; ++i )
4867 for( ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4868 v_[i+element->index()*MM] -= element->value();
4894 template<
typename Type
4897 class StaticMatrix<Type,M,0UL,SO>;
4910 template<
typename Type
4913 class StaticMatrix<Type,0UL,N,SO>;
4926 template<
typename Type
4928 class StaticMatrix<Type,0UL,0UL,SO>;
4948 template<
typename Type,
size_t M,
size_t N,
bool SO >
4949 inline bool isnan(
const StaticMatrix<Type,M,N,SO>& m );
4951 template<
typename Type,
size_t M,
size_t N,
bool SO >
4952 inline void reset( StaticMatrix<Type,M,N,SO>& m );
4954 template<
typename Type,
size_t M,
size_t N,
bool SO >
4955 inline void clear( StaticMatrix<Type,M,N,SO>& m );
4957 template<
typename Type,
size_t M,
size_t N,
bool SO >
4958 inline bool isDefault(
const StaticMatrix<Type,M,N,SO>& m );
4960 template<
typename Type,
size_t M,
size_t N,
bool SO >
4961 inline void swap( StaticMatrix<Type,M,N,SO>& a, StaticMatrix<Type,M,N,SO>& b ) ;
4973 template<
typename Type
4979 for(
size_t i=0UL; i<M*N; ++i ) {
4996 template<
typename Type
5016 template<
typename Type
5034 template<
typename Type
5040 for(
size_t i=0UL; i<M*N; ++i ) {
5059 template<
typename Type
5080 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5081 struct AddTrait< StaticMatrix<T1,M,N,SO>, StaticMatrix<T2,M,N,SO> >
5083 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
5086 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
5087 struct AddTrait< StaticMatrix<T1,M,N,SO1>, StaticMatrix<T2,M,N,SO2> >
5089 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
5105 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5106 struct SubTrait< StaticMatrix<T1,M,N,SO>, StaticMatrix<T2,M,N,SO> >
5108 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
5111 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
5112 struct SubTrait< StaticMatrix<T1,M,N,SO1>, StaticMatrix<T2,M,N,SO2> >
5114 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
5130 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5131 struct MultTrait< StaticMatrix<T1,M,N,SO>, T2 >
5133 typedef StaticMatrix< typename MultTrait<T1,T2>::Type, M, N, SO > Type;
5137 template<
typename T1,
typename T2,
size_t M,
size_t N,
bool SO >
5138 struct MultTrait< T1, StaticMatrix<T2,M,N,SO> >
5140 typedef StaticMatrix< typename MultTrait<T1,T2>::Type, M, N, SO > Type;
5144 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5145 struct MultTrait< StaticMatrix<T1,M,N,SO>, StaticVector<T2,N,false> >
5147 typedef StaticVector< typename MultTrait<T1,T2>::Type, M,
false > Type;
5150 template<
typename T1,
size_t M,
typename T2,
size_t N,
bool SO >
5151 struct MultTrait< StaticVector<T1,M,true>, StaticMatrix<T2,M,N,SO> >
5153 typedef StaticVector< typename MultTrait<T1,T2>::Type, N,
true > Type;
5156 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5157 struct MultTrait< StaticMatrix<T1,M,N,SO>, DynamicVector<T2,false> >
5159 typedef StaticVector< typename MultTrait<T1,T2>::Type, M,
false > Type;
5162 template<
typename T1,
typename T2,
size_t M,
size_t N,
bool SO >
5163 struct MultTrait< DynamicVector<T1,true>, StaticMatrix<T2,M,N,SO> >
5165 typedef StaticVector< typename MultTrait<T1,T2>::Type, N,
true > Type;
5168 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5169 struct MultTrait< StaticMatrix<T1,M,N,SO>, CompressedVector<T2,false> >
5171 typedef StaticVector< typename MultTrait<T1,T2>::Type, M,
false > Type;
5174 template<
typename T1,
typename T2,
size_t M,
size_t N,
bool SO >
5175 struct MultTrait< CompressedVector<T1,true>, StaticMatrix<T2,M,N,SO> >
5177 typedef StaticVector< typename MultTrait<T1,T2>::Type, N,
true > Type;
5180 template<
typename T1,
size_t M,
size_t K,
bool SO1,
typename T2,
size_t N,
bool SO2 >
5181 struct MultTrait< StaticMatrix<T1,M,K,SO1>, StaticMatrix<T2,K,N,SO2> >
5183 typedef StaticMatrix< typename MultTrait<T1,T2>::Type, M, N, SO1 > Type;
5199 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5200 struct DivTrait< StaticMatrix<T1,M,N,SO>, T2 >
5202 typedef StaticMatrix< typename DivTrait<T1,T2>::Type, M, N, SO > Type;
5219 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
5220 struct MathTrait< StaticMatrix<T1,M,N,SO>, StaticMatrix<T2,M,N,SO> >
5222 typedef StaticMatrix< typename MathTrait<T1,T2>::HighType, M, N, SO > HighType;
5223 typedef StaticMatrix< typename MathTrait<T1,T2>::LowType , M, N, SO > LowType;
5239 template<
typename T1,
size_t M,
size_t N,
bool SO >
5240 struct RowTrait< StaticMatrix<T1,M,N,SO> >
5242 typedef StaticVector<T1,N,true> Type;
5258 template<
typename T1,
size_t M,
size_t N,
bool SO >
5259 struct ColumnTrait< StaticMatrix<T1,M,N,SO> >
5261 typedef StaticVector<T1,M,false> Type;