49 #define LVARRAY_TENSOROPS_INIT_LOCAL_2( EXP ) { EXP[ 0 ], EXP[ 1 ] } 57 #define LVARRAY_TENSOROPS_ASSIGN_2( var, exp0, exp1 ) \ 58 var[ 0 ] = exp0; var[ 1 ] = exp1 64 #define LVARRAY_TENSOROPS_INIT_LOCAL_3( EXP ) { EXP[ 0 ], EXP[ 1 ], EXP[ 2 ] } 73 #define LVARRAY_TENSOROPS_ASSIGN_3( var, exp0, exp1, exp2 ) \ 74 var[ 0 ] = exp0; var[ 1 ] = exp1; var[ 2 ] = exp2 80 #define LVARRAY_TENSOROPS_INIT_LOCAL_6( EXP ) { EXP[ 0 ], EXP[ 1 ], EXP[ 2 ], EXP[ 3 ], EXP[ 4 ], EXP[ 5 ] } 92 #define LVARRAY_TENSOROPS_ASSIGN_6( var, exp0, exp1, exp2, exp3, exp4, exp5 ) \ 93 var[ 0 ] = exp0; var[ 1 ] = exp1; var[ 2 ] = exp2; var[ 3 ] = exp3; var[ 4 ] = exp4; var[ 5 ] = exp5 99 #define LVARRAY_TENSOROPS_INIT_LOCAL_2x2( EXP ) \ 100 { { EXP[ 0 ][ 0 ], EXP[ 0 ][ 1 ] }, \ 101 { EXP[ 1 ][ 0 ], EXP[ 1 ][ 1 ] } } 111 #define LVARRAY_TENSOROPS_ASSIGN_2x2( var, exp00, exp01, exp10, exp11 ) \ 112 var[ 0 ][ 0 ] = exp00; var[ 0 ][ 1 ] = exp01; \ 113 var[ 1 ][ 0 ] = exp10; var[ 1 ][ 1 ] = exp11 119 #define LVARRAY_TENSOROPS_INIT_LOCAL_3x3( EXP ) \ 120 { { EXP[ 0 ][ 0 ], EXP[ 0 ][ 1 ], EXP[ 0 ][ 2 ] }, \ 121 { EXP[ 1 ][ 0 ], EXP[ 1 ][ 1 ], EXP[ 1 ][ 2 ] }, \ 122 { EXP[ 2 ][ 0 ], EXP[ 2 ][ 1 ], EXP[ 2 ][ 2 ] } } 137 #define LVARRAY_TENSOROPS_ASSIGN_3x3( var, exp00, exp01, exp02, exp10, exp11, exp12, exp20, exp21, exp22 ) \ 138 var[ 0 ][ 0 ] = exp00; var[ 0 ][ 1 ] = exp01; var[ 0 ][ 2 ] = exp02; \ 139 var[ 1 ][ 0 ] = exp10; var[ 1 ][ 1 ] = exp11; var[ 1 ][ 2 ] = exp12; \ 140 var[ 2 ][ 0 ] = exp20; var[ 2 ][ 1 ] = exp21; var[ 2 ][ 2 ] = exp22 163 template< std::ptrdiff_t ISIZE,
typename T >
165 std::enable_if_t< HasStaticMember_SIZE< T > >
166 checkSizes( T
const & src )
168 static_assert( ISIZE == T::SIZE,
169 "Expected the first dimension of size ISIZE, got an type of size T::SIZE." );
180 template< std::ptrdiff_t PROVIDED_SIZE,
typename T, std::ptrdiff_t INFERRED_SIZE >
182 void checkSizes( T
const ( &src )[ INFERRED_SIZE ] )
184 static_assert( PROVIDED_SIZE == INFERRED_SIZE,
185 "Expected the first dimension of size PROVIDED_N, got an array of size INFERRED_N." );
198 template< std::ptrdiff_t PROVIDED_M,
199 std::ptrdiff_t PROVIDED_N,
201 std::ptrdiff_t INFERRED_M,
202 std::ptrdiff_t INFERRED_N >
204 void checkSizes( T
const ( &src )[ INFERRED_M ][ INFERRED_N ] )
206 static_assert( PROVIDED_M == INFERRED_M,
"Expected the first dimension of size PROVIDED_M, got an array of size INFERRED_M." );
207 static_assert( PROVIDED_N == INFERRED_N,
"Expected the second dimension of size PROVIDED_N, got an array of size INFERRED_N." );
217 template< std::ptrdiff_t ISIZE,
typename ARRAY >
219 std::enable_if_t< HasStaticMember_NDIM< ARRAY > >
220 checkSizes( ARRAY
const & array )
222 static_assert( ARRAY::NDIM == 1,
"Must be a 1D array." );
223 #ifdef LVARRAY_BOUNDS_CHECK 237 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename ARRAY >
239 std::enable_if_t< HasStaticMember_NDIM< ARRAY > >
240 checkSizes( ARRAY
const & array )
242 static_assert( ARRAY::NDIM == 2,
"Must be a 1D array." );
243 #ifdef LVARRAY_BOUNDS_CHECK 254 template< std::ptrdiff_t ISIZE >
255 constexpr std::ptrdiff_t
SYM_SIZE = ( ISIZE * ( ISIZE + 1 ) ) / 2;
271 template< std::ptrdiff_t ISIZE,
typename VECTOR >
275 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
276 internal::checkSizes< ISIZE >( vector );
279 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
295 template< std::ptrdiff_t ISIZE,
typename VECTOR >
297 void fill( VECTOR && vector, std::remove_reference_t< decltype( vector[ 0 ] ) >
const value )
299 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
300 internal::checkSizes< ISIZE >( vector );
302 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
317 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename MATRIX >
319 void fill( MATRIX && matrix, std::remove_reference_t< decltype( matrix[ 0 ][ 0 ] ) >
const value )
321 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
322 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
323 internal::checkSizes< ISIZE, JSIZE >( matrix );
325 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
327 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
329 matrix[ i ][ j ] = value;
343 template< std::ptrdiff_t ISIZE,
typename DST_VECTOR,
typename SRC_VECTOR >
345 void copy( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
346 SRC_VECTOR
const & LVARRAY_RESTRICT_REF srcVector )
348 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
349 internal::checkSizes< ISIZE >( dstVector );
350 internal::checkSizes< ISIZE >( srcVector );
352 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
354 dstVector[ i ] = srcVector[ i ];
368 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_MATRIX,
typename SRC_MATRIX >
370 void copy( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
371 SRC_MATRIX
const & LVARRAY_RESTRICT_REF srcMatrix )
373 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
374 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
375 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
376 internal::checkSizes< ISIZE, JSIZE >( srcMatrix );
378 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
380 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
382 dstMatrix[ i ][ j ] = srcMatrix[ i ][ j ];
395 template< std::ptrdiff_t ISIZE,
typename VECTOR >
397 void scale( VECTOR && vector, std::remove_reference_t< decltype( vector[ 0 ] ) >
const scale )
399 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
400 internal::checkSizes< ISIZE >( vector );
402 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
404 vector[ i ] *=
scale;
417 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename MATRIX >
419 void scale( MATRIX && matrix, std::remove_reference_t< decltype( matrix[ 0 ][ 0 ] ) >
const scale )
421 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
422 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
423 internal::checkSizes< ISIZE, JSIZE >( matrix );
425 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
427 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
429 matrix[ i ][ j ] *=
scale;
444 template< std::ptrdiff_t ISIZE,
typename DST_VECTOR,
typename SRC_VECTOR >
446 void scaledCopy( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
447 SRC_VECTOR
const & LVARRAY_RESTRICT_REF srcVector,
448 std::remove_reference_t< decltype( srcVector[ 0 ] ) >
const scale )
450 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
451 internal::checkSizes< ISIZE >( dstVector );
452 internal::checkSizes< ISIZE >( srcVector );
454 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
456 dstVector[ i ] =
scale * srcVector[ i ];
471 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_MATRIX,
typename SRC_MATRIX >
473 void scaledCopy( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
474 SRC_MATRIX
const & LVARRAY_RESTRICT_REF srcMatrix,
475 std::remove_reference_t< decltype( srcMatrix[ 0 ][ 0 ] ) >
const scale )
477 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
478 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
479 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
480 internal::checkSizes< ISIZE, JSIZE >( srcMatrix );
482 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
484 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
486 dstMatrix[ i ][ j ] =
scale * srcMatrix[ i ][ j ];
499 template< std::ptrdiff_t M,
typename DST_VECTOR >
501 void addScalar( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
502 std::remove_reference_t< decltype( dstVector[0] ) >
const value )
504 static_assert( M > 0,
"M must be greater than zero." );
505 internal::checkSizes< M >( dstVector );
507 for( std::ptrdiff_t i = 0; i < M; ++i )
509 dstVector[ i ] += value;
522 template< std::ptrdiff_t ISIZE,
typename DST_VECTOR,
typename SRC_VECTOR >
524 void add( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
525 SRC_VECTOR
const & LVARRAY_RESTRICT_REF srcVector )
527 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
528 internal::checkSizes< ISIZE >( dstVector );
529 internal::checkSizes< ISIZE >( srcVector );
531 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
533 dstVector[ i ] += srcVector[ i ];
547 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_MATRIX,
typename SRC_MATRIX >
549 void add( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
550 SRC_MATRIX
const & LVARRAY_RESTRICT_REF srcMatrix )
552 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
553 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
554 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
555 internal::checkSizes< ISIZE, JSIZE >( srcMatrix );
557 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
559 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
561 dstMatrix[ i ][ j ] += srcMatrix[ i ][ j ];
575 template< std::ptrdiff_t ISIZE,
typename DST_VECTOR,
typename SRC_VECTOR >
577 void subtract( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
578 SRC_VECTOR
const & LVARRAY_RESTRICT_REF srcVector )
580 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
581 internal::checkSizes< ISIZE >( dstVector );
582 internal::checkSizes< ISIZE >( srcVector );
584 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
586 dstVector[ i ] -= srcVector[ i ];
600 template< std::ptrdiff_t ISIZE,
typename DST_VECTOR,
typename SRC_VECTOR >
602 void scaledAdd( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
603 SRC_VECTOR
const & LVARRAY_RESTRICT_REF srcVector,
604 std::remove_reference_t< decltype( srcVector[ 0 ] ) >
const scale )
606 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
607 internal::checkSizes< ISIZE >( dstVector );
608 internal::checkSizes< ISIZE >( srcVector );
610 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
612 dstVector[ i ] = dstVector[ i ] +
scale * srcVector[ i ];
626 template< std::ptrdiff_t ISIZE,
typename DST_VECTOR,
typename VECTOR_A,
typename VECTOR_B >
629 VECTOR_A
const & LVARRAY_RESTRICT_REF vectorA,
630 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
632 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
633 internal::checkSizes< ISIZE >( dstVector );
634 internal::checkSizes< ISIZE >( vectorA );
635 internal::checkSizes< ISIZE >( vectorB );
637 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
639 dstVector[ i ] = vectorA[ i ] * vectorB[ i ];
657 template< std::ptrdiff_t ISIZE,
typename VECTOR >
661 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
662 internal::checkSizes< ISIZE >( vector );
664 auto norm = vector[ 0 ] * vector[ 0 ];
665 for( std::ptrdiff_t i = 1; i < ISIZE; ++i )
667 norm = norm + vector[ i ] * vector[ i ];
678 template< std::ptrdiff_t ISIZE,
typename VECTOR >
682 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
683 internal::checkSizes< ISIZE >( vector );
685 return math::sqrt( l2NormSquared< ISIZE >( vector ) );
695 template< std::ptrdiff_t ISIZE,
typename VECTOR >
699 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
700 internal::checkSizes< ISIZE >( vector );
702 auto const normInv =
math::invSqrt( l2NormSquared< ISIZE >( vector ) );
703 scale< ISIZE >( vector, normInv );
716 template< std::ptrdiff_t JSIZE,
typename VECTOR_A,
typename VECTOR_B >
718 auto AiBi( VECTOR_A
const & LVARRAY_RESTRICT_REF vectorA,
719 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
721 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
722 internal::checkSizes< JSIZE >( vectorA );
723 internal::checkSizes< JSIZE >( vectorB );
725 auto result = vectorA[ 0 ] * vectorB[ 0 ];
726 for( std::ptrdiff_t i = 1; i < JSIZE; ++i )
728 result = result + vectorA[ i ] * vectorB[ i ];
743 template<
typename DST_VECTOR,
typename VECTOR_A,
typename VECTOR_B >
746 VECTOR_A
const & LVARRAY_RESTRICT_REF vectorA,
747 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
749 internal::checkSizes< 3 >( dstVector );
750 internal::checkSizes< 3 >( vectorA );
751 internal::checkSizes< 3 >( vectorB );
753 dstVector[ 0 ] = vectorA[ 1 ] * vectorB[ 2 ] - vectorA[ 2 ] * vectorB[ 1 ];
754 dstVector[ 1 ] = vectorA[ 2 ] * vectorB[ 0 ] - vectorA[ 0 ] * vectorB[ 2 ];
755 dstVector[ 2 ] = vectorA[ 0 ] * vectorB[ 1 ] - vectorA[ 1 ] * vectorB[ 0 ];
778 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_MATRIX,
typename VECTOR_A,
typename VECTOR_B >
781 VECTOR_A
const & LVARRAY_RESTRICT_REF vectorA,
782 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
784 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
785 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
786 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
787 internal::checkSizes< ISIZE >( vectorA );
788 internal::checkSizes< JSIZE >( vectorB );
790 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
792 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
794 dstMatrix[ i ][ j ] = vectorA[ i ] * vectorB[ j ];
808 template< std::ptrdiff_t M,
typename DST_MATRIX,
typename VECTOR_A >
811 VECTOR_A
const & LVARRAY_RESTRICT_REF vectorA )
813 static_assert( M > 0,
"M must be greater than zero." );
814 internal::checkSizes< M, M >( dstMatrix );
815 internal::checkSizes< M >( vectorA );
817 for( std::ptrdiff_t i = 0; i < M; ++i )
819 for( std::ptrdiff_t j = 0; j < M; ++j )
821 dstMatrix[ i ][ j ] = vectorA[ i ] * vectorA[ j ];
838 template< std::ptrdiff_t JSIZE, std::ptrdiff_t ISIZE,
typename DST_MATRIX,
typename VECTOR_A,
typename VECTOR_B >
841 VECTOR_A
const & LVARRAY_RESTRICT_REF vectorA,
842 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
844 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
845 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
846 internal::checkSizes< JSIZE, ISIZE >( dstMatrix );
847 internal::checkSizes< JSIZE >( vectorA );
848 internal::checkSizes< ISIZE >( vectorB );
850 for( std::ptrdiff_t i = 0; i < JSIZE; ++i )
852 for( std::ptrdiff_t j = 0; j < ISIZE; ++j )
854 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + vectorA[ i ] * vectorB[ j ];
871 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_VECTOR,
typename MATRIX_A,
typename VECTOR_B >
874 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
875 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
877 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
878 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
879 internal::checkSizes< ISIZE >( dstVector );
880 internal::checkSizes< ISIZE, JSIZE >( matrixA );
881 internal::checkSizes< JSIZE >( vectorB );
883 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
885 dstVector[ i ] = matrixA[ i ][ 0 ] * vectorB[ 0 ];
886 for( std::ptrdiff_t j = 1; j < JSIZE; ++j )
888 dstVector[ i ] = dstVector[ i ] + matrixA[ i ][ j ] * vectorB[ j ];
905 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_VECTOR,
typename MATRIX_A,
typename VECTOR_B >
908 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
909 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
911 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
912 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
913 internal::checkSizes< ISIZE >( dstVector );
914 internal::checkSizes< ISIZE, JSIZE >( matrixA );
915 internal::checkSizes< JSIZE >( vectorB );
917 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
919 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
921 dstVector[ i ] = dstVector[ i ] + matrixA[ i ][ j ] * vectorB[ j ];
939 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_VECTOR,
typename MATRIX_A,
typename VECTOR_B >
942 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
943 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
945 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
946 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
947 internal::checkSizes< ISIZE >( dstVector );
948 internal::checkSizes< JSIZE, ISIZE >( matrixA );
949 internal::checkSizes< JSIZE >( vectorB );
951 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
953 dstVector[ i ] = matrixA[ 0 ][ i ] * vectorB[ 0 ];
954 for( std::ptrdiff_t j = 1; j < JSIZE; ++j )
956 dstVector[ i ] = dstVector[ i ] + matrixA[ j ][ i ] * vectorB[ j ];
974 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_VECTOR,
typename MATRIX_A,
typename VECTOR_B >
977 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
978 VECTOR_B
const & LVARRAY_RESTRICT_REF vectorB )
980 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
981 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
982 internal::checkSizes< ISIZE >( dstVector );
983 internal::checkSizes< JSIZE, ISIZE >( matrixA );
984 internal::checkSizes< JSIZE >( vectorB );
986 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
988 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
990 dstVector[ i ] = dstVector[ i ] + matrixA[ j ][ i ] * vectorB[ j ];
1012 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE,
typename DST_MATRIX,
typename SRC_MATRIX >
1014 void transpose( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1015 SRC_MATRIX
const & LVARRAY_RESTRICT_REF srcMatrix )
1017 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1018 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1019 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1020 internal::checkSizes< JSIZE, ISIZE >( srcMatrix );
1022 for( std::ptrdiff_t i = 0; i < JSIZE; ++i )
1024 for( std::ptrdiff_t j = 0; j < ISIZE; ++j )
1026 dstMatrix[ j ][ i ] = srcMatrix[ i ][ j ];
1045 template< std::ptrdiff_t ISIZE,
1046 std::ptrdiff_t JSIZE,
1047 std::ptrdiff_t KSIZE,
1048 typename DST_MATRIX,
1053 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
1054 MATRIX_B
const & LVARRAY_RESTRICT_REF matrixB )
1056 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1057 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1058 static_assert( KSIZE > 0,
"KSIZE must be greater than zero." );
1059 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1060 internal::checkSizes< ISIZE, KSIZE >( matrixA );
1061 internal::checkSizes< KSIZE, JSIZE >( matrixB );
1064 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1066 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1068 dstMatrix[ i ][ j ] = matrixA[ i ][ 0 ] * matrixB[ 0 ][ j ];
1069 for( std::ptrdiff_t k = 1; k < KSIZE; ++k )
1071 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ k ][ j ];
1091 template< std::ptrdiff_t ISIZE,
1092 std::ptrdiff_t JSIZE,
1093 std::ptrdiff_t KSIZE,
1094 typename DST_MATRIX,
1099 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
1100 MATRIX_B
const & LVARRAY_RESTRICT_REF matrixB )
1102 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1103 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1104 static_assert( KSIZE > 0,
"KSIZE must be greater than zero." );
1105 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1106 internal::checkSizes< ISIZE, KSIZE >( matrixA );
1107 internal::checkSizes< KSIZE, JSIZE >( matrixB );
1110 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1112 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1114 for( std::ptrdiff_t k = 0; k < KSIZE; ++k )
1116 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ k ][ j ];
1136 template< std::ptrdiff_t ISIZE,
1137 std::ptrdiff_t JSIZE,
1138 std::ptrdiff_t KSIZE,
1139 typename DST_MATRIX,
1144 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
1145 MATRIX_B
const & LVARRAY_RESTRICT_REF matrixB )
1147 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1148 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1149 static_assert( KSIZE > 0,
"KSIZE must be greater than zero." );
1150 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1151 internal::checkSizes< ISIZE, KSIZE >( matrixA );
1152 internal::checkSizes< JSIZE, KSIZE >( matrixB );
1155 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1157 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1159 dstMatrix[ i ][ j ] = matrixA[ i ][ 0 ] * matrixB[ j ][ 0 ];
1160 for( std::ptrdiff_t k = 1; k < KSIZE; ++k )
1162 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ j ][ k ];
1182 template< std::ptrdiff_t ISIZE,
1183 std::ptrdiff_t JSIZE,
1184 std::ptrdiff_t KSIZE,
1185 typename DST_MATRIX,
1190 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
1191 MATRIX_B
const & LVARRAY_RESTRICT_REF matrixB )
1193 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1194 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1195 static_assert( KSIZE > 0,
"KSIZE must be greater than zero." );
1196 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1197 internal::checkSizes< ISIZE, KSIZE >( matrixA );
1198 internal::checkSizes< JSIZE, KSIZE >( matrixB );
1200 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1202 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1204 for( std::ptrdiff_t k = 0; k < KSIZE; ++k )
1206 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ j ][ k ];
1223 template< std::ptrdiff_t ISIZE,
1224 std::ptrdiff_t JSIZE,
1225 typename DST_MATRIX,
1229 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA )
1231 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1232 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1233 internal::checkSizes< ISIZE, ISIZE >( dstMatrix );
1234 internal::checkSizes< ISIZE, JSIZE >( matrixA );
1236 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1238 for( std::ptrdiff_t j = 0; j < ISIZE; ++j )
1240 for( std::ptrdiff_t k = 0; k < JSIZE; ++k )
1242 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixA[ j ][ k ];
1262 template< std::ptrdiff_t ISIZE,
1263 std::ptrdiff_t JSIZE,
1264 std::ptrdiff_t KSIZE,
1265 typename DST_MATRIX,
1270 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
1271 MATRIX_B
const & LVARRAY_RESTRICT_REF matrixB )
1273 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1274 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1275 static_assert( KSIZE > 0,
"KSIZE must be greater than zero." );
1276 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1277 internal::checkSizes< KSIZE, ISIZE >( matrixA );
1278 internal::checkSizes< KSIZE, JSIZE >( matrixB );
1280 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1282 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1284 dstMatrix[ i ][ j ] = matrixA[ 0 ][ i ] * matrixB[ 0 ][ j ];
1285 for( std::ptrdiff_t k = 1; k < KSIZE; ++k )
1287 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ k ][ i ] * matrixB[ k ][ j ];
1307 template< std::ptrdiff_t ISIZE,
1308 std::ptrdiff_t JSIZE,
1309 std::ptrdiff_t KSIZE,
1310 typename DST_MATRIX,
1315 MATRIX_A
const & LVARRAY_RESTRICT_REF matrixA,
1316 MATRIX_B
const & LVARRAY_RESTRICT_REF matrixB )
1318 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1319 static_assert( JSIZE > 0,
"JSIZE must be greater than zero." );
1320 static_assert( KSIZE > 0,
"KSIZE must be greater than zero." );
1321 internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1322 internal::checkSizes< KSIZE, ISIZE >( matrixA );
1323 internal::checkSizes< KSIZE, JSIZE >( matrixB );
1325 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1327 for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1329 for( std::ptrdiff_t k = 0; k < KSIZE; ++k )
1331 dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ k ][ i ] * matrixB[ k ][ j ];
1351 template< std::ptrdiff_t ISIZE,
typename MATRIX >
1355 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1356 internal::checkSizes< ISIZE, ISIZE >( matrix );
1358 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1360 for( std::ptrdiff_t j = i + 1; j < ISIZE; ++j )
1362 auto const entryIJ = matrix[ i ][ j ];
1363 matrix[ i ][ j ] = matrix[ j ][ i ];
1364 matrix[ j ][ i ] = entryIJ;
1377 template< std::ptrdiff_t ISIZE,
typename MATRIX >
1379 void addIdentity( MATRIX && matrix, std::remove_reference_t< decltype( matrix[ 0 ][ 0 ] ) >
const scale )
1381 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1382 internal::checkSizes< ISIZE, ISIZE >( matrix );
1384 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1386 matrix[ i ][ i ] +=
scale;
1396 template< std::ptrdiff_t ISIZE,
typename MATRIX >
1400 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1401 internal::checkSizes< ISIZE, ISIZE >( matrix );
1403 auto trace = matrix[ 0 ][ 0 ];
1404 for( std::ptrdiff_t i = 1; i < ISIZE; ++i )
1406 trace += matrix[ i ][ i ];
1428 template< std::ptrdiff_t ISIZE,
typename SYM_MATRIX >
1430 void symAddIdentity( SYM_MATRIX && symMatrix, std::remove_reference_t< decltype( symMatrix[ 0 ] ) >
const scale )
1432 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1433 internal::checkSizes< SYM_SIZE< ISIZE > >( symMatrix );
1435 for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1437 symMatrix[ i ] +=
scale;
1447 template< std::ptrdiff_t ISIZE,
typename SYM_MATRIX >
1451 static_assert( ISIZE > 0,
"ISIZE must be greater than zero." );
1452 internal::checkSizes< SYM_SIZE< ISIZE > >( symMatrix );
1454 auto trace = symMatrix[ 0 ];
1455 for( std::ptrdiff_t i = 1; i < ISIZE; ++i )
1457 trace += symMatrix[ i ];
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
constexpr void fill(VECTOR &&vector, std::remove_reference_t< decltype(vector[0]) > const value)
Set the entries of vector to value.
constexpr std::ptrdiff_t SYM_SIZE
The size of a symmetric MxM matrix in Voigt notation.
constexpr void Rij_add_AikAjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA)
Multiply matrixA with the transpose of itself and put the result into dstMatrix.
constexpr void scale(VECTOR &&vector, std::remove_reference_t< decltype(vector[0]) > const scale)
Multiply the entries of vector by scale.
constexpr void Rij_add_AikBjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with the transpose of matrixB and put the result into dstMatrix. ...
constexpr void symAddIdentity(SYM_MATRIX &&symMatrix, std::remove_reference_t< decltype(symMatrix[0]) > const scale)
Add scale times the identity matrix to symMatrix.
constexpr void transpose(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, SRC_MATRIX const &LVARRAY_RESTRICT_REF srcMatrix)
Store the transpose of the NxM matrix srcMatrix in dstMatrix.
#define HAS_STATIC_MEMBER(NAME)
Macro that expands to a static constexpr bool templated on a type that is only true when the type has...
float sqrt(float const x)
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
constexpr void copy(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Copy srcVector into dstVector.
constexpr void Ri_add_AijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of matrixA and vectorB adding the result to dstVector...
constexpr auto l2NormSquared(VECTOR const &vector)
Contains the implementation of LvArray::ArraySlice.
constexpr void Rij_eq_AiAj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA)
Perform the outer product of vectorA with itself writing the result to dstMatrix. ...
constexpr void Rij_eq_AkiBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply the transpose of matrixA with matrixB and put the result into dstMatrix. ...
Contains some portable math functions.
constexpr void subtract(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Subtract srcVector from dstVector.
constexpr void Rij_add_AkiBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply the transpose of matrixA with matrixB and add the result into dstMatrix. ...
float invSqrt(float const x)
constexpr auto l2Norm(VECTOR const &vector)
constexpr void Rij_eq_AikBjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with the transpose of matrixB and put the result into dstMatrix. ...
constexpr void Rij_eq_AiBj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the outer product of vectorA and vectorB writing the result to dstMatrix. ...
constexpr void Rij_eq_AikBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with matrixB and put the result into dstMatrix.
constexpr void addScalar(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, std::remove_reference_t< decltype(dstVector[0]) > const value)
Add value to dstVector.
constexpr auto normalize(VECTOR &&vector)
Scale vector to a unit vector.
constexpr void Ri_eq_AjiBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of the transpose of matrixA and vectorB writing the result t...
constexpr auto AiBi(VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
constexpr void addIdentity(MATRIX &&matrix, std::remove_reference_t< decltype(matrix[0][0]) > const scale)
Add scale times the identity matrix to matrix.
constexpr auto trace(MATRIX const &matrix)
constexpr void Ri_eq_AijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of matrixA and vectorB writing the result to dstVector...
constexpr void crossProduct(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Compute the cross product of vectorA and vectorB and put it in dstVector.
constexpr void Rij_add_AikBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with matrixB and add the result to dstMatrix.
constexpr auto symTrace(SYM_MATRIX const &symMatrix)
constexpr void Rij_add_AiBj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the outer product of vectorA and vectorB adding the result to dstMatrix.
constexpr void add(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Add srcVector to dstVector.
constexpr void scaledCopy(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector, std::remove_reference_t< decltype(srcVector[0]) > const scale)
Copy srcVector scaled by scale into dstVector.
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
constexpr void hadamardProduct(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Multiply the elements of vectorA and vectorB putting the result into dstVector.
#define LVARRAY_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
constexpr void Ri_add_AjiBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of the transpose of matrixA and vectorB adding the result to...
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
constexpr auto maxAbsoluteEntry(VECTOR &&vector)
constexpr void scaledAdd(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector, std::remove_reference_t< decltype(srcVector[0]) > const scale)
Add srcVector scaled by scale to dstVector.