Skip to main content

GraphScope

Struct GraphScope 

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

Owns a traced graph while you build symbolic tensors.

Implementations§

Source§

impl GraphScope

Source

pub fn new(name: impl Into<String>) -> Self

Source

pub fn graph(&self) -> Graph

Source

pub fn fresh_symbol(&mut self) -> u32

Fresh dynamic-dimension symbol (for variable batch / sequence length).

Source

pub fn input( &mut self, name: impl Into<String>, shape: impl Into<Shape>, ) -> Tensor

Source

pub fn input_dyn( &mut self, name: impl Into<String>, dims: &[Dim], dtype: DType, ) -> Tensor

Input with a caller-chosen dynamic symbol on one axis.

Source

pub fn param( &mut self, name: impl Into<String>, shape: impl Into<Shape>, ) -> Tensor

Source

pub fn scalar(&mut self, value: f64) -> Tensor

Rank-0 literal broadcastable in binary ops.

Source

pub fn constant(&mut self, value: f64, dtype: DType) -> Tensor

Source

pub fn constant_nd( &mut self, data: Vec<f64>, dims: Vec<usize>, dtype: DType, ) -> Tensor

Materialize an N-dimensional constant tensor from row-major data (given as f64, encoded to dtype’s element width). Backs the rlx! array-const form (const mask = [[0,1],[1,0]] : F32;). data.len() must equal the product of dims. Supports F32/F64/I32/I64.

Source

pub fn scan_block( &mut self, init: &Tensor, bcasts: &[&Tensor], length: u32, body: impl FnOnce(&Tensor, &[Tensor]) -> Tensor, ) -> Tensor

Build a bounded sequential scan (Op::Scan) — a single compact loop node, not an unrolled copy. init is the loop carry; bcasts are values held constant across iterations (typically weights); length is the iteration count. body(carry, bcasts) -> next_carry is traced ONCE into a standalone body graph, so the result is O(1) IR regardless of length (unlike an unrolled repeat). The next carry must match the carry’s shape. Backs the rlx! scan construct.

use rlx_tensor::{graph, shape};
let g = graph("rnn", |s| {
    let h0 = s.input("h0", shape![1, 8]);
    let w  = s.param("w", shape![8, 8]);
    s.scan_block(&h0, &[&w], 12, |h, bc| (h.matmul(&bc[0])).tanh())
});
assert_eq!(g.outputs.len(), 1);
Source

pub fn cat(&mut self, tensors: &[&Tensor], axis: usize) -> Tensor

Stack existing tensors along axis (zero-copy at IR level).

Source

pub fn set_outputs( &mut self, outputs: impl IntoIterator<Item = impl Into<NodeId>>, )

Source

pub fn finish(self) -> Graph

Trait Implementations§

Source§

impl Debug for GraphScope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.