/// <summary> /// Evaluates the specified write target. /// </summary> /// <param name="writeTarget">The write target.</param> /// <returns>Tensor.</returns> public override NDArray Evaluate(NDArray writeTarget) { using (var s = src.Evaluate(null)) using (var i = indices.Evaluate(null)) { if (!writeTarget.Equals(s)) { Ops.Copy(writeTarget, s); } Ops.ScatterFill(writeTarget, value.Evaluate(), dimension, i); } return(writeTarget); }
/// <summary> /// Randoms the cauchy. /// </summary> /// <param name="seedSource">The seed source.</param> /// <param name="median">The median.</param> /// <param name="sigma">The sigma.</param> /// <param name="allocator">The allocator.</param> /// <param name="type">The type.</param> /// <param name="sizes">The sizes.</param> /// <returns>TVar.</returns> public static Variable RandomCauchy(SeedSource seedSource, ScalarVar median, ScalarVar sigma, IAllocator allocator, DType type, params long[] sizes) { return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomCauchy(res, seedSource, median.Evaluate(), sigma.Evaluate())))); }
/// <summary> /// Randoms the exponential. /// </summary> /// <param name="seedSource">The seed source.</param> /// <param name="lambda">The lambda.</param> /// <param name="allocator">The allocator.</param> /// <param name="type">The type.</param> /// <param name="sizes">The sizes.</param> /// <returns>TVar.</returns> public static Variable RandomExponential(SeedSource seedSource, ScalarVar lambda, IAllocator allocator, DType type, params long[] sizes) { return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomExponential(res, seedSource, lambda.Evaluate())))); }
/// <summary> /// Randoms the normal. /// </summary> /// <param name="seedSource">The seed source.</param> /// <param name="mean">The mean.</param> /// <param name="stdv">The STDV.</param> /// <param name="allocator">The allocator.</param> /// <param name="type">The type.</param> /// <param name="sizes">The sizes.</param> /// <returns>TVar.</returns> public static Variable RandomNormal(SeedSource seedSource, ScalarVar mean, ScalarVar stdv, IAllocator allocator, DType type, params long[] sizes) { return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomNormal(res, seedSource, mean.Evaluate(), stdv.Evaluate())))); }
/// <summary> /// Randoms the uniform. /// </summary> /// <param name="seedSource">The seed source.</param> /// <param name="min">The minimum.</param> /// <param name="max">The maximum.</param> /// <param name="allocator">The allocator.</param> /// <param name="type">The type.</param> /// <param name="sizes">The sizes.</param> /// <returns>TVar.</returns> public static Variable RandomUniform(SeedSource seedSource, ScalarVar min, ScalarVar max, IAllocator allocator, DType type, params long[] sizes) { return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomUniform(res, seedSource, min.Evaluate(), max.Evaluate())))); }
/// <summary> /// Lerps the specified a. /// </summary> /// <param name="a">a.</param> /// <param name="b">The b.</param> /// <param name="weight">The weight.</param> /// <returns>TVar.</returns> public static Variable Lerp(Variable a, Variable b, ScalarVar weight) { return(new Variable(new BinaryTensorTensorExpression(a.Expression, b.Expression, (res, aVal, bVal) => Ops.Lerp(res, aVal, bVal, weight.Evaluate())))); }
/// <summary> /// Clamps the specified minimum. /// </summary> /// <param name="min">The minimum.</param> /// <param name="max">The maximum.</param> /// <returns>TVar.</returns> public Variable Clamp(ScalarVar min, ScalarVar max) { return(new Variable(new UnaryTensorExpression(this.Expression, (res, src) => Ops.Clamp(res, src, min.Evaluate(), max.Evaluate())))); }
/// <summary> /// Fills the specified value. /// </summary> /// <param name="value">The value.</param> /// <param name="allocator">The allocator.</param> /// <param name="type">The type.</param> /// <param name="sizes">The sizes.</param> /// <returns>TVar.</returns> public static Variable Fill(ScalarVar value, IAllocator allocator, DType type, params long[] sizes) { return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.Fill(res, value.Evaluate())))); }
/// <summary> /// Randoms the bernoulli. /// </summary> /// <param name="seedSource">The seed source.</param> /// <param name="p">The p.</param> /// <param name="allocator">The allocator.</param> /// <param name="type">The type.</param> /// <param name="sizes">The sizes.</param> /// <returns>TVar.</returns> public static Variable RandomBernoulli(SeedSource seedSource, ScalarVar p, IAllocator allocator, DType type, params long[] sizes) { return(new Variable(new FillExpression(allocator, type, sizes, res => Ops.RandomBernoulli(res, seedSource, p.Evaluate())))); }
/// <summary> /// Lerps the specified a. /// </summary> /// <param name="a">a.</param> /// <param name="b">The b.</param> /// <param name="weight">The weight.</param> /// <returns>SVar.</returns> public static ScalarVar Lerp(ScalarVar a, ScalarVar b, ScalarVar weight) { return(new ScalarVar(new DelegateScalarExpression(() => (float)LerpFloat(a.Evaluate(), b.Evaluate(), weight.Evaluate())))); }
/// <summary> /// Atan2s the specified y. /// </summary> /// <param name="y">The y.</param> /// <param name="x">The x.</param> /// <returns>SVar.</returns> public static ScalarVar Atan2(ScalarVar y, ScalarVar x) { return(new ScalarVar(new DelegateScalarExpression(() => (float)Math.Atan2(y.Evaluate(), x.Evaluate())))); }