onesLike

  1. Tensor!(T, Shape, UseGradient.no) onesLike(Tensor!(T, Shape, useGradient) x)
  2. Tensor!(T, Shape, useGrad) onesLike(Tensor!(T, Shape, useGradient) x)
    Tensor!(T, Shape, useGrad)
    onesLike
    (
    UseGradient useGrad
    T
    size_t[] Shape
    UseGradient useGradient
    )
    (
    Tensor!(T, Shape, useGradient) x
    )

Examples

ditto

auto x = tensor!([2, 2])([1.0f, 2.0f, 3.0f, 4.0f]);
auto x1 = onesLike(x);

assert(x.shape == x1.shape);
assert(x1.value == ones!(float, [2, 2]).value);

ditto

auto x = tensor!([2, 3])([1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f]);
auto x1 = onesLike(x);

assert(x.shape == x1.shape);
assert(x1.value == ones!(float, [2, 3]).value);

ditto

auto x = tensor!([2, 3])([1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f]);
auto x1 = onesLike!(UseGradient.yes)(x);

static assert(canBackward!(typeof(x1)));

Meta