LCOV - code coverage report
Current view: top level - tensors - VecBase.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 25 25
Test Date: 2025-06-29 01:25:44 Functions: 66.7 % 30 20

            Line data    Source code
       1              : // Copyright 2024, UChicago Argonne, LLC
       2              : // All Rights Reserved
       3              : // Software Name: NEML2 -- the New Engineering material Model Library, version 2
       4              : // By: Argonne National Laboratory
       5              : // OPEN SOURCE LICENSE (MIT)
       6              : //
       7              : // Permission is hereby granted, free of charge, to any person obtaining a copy
       8              : // of this software and associated documentation files (the "Software"), to deal
       9              : // in the Software without restriction, including without limitation the rights
      10              : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      11              : // copies of the Software, and to permit persons to whom the Software is
      12              : // furnished to do so, subject to the following conditions:
      13              : //
      14              : // The above copyright notice and this permission notice shall be included in
      15              : // all copies or substantial portions of the Software.
      16              : //
      17              : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      18              : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      19              : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      20              : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      21              : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      22              : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      23              : // THE SOFTWARE.
      24              : 
      25              : #include "neml2/tensors/VecBase.h"
      26              : #include "neml2/tensors/tensors.h"
      27              : #include "neml2/tensors/functions/sqrt.h"
      28              : #include "neml2/tensors/functions/linalg/vecdot.h"
      29              : 
      30              : namespace neml2
      31              : {
      32              : template <class Derived>
      33              : Derived
      34          159 : VecBase<Derived>::fill(const CScalar & v1,
      35              :                        const CScalar & v2,
      36              :                        const CScalar & v3,
      37              :                        const TensorOptions & options)
      38              : {
      39          159 :   return VecBase<Derived>::fill(Scalar(v1, options), Scalar(v2, options), Scalar(v3, options));
      40              : }
      41              : 
      42              : template <class Derived>
      43              : Derived
      44          190 : VecBase<Derived>::fill(const Scalar & v1, const Scalar & v2, const Scalar & v3)
      45              : {
      46          950 :   return Derived(at::stack({v1, v2, v3}, -1), v1.batch_sizes());
      47          190 : }
      48              : 
      49              : template <class Derived>
      50              : R2
      51            1 : VecBase<Derived>::identity_map(const TensorOptions & options)
      52              : {
      53            1 :   return R2::identity(options);
      54              : }
      55              : 
      56              : template <class Derived>
      57              : Scalar
      58         2138 : VecBase<Derived>::operator()(Size i) const
      59              : {
      60         6414 :   return Scalar(this->base_index({i}), this->batch_sizes());
      61         2138 : }
      62              : 
      63              : template <class Derived>
      64              : Scalar
      65         1628 : VecBase<Derived>::norm_sq() const
      66              : {
      67         1628 :   return linalg::vecdot(*this, *this);
      68              : }
      69              : 
      70              : template <class Derived>
      71              : Scalar
      72         1197 : VecBase<Derived>::norm() const
      73              : {
      74         1197 :   return sqrt(norm_sq());
      75              : }
      76              : 
      77              : template <class Derived>
      78              : Derived
      79           21 : VecBase<Derived>::rotate(const Rot & r) const
      80              : {
      81           21 :   return this->rotate(r.euler_rodrigues());
      82              : }
      83              : 
      84              : template <class Derived>
      85              : Derived
      86           37 : VecBase<Derived>::rotate(const R2 & R) const
      87              : {
      88           37 :   return Derived(R * Vec(*this));
      89              : }
      90              : 
      91              : template <class Derived>
      92              : R2
      93            6 : VecBase<Derived>::drotate(const Rot & r) const
      94              : {
      95           30 :   return R2(at::einsum("...ijk,...j", {r.deuler_rodrigues(), *this}));
      96           12 : }
      97              : 
      98              : template <class Derived>
      99              : R3
     100            6 : VecBase<Derived>::drotate(const R2 & R) const
     101              : {
     102            6 :   auto I = R2::identity(R.options());
     103           30 :   return R3(at::einsum("...ij,...k", {I, *this}));
     104           12 : }
     105              : 
     106              : #define VECBASE_INSTANTIATE(T) template class VecBase<T>
     107              : FOR_ALL_VECBASE(VECBASE_INSTANTIATE);
     108              : } // namespace neml2
        

Generated by: LCOV version 2.0-1