* implement math_ops.real, reduce_variance, reduce_std * add dtype.real_dtype() * add outward-facing api functionstags/v0.20
| @@ -422,6 +422,9 @@ namespace Tensorflow | |||||
| public Tensor range(object start, object limit = null, object delta = null, TF_DataType dtype = TF_DataType.DtInvalid, string name = "range") | public Tensor range(object start, object limit = null, object delta = null, TF_DataType dtype = TF_DataType.DtInvalid, string name = "range") | ||||
| => math_ops.range(start, limit: limit, delta: delta, dtype: dtype, name: name); | => math_ops.range(start, limit: limit, delta: delta, dtype: dtype, name: name); | ||||
| public Tensor real(Tensor input, string name = null) | |||||
| => math_ops.real(input, name); | |||||
| /// <summary> | /// <summary> | ||||
| /// Computes the "logical or" of elements across dimensions of a tensor. | /// Computes the "logical or" of elements across dimensions of a tensor. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -509,6 +512,12 @@ namespace Tensorflow | |||||
| public Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | public Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | ||||
| => math_ops.reduce_min(input_tensor, axis, keepdims, name); | => math_ops.reduce_min(input_tensor, axis, keepdims, name); | ||||
| public Tensor reduce_std(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | |||||
| => math_ops.reduce_std(input_tensor, axis, keepdims, name); | |||||
| public Tensor reduce_variance(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | |||||
| => math_ops.reduce_variance(input_tensor, axis, keepdims, name); | |||||
| public Tensor sigmoid<T>(T x, string name = null) | public Tensor sigmoid<T>(T x, string name = null) | ||||
| => math_ops.sigmoid(x, name: name); | => math_ops.sigmoid(x, name: name); | ||||
| @@ -229,6 +229,22 @@ namespace Tensorflow | |||||
| public static Tensor mul_no_nan<Tx, Ty>(Tx x, Ty y, string name = null) | public static Tensor mul_no_nan<Tx, Ty>(Tx x, Ty y, string name = null) | ||||
| => gen_math_ops.mul_no_nan(x, y, name: name); | => gen_math_ops.mul_no_nan(x, y, name: name); | ||||
| public static Tensor real(Tensor input, string name = null) | |||||
| { | |||||
| using (var name_ = ops.name_scope(name, "Real", new [] {input})) | |||||
| { | |||||
| input = ops.convert_to_tensor(input, name: "input"); | |||||
| if (input.dtype.is_complex()) | |||||
| { | |||||
| var real_dtype = input.dtype.real_dtype(); | |||||
| return real(input, name: name); | |||||
| } else | |||||
| { | |||||
| return input; | |||||
| } | |||||
| } | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Computes the mean of elements across dimensions of a tensor. | /// Computes the mean of elements across dimensions of a tensor. | ||||
| @@ -295,6 +311,46 @@ namespace Tensorflow | |||||
| } | } | ||||
| } | } | ||||
| public static Tensor reduce_std(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | |||||
| { | |||||
| if (name == null) | |||||
| name = "reduce_std"; | |||||
| // else {name = name;} | |||||
| using (ops.name_scope(name)) | |||||
| { | |||||
| var variance = reduce_variance(input_tensor, axis: axis, keepdims: keepdims); | |||||
| return gen_math_ops.sqrt(variance); | |||||
| } | |||||
| } | |||||
| public static Tensor reduce_variance(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) | |||||
| { | |||||
| if (name == null) | |||||
| name = "reduce_variance"; | |||||
| // else {name = name;} | |||||
| using (ops.name_scope(name)) | |||||
| { | |||||
| var means = reduce_mean(input_tensor, axis: axis, keepdims: true); | |||||
| if (means.dtype.is_integer()) | |||||
| throw new TypeError("Input must be either real or complex"); | |||||
| var diff = input_tensor - means; | |||||
| Tensor squared_deviations; | |||||
| if (diff.dtype.is_complex()) | |||||
| { | |||||
| var real_dtype = diff.dtype.real_dtype(); | |||||
| squared_deviations = real( | |||||
| gen_math_ops.mul(conj(diff), diff)); | |||||
| } else | |||||
| { | |||||
| squared_deviations = gen_math_ops.square(diff); | |||||
| } | |||||
| return reduce_mean(squared_deviations, axis: axis, keepdims: keepdims); | |||||
| } | |||||
| } | |||||
| public static Tensor sigmoid<T>(T x, string name = null) | public static Tensor sigmoid<T>(T x, string name = null) | ||||
| => tf_with(ops.name_scope(name, "Sigmoid", x), scope => | => tf_with(ops.name_scope(name, "Sigmoid", x), scope => | ||||
| { | { | ||||
| @@ -278,5 +278,16 @@ namespace Tensorflow | |||||
| { | { | ||||
| return self.as_datatype_enum() == other.as_datatype_enum(); | return self.as_datatype_enum() == other.as_datatype_enum(); | ||||
| } | } | ||||
| public static TF_DataType real_dtype(this TF_DataType self) | |||||
| { | |||||
| TF_DataType base_ = self.as_base_dtype(); | |||||
| if (base_ == complex64) | |||||
| return float32; | |||||
| else if (base_ == complex128) | |||||
| return float64; | |||||
| else | |||||
| return self; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||