Function tensorflow::ops::constant

source ·
pub fn constant<T: TensorType, TT: Into<Tensor<T>>>(
    value: TT,
    scope: &mut Scope
) -> Result<Operation>
Expand description

Creates a constant.

The value can be anything convertible to a tensor, so possibilities include:

let a = constant(1.0f32, &mut scope)?;
let b = constant(&[1.0f32, 2.0][..], &mut scope)?;
let c = constant(Tensor::new(&[2, 2]).with_values(&[0f32, 1.0, 2.0, 3.0])?, &mut scope)?;

Note that e.g. &[1, 2][..] is used instead of &[1, 2]. This forces the compiler to treat the value as a slice rather than a reference to a fixed-size array. This is necessary because Into<Tensor> is implemented for slices but not arrays, and the compiler doesn’t automatically fall back to treating the array reference as a slice.