TensorComplexRealPrims

Trait TensorComplexRealPrims 

Source
pub trait TensorComplexRealPrims<Input: ComplexFloat + Scalar> {
    type Real: Scalar + Send + Sync;
    type Plan;
    type Context;

    // Required methods
    fn plan(
        ctx: &mut Self::Context,
        desc: &ComplexRealPrimsDescriptor,
        shapes: &[&[usize]],
    ) -> Result<Self::Plan>;
    fn execute(
        ctx: &mut Self::Context,
        plan: &Self::Plan,
        alpha: Input::Real,
        inputs: &[&Tensor<Input>],
        beta: Input::Real,
        output: &mut Tensor<Self::Real>,
    ) -> Result<()>;
    fn has_complex_real_support(desc: ComplexRealPrimsDescriptor) -> bool;
}
Expand description

Cross-dtype complex-to-real unary protocol family.

The input tensor is complex-valued and the output tensor is real-valued.

§Examples

use num_complex::Complex64;
use tenferro_prims::{
    ComplexRealPrimsDescriptor, ComplexRealUnaryOp, CpuBackend, CpuContext,
    TensorComplexRealPrims,
};

let mut ctx = CpuContext::new(1);
let desc = ComplexRealPrimsDescriptor::PointwiseUnary {
    op: ComplexRealUnaryOp::Abs,
};
let _plan = <CpuBackend as TensorComplexRealPrims<Complex64>>::plan(
    &mut ctx,
    &desc,
    &[&[2, 2], &[2, 2]],
)
.unwrap();

Required Associated Types§

Source

type Real: Scalar + Send + Sync

The real-valued output scalar type.

Source

type Plan

Backend plan type.

Source

type Context

Backend execution context.

Required Methods§

Source

fn plan( ctx: &mut Self::Context, desc: &ComplexRealPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a complex-to-real unary operation for the given input/output shapes.

Source

fn execute( ctx: &mut Self::Context, plan: &Self::Plan, alpha: Input::Real, inputs: &[&Tensor<Input>], beta: Input::Real, output: &mut Tensor<Self::Real>, ) -> Result<()>

Execute a previously planned complex-to-real unary operation.

The execution contract matches the rest of tenferro prims: output <- alpha * op(inputs) + beta * output.

Source

fn has_complex_real_support(desc: ComplexRealPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Input> TensorComplexRealPrims<Input> for CpuBackend
where Input: ComplexFloat + Scalar + 'static, Input::Real: CpuScalarValue + Float,

Source§

type Real = <Input as ComplexFloat>::Real

Source§

type Plan = CpuComplexRealPlan

Source§

type Context = CpuContext

Source§

impl<Input> TensorComplexRealPrims<Input> for CudaBackend
where Input: ComplexFloat + Scalar, Input::Real: Scalar,

Available on non-crate feature cuda only.
Source§

impl<Input> TensorComplexRealPrims<Input> for RocmBackend
where Input: ComplexFloat + Scalar, Input::Real: Scalar,