pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
identity.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_IDENTITY_H
4#define pRC_CORE_TENSOR_IDENTITY_H
5
9
10namespace pRC
11{
21 template<class T>
22 struct Identity<T, If<IsTensorView<T>>> : Identity<ResultOf<Eval, T>>
23 {
24 };
25
31 template<class T>
32 struct Identity<T, If<IsTensor<T>>>
33 {
34 static_assert(IsInvocable<Diagonal, T>(),
35 "Diagonal has to be invocable for T.");
40 constexpr auto operator()()
41 {
42 return diagonal(unit<T>());
43 }
44
53 template<class X, If<IsConstructible<typename T::Type, X>> = 0>
54 constexpr auto operator()(X &&value)
55 {
56 return diagonal(unit<T>(forward<X>(value)));
57 }
58 };
59}
60#endif // pRC_CORE_TENSOR_IDENTITY_H
Definition cholesky.hpp:18
static constexpr auto diagonal(X &&a)
Transforms a Tensor into diagonal form.
Definition diagonal.hpp:26
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
constexpr auto operator()()
Returns the identity of Tensor class T, i.e. a Tensor with diagonal filled with 1s.
Definition identity.hpp:40
constexpr auto operator()(X &&value)
Returns the scaled identity of Tensor class T, i.e. a Tensor with diagonal filled with the scaling fa...
Definition identity.hpp:54
Definition type_traits.hpp:262
Definition type_traits.hpp:60
Definition type_traits.hpp:16