1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Convenience macros for the TenfloweRS framework.
//!
//! This module provides macros that simplify common tensor construction patterns,
//! reducing boilerplate and improving ergonomics when working with tensors.
/// Creates a 1D \[`Tensor`\] from a list of values.
///
/// This macro accepts a comma-separated list of values and produces a 1D tensor
/// by delegating to [`tenflowers_core::Tensor::from_data`]. The element type is
/// inferred from the values; an explicit type suffix (e.g. `1.0f32`) may be used
/// to disambiguate.
///
/// # Examples
///
/// ```rust
/// use tenflowers::tensor;
/// use tenflowers::prelude::Tensor;
///
/// let t = tensor![1.0f32, 2.0, 3.0];
/// assert_eq!(t.shape().dims(), &[3]);
/// ```
///
/// ```rust
/// use tenflowers::tensor;
/// use tenflowers::prelude::Tensor;
///
/// let t = tensor![0i32, 1, 2, 3, 4];
/// assert_eq!(t.shape().dims(), &[5]);
/// ```
///
/// # Errors
///
/// Because the underlying \[`Tensor::from_data`\] call validates the shape, the
/// macro **panics** on a length/shape mismatch — but since the shape is derived
/// directly from the supplied values this cannot happen in practice.