LvArray
fixedSizeSquareMatrixOps.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 #include "genericTensorOps.hpp"
17 
18 namespace LvArray
19 {
20 namespace tensorOps
21 {
22 
28 
36 template< std::ptrdiff_t M, typename MATRIX >
38 auto determinant( MATRIX const & matrix )
40 
51 template< std::ptrdiff_t M, typename DST_MATRIX, typename SRC_MATRIX >
53 auto invert( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
54  SRC_MATRIX const & LVARRAY_RESTRICT_REF srcMatrix )
55 {
56  static_assert( std::is_floating_point< std::decay_t< decltype( dstMatrix[ 0 ][ 0 ] ) > >::value,
57  "The destination matrix must be contain floating point values." );
58  return internal::SquareMatrixOps< M >::invert( std::forward< DST_MATRIX >( dstMatrix ), srcMatrix );
59 }
60 
69 template< std::ptrdiff_t M, typename MATRIX >
71 auto invert( MATRIX && matrix )
72 {
73  static_assert( std::is_floating_point< std::decay_t< decltype( matrix[ 0 ][ 0 ] ) > >::value,
74  "The matrix must be contain floating point values." );
75  return internal::SquareMatrixOps< M >::invert( std::forward< MATRIX >( matrix ) );
76 }
77 
79 
85 
98 template< std::ptrdiff_t M, typename DST_VECTOR, typename SYM_MATRIX_A, typename VECTOR_B >
100 void Ri_eq_symAijBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
101  SYM_MATRIX_A const & LVARRAY_RESTRICT_REF symMatrixA,
102  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
103 {
104  internal::SquareMatrixOps< M >::Ri_eq_symAijBj( std::forward< DST_VECTOR >( dstVector ),
105  symMatrixA,
106  vectorB );
107 }
108 
120 template< std::ptrdiff_t M, typename DST_VECTOR, typename SYM_MATRIX_A, typename VECTOR_B >
122 void Ri_add_symAijBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
123  SYM_MATRIX_A const & LVARRAY_RESTRICT_REF symMatrixA,
124  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
125 {
126  internal::SquareMatrixOps< M >::Ri_add_symAijBj( std::forward< DST_VECTOR >( dstVector ),
127  symMatrixA,
128  vectorB );
129 }
130 
143 template< std::ptrdiff_t M, typename DST_MATRIX, typename SYM_MATRIX_A, typename MATRIX_B >
145 void Rij_eq_symAikBjk( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
146  SYM_MATRIX_A const & LVARRAY_RESTRICT_REF symMatrixA,
147  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
148 {
149  internal::SquareMatrixOps< M >::Rij_eq_symAikBjk( std::forward< DST_MATRIX >( dstMatrix ),
150  symMatrixA,
151  matrixB );
152 }
153 
168 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename MATRIX_A, typename SYM_MATRIX_B >
170 void Rij_eq_AikSymBklAjl( DST_SYM_MATRIX && LVARRAY_RESTRICT_REF dstSymMatrix,
171  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
172  SYM_MATRIX_B const & LVARRAY_RESTRICT_REF symMatrixB )
173 {
174  internal::SquareMatrixOps< M >::Rij_eq_AikSymBklAjl( std::forward< DST_SYM_MATRIX >( dstSymMatrix ),
175  matrixA,
176  symMatrixB );
177 }
178 
179 
189 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename VECTOR_A >
191 void symRij_eq_AiAj( DST_SYM_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
192  VECTOR_A const & LVARRAY_RESTRICT_REF vectorA )
193 {
194  internal::SquareMatrixOps< M >::symRij_eq_AiAj( std::forward< DST_SYM_MATRIX >( dstMatrix ),
195  vectorA );
196 }
197 
210 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename VECTOR_A, typename VECTOR_B >
212 void symRij_eq_AiBj_plus_AjBi( DST_SYM_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
213  VECTOR_A const & LVARRAY_RESTRICT_REF vectorA,
214  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
215 {
216  internal::SquareMatrixOps< M >::symRij_eq_AiBj_plus_AjBi( std::forward< DST_SYM_MATRIX >( dstMatrix ),
217  vectorA,
218  vectorB );
219 }
220 
221 
227 template< std::ptrdiff_t M, typename SYM_MATRIX >
229 auto symDeterminant( SYM_MATRIX const & symMatrix )
230 { return internal::SquareMatrixOps< M >::symDeterminant( symMatrix ); }
231 
242 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename SRC_SYM_MATRIX >
244 auto symInvert( DST_SYM_MATRIX && LVARRAY_RESTRICT_REF dstSymMatrix,
245  SRC_SYM_MATRIX const & LVARRAY_RESTRICT_REF srcSymMatrix )
246 {
247  static_assert( std::is_floating_point< std::decay_t< decltype( dstSymMatrix[ 0 ] ) > >::value,
248  "The destination matrix must be contain floating point values." );
249  return internal::SquareMatrixOps< M >::symInvert( std::forward< DST_SYM_MATRIX >( dstSymMatrix ), srcSymMatrix );
250 }
251 
260 template< std::ptrdiff_t M, typename SYM_MATRIX >
262 auto symInvert( SYM_MATRIX && symMatrix )
263 {
264  static_assert( std::is_floating_point< std::decay_t< decltype( symMatrix[ 0 ] ) > >::value,
265  "The matrix must be contain floating point values." );
266  return internal::SquareMatrixOps< M >::symInvert( std::forward< SYM_MATRIX >( symMatrix ) );
267 }
268 
283 template< std::ptrdiff_t M, typename DST_VECTOR, typename SYM_MATRIX >
285 void symEigenvalues( DST_VECTOR && LVARRAY_RESTRICT_REF eigenvalues,
286  SYM_MATRIX const & LVARRAY_RESTRICT_REF symMatrix )
287 {
288  static_assert( std::is_floating_point< std::decay_t< decltype( eigenvalues[ 0 ] ) > >::value,
289  "eigenvalues must be contain floating point values." );
290  internal::SquareMatrixOps< M >::symEigenvalues( std::forward< DST_VECTOR >( eigenvalues ), symMatrix );
291 }
292 
310 template< std::ptrdiff_t M, typename DST_VECTOR, typename DST_MATRIX, typename SYM_MATRIX >
312 void symEigenvectors( DST_VECTOR && LVARRAY_RESTRICT_REF eigenvalues,
313  DST_MATRIX && LVARRAY_RESTRICT_REF eigenvectors,
314  SYM_MATRIX const & LVARRAY_RESTRICT_REF symMatrix )
315 {
316  static_assert( std::is_floating_point< std::decay_t< decltype( eigenvalues[ 0 ] ) > >::value,
317  "eigenvalues must be contain floating point values." );
318  static_assert( std::is_floating_point< std::decay_t< decltype( eigenvectors[ 0 ][ 0 ] ) > >::value,
319  "eigenvectors must be contain floating point values." );
320  internal::SquareMatrixOps< M >::symEigenvectors( std::forward< DST_VECTOR >( eigenvalues ),
321  std::forward< DST_MATRIX >( eigenvectors ),
322  symMatrix );
323 }
324 
333 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename SRC_MATRIX >
334 LVARRAY_HOST_DEVICE constexpr inline
335 void denseToSymmetric( DST_SYM_MATRIX && dstSymMatrix, SRC_MATRIX const & srcMatrix )
336 {
337  return internal::SquareMatrixOps< M >::denseToSymmetric( std::forward< DST_SYM_MATRIX >( dstSymMatrix ),
338  srcMatrix );
339 }
340 
349 template< std::ptrdiff_t M, typename DST_MATRIX, typename SRC_SYM_MATRIX >
350 LVARRAY_HOST_DEVICE constexpr inline
351 void symmetricToDense( DST_MATRIX && dstMatrix, SRC_SYM_MATRIX const & srcSymMatrix )
352 {
353  return internal::SquareMatrixOps< M >::symmetricToDense( std::forward< DST_MATRIX >( dstMatrix ),
354  srcSymMatrix );
355 }
356 
358 
359 } // namespace tensorOps
360 } // namespace LvArray
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void Ri_eq_symAijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SYM_MATRIX_A const &LVARRAY_RESTRICT_REF symMatrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Multiply the vector vectorB by the symmetric matrix symMatrixA and store the result in dstVector...
Definition: fixedSizeSquareMatrixOps.hpp:100
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void symRij_eq_AiBj_plus_AjBi(DST_SYM_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the unscaled symmetric outer product of vectorA and vectorB with itself writing the result to...
Definition: fixedSizeSquareMatrixOps.hpp:212
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void Rij_eq_symAikBjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, SYM_MATRIX_A const &LVARRAY_RESTRICT_REF symMatrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply the transpose of matrix matrixB by the symmetric matrix symMatrixA and store the result in d...
Definition: fixedSizeSquareMatrixOps.hpp:145
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void symEigenvectors(DST_VECTOR &&LVARRAY_RESTRICT_REF eigenvalues, DST_MATRIX &&LVARRAY_RESTRICT_REF eigenvectors, SYM_MATRIX const &LVARRAY_RESTRICT_REF symMatrix)
Compute the eigenvalues and eigenvectors of the symmetric matrix symMatrix.
Definition: fixedSizeSquareMatrixOps.hpp:312
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK auto invert(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, SRC_MATRIX const &LVARRAY_RESTRICT_REF srcMatrix)
Invert the source matrix srcMatrix and store the result in dstMatrix.
Definition: fixedSizeSquareMatrixOps.hpp:53
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK auto symDeterminant(SYM_MATRIX const &symMatrix)
Definition: fixedSizeSquareMatrixOps.hpp:229
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK auto invert(MATRIX &&matrix)
Invert the matrix matrix overwritting it.
Definition: fixedSizeSquareMatrixOps.hpp:71
Contains the implementation of arbitrary sized vector and matrix operations.
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
Definition: Macros.hpp:609
Contains the implementation of the 2x2 and 3x3 matrix operations.
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void Ri_add_symAijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SYM_MATRIX_A const &LVARRAY_RESTRICT_REF symMatrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Multiply the vector vectorB by the symmetric matrix symMatrixA and add the result to dstVector...
Definition: fixedSizeSquareMatrixOps.hpp:122
The top level namespace.
Definition: Array.hpp:24
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void Rij_eq_AikSymBklAjl(DST_SYM_MATRIX &&LVARRAY_RESTRICT_REF dstSymMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, SYM_MATRIX_B const &LVARRAY_RESTRICT_REF symMatrixB)
Multiply the transpose of matrix matrixA by the symmetric matrix symMatrixB then by matrixA and store...
Definition: fixedSizeSquareMatrixOps.hpp:170
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK auto symInvert(SYM_MATRIX &&symMatrix)
Invert the symmetric matrix symMatrix overwritting it.
Definition: fixedSizeSquareMatrixOps.hpp:262
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK auto determinant(MATRIX const &matrix)
Definition: fixedSizeSquareMatrixOps.hpp:38
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void symRij_eq_AiAj(DST_SYM_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. ...
Definition: fixedSizeSquareMatrixOps.hpp:191
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK auto symInvert(DST_SYM_MATRIX &&LVARRAY_RESTRICT_REF dstSymMatrix, SRC_SYM_MATRIX const &LVARRAY_RESTRICT_REF srcSymMatrix)
Invert the symmetric matrix srcSymMatrix and store the result in dstSymMatrix.
Definition: fixedSizeSquareMatrixOps.hpp:244
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void symEigenvalues(DST_VECTOR &&LVARRAY_RESTRICT_REF eigenvalues, SYM_MATRIX const &LVARRAY_RESTRICT_REF symMatrix)
Compute the eigenvalues of the symmetric matrix symMatrix.
Definition: fixedSizeSquareMatrixOps.hpp:285
LVARRAY_HOST_DEVICE constexpr void denseToSymmetric(DST_SYM_MATRIX &&dstSymMatrix, SRC_MATRIX const &srcMatrix)
Convert the upper triangular part of srcMatrix to a symmetric matrix.
Definition: fixedSizeSquareMatrixOps.hpp:335
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:549
LVARRAY_HOST_DEVICE constexpr void symmetricToDense(DST_MATRIX &&dstMatrix, SRC_SYM_MATRIX const &srcSymMatrix)
Convert the srcSymMatrix into a dense matrix.
Definition: fixedSizeSquareMatrixOps.hpp:351