Skip to main content

srange

Macro srange 

Source
macro_rules! srange {
    ($size: expr, $shape: expr) => { ... };
    ($start: expr, $end: expr, $shape: expr) => { ... };
    ($start: expr, $end: expr, $step: expr, $shape: expr) => { ... };
}
Expand description

Build a tensor of evenly spaced values and reshape it in one step.

Like arange!, but takes a target shape as the final argument and lays the values out row-major into it. Panics if the number of values doesn’t equal the product of shape.

  • srange!(size, shape) - values 0..size, reshaped to shape.
  • srange!(start, end, shape) - values start..end, reshaped to shape.
  • srange!(start, end, step, shape) - values start..end by step, reshaped to shape.

§Examples

use candela::{srange, Dimension, Tensor};
let t: Tensor<f64> = srange![6, &[2, 3]];
assert_eq!(t.shape(), &[2, 3]);
assert_eq!(t.data(), &[0.0, 1.0, 2.0, 3.0, 4.0, 5.0]);