Skip to main content

CustomOpRegistry

Struct CustomOpRegistry 

Source
pub struct CustomOpRegistry { /* private fields */ }
Expand description

Registry for custom operations.

Implementations§

Source§

impl CustomOpRegistry

Source

pub fn new() -> Self

Create a new registry.

Source

pub fn register( &mut self, name: impl Into<String>, metadata: CustomOpMetadata, handler: CustomOpHandler, ) -> Result<()>

Register a custom operation.

§Examples
use tensorlogic_compiler::compile::CustomOpRegistry;
use tensorlogic_compiler::compile::CustomOpMetadata;
use std::sync::Arc;

let mut registry = CustomOpRegistry::new();

let metadata = CustomOpMetadata {
    name: "custom_and".to_string(),
    description: "Custom AND with threshold".to_string(),
    expected_arity: Some(2),
    is_differentiable: true,
};

registry.register(
    "custom_and",
    metadata,
    Arc::new(|expr, ctx, graph, data| {
        // Custom compilation logic here
        Ok(0)
    }),
).unwrap();
Source

pub fn unregister(&mut self, name: &str) -> Result<()>

Unregister a custom operation.

Source

pub fn has_operation(&self, name: &str) -> bool

Check if an operation is registered.

Source

pub fn get_metadata(&self, name: &str) -> Option<CustomOpMetadata>

Get metadata for an operation.

Source

pub fn list_operations(&self) -> Vec<String>

List all registered operations.

Source

pub fn invoke( &self, name: &str, expr: &TLExpr, ctx: &mut CompilerContext, graph: &mut EinsumGraph, data: &CustomOpData, ) -> Result<usize>

Invoke a custom operation.

Trait Implementations§

Source§

impl Default for CustomOpRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.