C.Function get_length_and_remove_last_dimension(C.Function x, string name) { var number_dimensions = x.Output.Shape.Dimensions.Count; x = CC.Square(x); var sum_entries = CC.ReduceSum(x, new C.Axis(number_dimensions - 1)); var epsilon = C.Constant.Scalar(C.DataType.Float, 1e-7, computeDevice); x = CC.Sqrt(CC.Plus(sum_entries, epsilon)); x = CC.Squeeze(x); return(x); }
C.Function squash(C.Function vectors, string name, int axis) { var squared_values = CC.Square(vectors); var s_squared_sum = CC.ReduceSum(squared_values, new C.AxisVector(new C.Axis[] { new C.Axis(axis) }), keepDims: true); var epsilon = C.Constant.Scalar(C.DataType.Float, 1e-7, computeDevice); var one = C.Constant.Scalar(C.DataType.Float, 1.0, computeDevice); var normalize_factor = CC.Plus(CC.Sqrt(s_squared_sum), epsilon); var one_plus_s_squared_sum = CC.Plus(s_squared_sum, one); var scale = CC.ElementDivide(s_squared_sum, one_plus_s_squared_sum); scale = CC.ElementDivide(scale, normalize_factor); var result = CC.ElementTimes(scale, vectors, name); return(result); }
C.Function get_mask_and_infer_from_last_dimension(C.Function inputs, C.Function mask) { if (mask == null) { var inputs_shape = inputs.Output.Shape.Dimensions.ToArray(); var ndims = inputs_shape.Length - 1; var x = CC.Sqrt(CC.ReduceSum(CC.Square(inputs), new C.Axis(ndims - 1))); x = CC.Squeeze(x); System.Diagnostics.Debug.Assert(x.Output.Shape.Dimensions.Count == 1); x = CC.Argmax(x, new C.Axis(0)); mask = CC.OneHotOp(x, numClass: (uint)inputs_shape[0], outputSparse: false, axis: new C.Axis(0)); } mask = CC.Reshape(mask, mask.Output.Shape.AppendShape(new int[] { 1 })); var masked = CC.ElementTimes(inputs, mask); masked = CC.Flatten(masked); masked = CC.Squeeze(masked); return(masked); }
public Tensor sqrt(Tensor x) { return(Out(C.Sqrt(In(x)))); }
public Tensor sqrt(Tensor x) { log(new { x }); return(Out(C.Sqrt(In(x)))); }