Skip to main content

shape

Macro shape 

Source
macro_rules! shape {
    ($dtype:ident; $($rest:tt)+) => { ... };
    ($($rest:tt)+) => { ... };
}
Expand description

Build a Shape. Default dtype is F32.

Each static dimension may be any usize expression — a literal, an identifier, or arithmetic like w / 2, w + heads, cfg.width * 2 — so graph builders can size params/inputs from computed dimensions directly (no need to hoist every derived size into a let). Dynamic dimensions use ? → symbol 0 (repeat ? for the same unknown size), ?1 → symbol 1, etc. A leading Dtype; sets the element type (default F32).

use rlx_tensor::{shape, DType};

let a = shape![2, 4];
let b = shape![F32; ?, 128];
let w = 64usize;
let c = shape![w + 1, w / 2, 3 * w];   // computed dimensions
assert_eq!(c.dtype(), DType::F32);
assert!(c.is_static());
assert!(!b.is_static());