pub struct GraphScope { /* private fields */ }Expand description
Owns a traced graph while you build symbolic tensors.
Implementations§
Source§impl GraphScope
impl GraphScope
pub fn new(name: impl Into<String>) -> Self
pub fn graph(&self) -> Graph
Sourcepub fn fresh_symbol(&mut self) -> u32
pub fn fresh_symbol(&mut self) -> u32
Fresh dynamic-dimension symbol (for variable batch / sequence length).
pub fn input( &mut self, name: impl Into<String>, shape: impl Into<Shape>, ) -> Tensor
Sourcepub fn input_dyn(
&mut self,
name: impl Into<String>,
dims: &[Dim],
dtype: DType,
) -> Tensor
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.
pub fn param( &mut self, name: impl Into<String>, shape: impl Into<Shape>, ) -> Tensor
pub fn constant(&mut self, value: f64, dtype: DType) -> Tensor
Sourcepub fn constant_nd(
&mut self,
data: Vec<f64>,
dims: Vec<usize>,
dtype: DType,
) -> Tensor
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.
Sourcepub fn scan_block(
&mut self,
init: &Tensor,
bcasts: &[&Tensor],
length: u32,
body: impl FnOnce(&Tensor, &[Tensor]) -> Tensor,
) -> Tensor
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);Sourcepub fn cat(&mut self, tensors: &[&Tensor], axis: usize) -> Tensor
pub fn cat(&mut self, tensors: &[&Tensor], axis: usize) -> Tensor
Stack existing tensors along axis (zero-copy at IR level).
pub fn set_outputs( &mut self, outputs: impl IntoIterator<Item = impl Into<NodeId>>, )
pub fn finish(self) -> Graph
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for GraphScope
impl !Send for GraphScope
impl !Sync for GraphScope
impl !UnwindSafe for GraphScope
impl Freeze for GraphScope
impl Unpin for GraphScope
impl UnsafeUnpin for GraphScope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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