lin
matrix_operations.hpp
Go to the documentation of this file.
1 // vim: set tabstop=2:softtabstop=2:shiftwidth=2:expandtab
2 
7 #ifndef LIN_CORE_OPERATIONS_MATRIX_OPERATIONS_HPP_
8 #define LIN_CORE_OPERATIONS_MATRIX_OPERATIONS_HPP_
9 
10 #include "../config.hpp"
11 #include "../traits.hpp"
12 #include "../types/stream.hpp"
13 
14 #include <type_traits>
15 
16 namespace lin {
17 
22 template <class C, std::enable_if_t<internal::is_square<C>::value, size_t> = 0>
23 constexpr auto trace(internal::Stream<C> const &c) {
24  LIN_ASSERT(c.rows() == c.cols());
25 
26  typename C::Traits::elem_t x = c(0, 0);
27  for (lin::size_t i = 1; i < c.rows(); i++) x += c(i, i);
28  return x;
29 }
30 
34 } // namespace lin
35 
36 #endif
#define LIN_ASSERT(x)
Asserts the condition x when assertions are enabled within lin.
Definition: config.hpp:22
std::size_t size_t
Type tracking tensor dimensions and sizing.
Definition: config.hpp:33
Definition: config.hpp:27