Procs
proc complex[T: SomeNumber](re: Tensor[T]): auto {.inline, noinit.}
-
Create a new, complex Tensor from a single real Tensor
The input Tensor is copied into the real part of the output Tensor, while the imaginary part is set to all zeros.
If the input is an integer Tensor, the output will be a Tensor of Complex64 to avoid any loss of precision. If you want to convert it into a Tensor of Complex32, you can use .asType(Complex32) instead.
Note that you can also convert a real tensor into a complex tensor by means of the asType procedure. However, this has the advantage that you can use the same function to combine a real and imaginary tensor or a single real tensor into a complex tensor. Another advantage is that this function will automatically use the right Complex type for the output tensor, leading to more generic code. Use asType only when you want to control the type of the Complex tensor.
Source Edit proc complex[T: SomeNumber](re: Tensor[T]; im: Tensor[T]): auto {.inline, noinit.}
-
Create a new, complex Tensor by combining two real Tensors
The first input Tensor is copied into the real part of the output Tensor, while the second input Tensor is copied into the imaginary part.
If the inputs are integer Tensors, the output will be a Tensor of Complex64 to avoid any loss of precision.
Source Edit proc complex_imag[T: SomeNumber](im: Tensor[T]): auto {.inline, noinit.}
-
Create a new, imaginary Tensor from a single real Tensor
The input Tensor is copied into the imaginary part of the output Tensor, while the real part is set to all zeros.
If the input is an integer Tensor, the output will be a Tensor of Complex64 to avoid any loss of precision. If you want to convert it into a Tensor of Complex32, you must convert the input to float32 first by using .asType(float32).
Source Edit