85template<
class Coordinates,
Expression ... Sources>
89template<
class Coordinates, Expression Source>
101 switch (source.dtype()) {
102 case float32: dtype_ = complex64;
break;
103 case float64: dtype_ = complex128;
break;
105 throw Exception(
"Complex view error: source tensor dtype must be float32 or float64");
108 if (source.strides()[-1] == 1 && source.strides()[-2] == 2) {
109 assert(source.shape().back() == 2 &&
110 "Complex view error: last dimension must be size 2 (real + imag).");
111 shape_ =
Shape(source.shape().begin(), source.shape().end() - 1);
112 strides_ =
Strides(source.strides().begin(), source.strides().end() - 1);
116 "Complex view error: source tensor is not contiguous in last two dimensions. "
117 "Cannot create complex view safely."
176 return source.offset();
188template<
class Coordinates, Expression Real, Expression Imaginary>
200 , imaginary(imaginary)
202 if (real.shape() != imaginary.shape() | real.strides() != imaginary.strides())
203 throw Exception(
"Complexification error: real and imaginary part layouts must match");
205 if (real.dtype() == float64 || imaginary.dtype() == float64) {
243 return real.strides();
289template<Expression Source>
302 case complex64: dtype_ = float32;
break;
303 case complex128: dtype_ = float64;
break;
306 "Real view error: source tensor dtype must be complex64 or complex128");
309 if (
source.strides()[-1] == 1) {
317 throw Exception(
"Real view error: source tensor is not in interleaved real/imag format");
401template<Expression Real>
425template<Expression Real, Expression Imaginary>
426constexpr auto complex(Real&& real, Imaginary&& imaginary) {
428 std::forward<Real>(real),
429 std::forward<Imaginary>(imaginary)
452template<Expression Magnitude, Expression Angle>
453constexpr auto polar(Magnitude&& rho, Angle&& theta) {
455 std::forward<Magnitude>(rho),
456 std::forward<Angle>(theta)
485template<Expression Complex>
A simple generic exception type for the Tannic Tensor Library.
Definition: exceptions.hpp:44
Represents the shape (dimensions) of an tensor-like expression.
Definition: shape.hpp:79
constexpr void expand(size_type size)
Expands the shape's last dimension with a given size.
Definition: shape.hpp:286
Represents the memory strides associated with a tensor shape.
Definition: strides.hpp:87
constexpr void expand(size_type size)
Expands the strides's last dimension with a given size.
Definition: strides.hpp:267
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:99
Trait< Imaginary >::Reference imaginary
Definition: complex.hpp:192
std::ptrdiff_t offset() const
Returns the offset of the complex expression.
Definition: complex.hpp:250
constexpr Shape const & shape() const
Returns the shape of the complex tensor.
Definition: complex.hpp:230
constexpr Strides const & strides() const
Returns the strides of the complex tensor.
Definition: complex.hpp:242
Trait< Real >::Reference real
Definition: complex.hpp:191
constexpr Complexification(typename Trait< Real >::Reference real, typename Trait< Imaginary >::Reference imaginary)
Returns the complex dtype of the combined tensor.
Definition: complex.hpp:198
constexpr type dtype() const
Returns the complex dtype of the combined tensor.
Definition: complex.hpp:218
constexpr type dtype() const
Returns the complex dtype of the view.
Definition: complex.hpp:131
constexpr Strides const & strides() const
Returns the strides of the complex view.
Definition: complex.hpp:165
Trait< Source >::Reference source
Definition: complex.hpp:92
std::ptrdiff_t offset() const
Returns the offset of the view.
Definition: complex.hpp:175
constexpr Complexification(Trait< Source >::Reference source)
Constructs complex view from interleaved data.
Definition: complex.hpp:98
constexpr Shape const & shape() const
Returns the shape of the complex view.
Definition: complex.hpp:151
Creates a complex tensor view from real components.
Definition: complex.hpp:86
Creates a real-valued view of complex tensor data.
Definition: complex.hpp:290
constexpr Shape const & shape() const
Returns the shape of the real view.
Definition: complex.hpp:351
constexpr type dtype() const
Returns the real dtype of the view.
Definition: complex.hpp:331
constexpr Realification(Trait< Source >::Reference source)
Definition: complex.hpp:298
Trait< Source >::Reference source
Definition: complex.hpp:292
std::ptrdiff_t offset() const
Definition: complex.hpp:368
constexpr Strides const & strides() const
Returns the strides of the real view.
Definition: complex.hpp:364
Tensor forward() const
Definition: tensor.hpp:1264
Defines the core protocol for all expression-like types in the Tannic Tensor Library.
Definition: concepts.hpp:86
Definition: comparisons.hpp:69
constexpr auto realify(Complex &&complex)
Creates a real-valued view of complex tensor data.
Definition: complex.hpp:486
constexpr auto complex(Real &&real, Imaginary &&imaginary)
Creates complex tensor from separate real and imaginary tensors
Definition: complex.hpp:426
constexpr auto polar(Magnitude &&rho, Angle &&theta)
Creates complex tensor from polar coordinates (magnitude/angle)
Definition: complex.hpp:453
constexpr auto complexify(Real &&real)
Creates a complex tensor view from interleaved real/imaginary data.
Definition: complex.hpp:402
Definition: buffer.hpp:41
std::decay_t< T > Reference
Definition: traits.hpp:28
Tag type for Cartesian (real/imaginary) complex number representation.
Definition: complex.hpp:57
static void forward(Tensor const &, Tensor const &, Tensor &)
Tag type for Polar (magnitude/angle) complex number representation.
Definition: complex.hpp:68
static void forward(Tensor const &, Tensor const &, Tensor &)