LCOV - code coverage report
Current view: top level - tarch/la - VectorOperations.cpph (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.4 % 43 38
Test Date: 2026-08-21 15:14:06 Functions: 80.8 % 26 21

            Line data    Source code
       1              : // Copyright (C) 2015 Technische Universitaet Muenchen
       2              : // This file is part of the Mamico project. For conditions of distribution
       3              : // and use, please see the copyright notice in Mamico's main folder, or at
       4              : // www5.in.tum.de/mamico
       5              : #ifndef _TARCH_LA_VECTOROPERATIONS_H_
       6              : #define _TARCH_LA_VECTOROPERATIONS_H_
       7              : 
       8              : #include <Kokkos_Core.hpp>
       9              : 
      10              : /**     namespace tarch */
      11              : namespace tarch {
      12              : /** namespace la */
      13              : namespace la {
      14              : /** this file contains some methods for vector types.
      15              :  *      @brief adds two vectors and returns the result
      16              :  *      @tparam T Data type
      17              :  *      @tparam size Vector size
      18              :  *      @author Philipp Neumann
      19              :  *      @return result resulting vector
      20              :  */
      21      5746428 : template <int size, class T> KOKKOS_FUNCTION tarch::la::Vector<size, T> operator+(const tarch::la::Vector<size, T>& l, const tarch::la::Vector<size, T>& r) {
      22      5746428 :   tarch::la::Vector<size, T> result;
      23     22985712 :   for (int i = 0; i < size; i++) {
      24     17239284 :     result[i] = l[i] + r[i];
      25              :   }
      26      5746428 :   return result;
      27              : }
      28              : 
      29              : /** this file contains some methods for vector types.
      30              :  *      @brief subtracts two vectors and returns the result
      31              :  *      @tparam T Data type
      32              :  *      @tparam size Vector size
      33              :  *      @author Philipp Neumann
      34              :  *      @return result resulting vector
      35              :  */
      36      4878296 : template <int size, class T> KOKKOS_FUNCTION tarch::la::Vector<size, T> operator-(const tarch::la::Vector<size, T>& l, const tarch::la::Vector<size, T>& r) {
      37      4878296 :   tarch::la::Vector<size, T> result;
      38     19513184 :   for (int i = 0; i < size; i++) {
      39     14634888 :     result[i] = l[i] - r[i];
      40              :   }
      41      4878296 :   return result;
      42              : }
      43              : 
      44              : /** this file contains some methods for vector types.
      45              :  *      @brief multiplies a vector to a scalar and returns the resulting vector
      46              :  *      @tparam T Data type
      47              :  *      @tparam size Vector size
      48              :  *      @author Philipp Neumann
      49              :  *      @return result resulting vector
      50              :  */
      51           72 : template <int size, class T> KOKKOS_FUNCTION tarch::la::Vector<size, T> operator*(const tarch::la::Vector<size, T>& v, const T& s) {
      52           72 :   tarch::la::Vector<size, T> result;
      53          288 :   for (int i = 0; i < size; i++) {
      54          216 :     result[i] = v[i] * s;
      55              :   }
      56           72 :   return result;
      57              : }
      58              : 
      59              : /** this file contains some methods for vector types.
      60              :  *      @brief multiplies a scalar to a vector and returns the resulting vector
      61              :  *      @tparam T Data type
      62              :  *      @tparam size Vector size
      63              :  *      @author Philipp Neumann
      64              :  *      @return result resulting vector
      65              :  */
      66       420016 : template <int size, class T> KOKKOS_FUNCTION tarch::la::Vector<size, T> operator*(const T& s, const tarch::la::Vector<size, T>& v) {
      67       420016 :   tarch::la::Vector<size, T> result;
      68      1680064 :   for (int i = 0; i < size; i++) {
      69      1260048 :     result[i] = v[i] * s;
      70              :   }
      71       420016 :   return result;
      72              : }
      73              : 
      74              : /** this file contains some methods for vector types.
      75              :  *      @brief devides a vector over a scaler, i.e. this operator devides all
      76              :  * entries of vector over a scalar and returns the result.
      77              :  *  @tparam T Data type
      78              :  *  @tparam size Vector size
      79              :  *      @author Niklas Wittmer
      80              :  *      @return result resulting vector
      81              :  */
      82           72 : template <int size, class T> KOKKOS_FUNCTION tarch::la::Vector<size, T> operator/(const tarch::la::Vector<size, T>& v, const T& s) {
      83           72 :   tarch::la::Vector<size, T> result;
      84          288 :   for (int i = 0; i < size; i++) {
      85          216 :     result[i] = v[i] / s;
      86              :   }
      87           72 :   return result;
      88              : }
      89              : 
      90              : /** this file contains some methods for vector types.
      91              :  *      @brief computes the inner product of two vectors
      92              :  *      @tparam T Data type
      93              :  *      @tparam size Vector size
      94              :  *      @author Philipp Neumann
      95              :  *      @return t resulting scalar
      96              :  */
      97            0 : template <int size, class T> KOKKOS_FUNCTION T dot(const tarch::la::Vector<size, T>& l, const tarch::la::Vector<size, T>& r) {
      98            0 :   T t = l[0] * r[0];
      99            0 :   for (int i = 1; i < size; i++) {
     100            0 :     t += l[i] * r[i];
     101              :   }
     102            0 :   return t;
     103              : }
     104              : 
     105              : /** This operator overloading compares two vectors and determins if they are equal.
     106              :  *      @brief for comparison of two vectors
     107              :  *      @tparam T Data type
     108              :  *      @tparam size Vector size
     109              :  *      @author Philipp Neumann
     110              :  *      @return equal result; true: if they are equal, false otherwise.
     111              :  */
     112       980988 : template <int size, class T> KOKKOS_FUNCTION bool operator==(const Vector<size, T>& l, const Vector<size, T>& r) {
     113       980988 :   bool equal = true;
     114      3923804 :   for (int i = 0; i < size; i++) {
     115      5885628 :     equal = equal && (l[i] == r[i]);
     116              :   }
     117       980988 :   return equal;
     118              : }
     119              : 
     120              : /** This operator overloading compares two vectors and determins if they are NOT equal.
     121              :  *      @brief for comparison of two vectors
     122              :  *      @tparam T Data type
     123              :  *      @tparam size Vector size
     124              :  *      @author Philipp Neumann
     125              :  *      @return true: if they are NOT equal, false otherwise.
     126              :  */
     127       413748 : template <int size, class T> KOKKOS_FUNCTION bool operator!=(const Vector<size, T>& l, const Vector<size, T>& r) {
     128       513096 :   for (int i = 0; i < size; i++) {
     129       495970 :     if (l[i] != r[i])
     130              :       return true;
     131              :   }
     132              :   return false;
     133              : }
     134              : 
     135              : /** this file contains some methods for vector types.
     136              :  *      @brief computes the L2-norm
     137              :  *      @tparam T Data type
     138              :  *      @tparam size Vector size
     139              :  *      @author Philipp Neumann
     140              :  *      @return the square root of the inner product (dot product) of a vector
     141              :  *with itself
     142              :  */
     143              : template <int size, class T> KOKKOS_FUNCTION T norm2(const Vector<size, T>& v) { return sqrt(tarch::la::dot(v, v)); }
     144              : 
     145              : /** this file contains some methods for vector types.
     146              :  *      @brief operator overloading for output purposes
     147              :  *      @tparam T Data type
     148              :  *      @tparam size Vector size
     149              :  *      @author Philipp Neumann
     150              :  */
     151          224 : template <int size, class T> std::ostream& operator<<(std::ostream& os, const tarch::la::Vector<size, T>& v) {
     152          672 :   for (int i = 0; i < size - 1; i++) {
     153          448 :     os << v[i] << " , ";
     154              :   }
     155          224 :   os << v[size - 1];
     156          224 :   return os;
     157              : }
     158              : 
     159              : } // namespace la
     160              : } // namespace tarch
     161              : #endif
        

Generated by: LCOV version 2.0-1