From acb55057bc05c2ce9ab42769d504cd4ed91a8a73 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Tue, 17 Sep 2019 15:49:18 -0500 Subject: [PATCH] tf.ones_like, tf.not_equal, tf.floordiv, tf.zeros_like, tf.truediv, tf.add_n, tf.reduced_all, tf.dynamic_stitch --- src/TensorFlowNET.Core/APIs/tf.array.cs | 25 +++++++++++ src/TensorFlowNET.Core/APIs/tf.data_flow.cs | 33 ++++++++++++++ src/TensorFlowNET.Core/APIs/tf.math.cs | 50 +++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 src/TensorFlowNET.Core/APIs/tf.data_flow.cs diff --git a/src/TensorFlowNET.Core/APIs/tf.array.cs b/src/TensorFlowNET.Core/APIs/tf.array.cs index aca13ed1..4d0a43df 100644 --- a/src/TensorFlowNET.Core/APIs/tf.array.cs +++ b/src/TensorFlowNET.Core/APIs/tf.array.cs @@ -128,6 +128,20 @@ namespace Tensorflow public Tensor stack(object values, int axis = 0, string name = "stack") => array_ops.stack(values, axis, name: name); + /// + /// Creates a tensor with all elements set to 1. + /// + /// + /// + /// A name for the operation (optional). + /// + /// if true, attempt to statically determine the shape of 'tensor' and + /// encode it as a constant. + /// + /// A `Tensor` with all elements set to 1. + public Tensor ones_like(Tensor tensor, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool optimize = true) + => array_ops.ones_like(tensor, dtype: dtype, name: name, optimize: optimize); + public Tensor one_hot(Tensor indices, int depth, Tensor on_value = null, Tensor off_value = null, @@ -191,5 +205,16 @@ namespace Tensorflow /// public Tensor[] unstack(Tensor value, int? num = null, int axis = 0, string name = "unstack") => array_ops.unstack(value, num: num, axis: axis, name: name); + + /// + /// Creates a tensor with all elements set to zero. + /// + /// + /// + /// + /// + /// A `Tensor` with all elements set to zero. + public Tensor zeros_like(Tensor tensor, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool optimize = true) + => array_ops.zeros_like(tensor, dtype: dtype, name: name, optimize: optimize); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.data_flow.cs b/src/TensorFlowNET.Core/APIs/tf.data_flow.cs new file mode 100644 index 00000000..593596ff --- /dev/null +++ b/src/TensorFlowNET.Core/APIs/tf.data_flow.cs @@ -0,0 +1,33 @@ +/***************************************************************************** + Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +******************************************************************************/ + +using System; + +namespace Tensorflow +{ + public partial class tensorflow + { + /// + /// Interleave the values from the data tensors into a single tensor. + /// + /// + /// + /// + /// + public static Tensor dynamic_stitch(Tensor[] indices, Tensor[] data, string name = null) + => gen_data_flow_ops.dynamic_stitch(indices, data, name: name); + } +} diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index 985e3f73..b89ab310 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -44,6 +44,15 @@ namespace Tensorflow public Tensor add(Tx a, Ty b, string name = null) => gen_math_ops.add(a, b, name: name); + /// + /// Adds all input tensors element-wise. + /// + /// + /// + /// A `Tensor` of same shape and type as the elements of `inputs`. + public Tensor add_n(Tensor[] inputs, string name = null) + => math_ops.add_n(inputs, name: name); + /// /// Computes atan of x element-wise. /// @@ -331,6 +340,16 @@ namespace Tensorflow public Tensor negative(Tensor x, string name = null) => gen_math_ops.neg(x, name); + /// + /// Returns the truth value of (x != y) element-wise. + /// + /// + /// + /// + /// A `Tensor` of type bool with the same size as that of x or y. + public Tensor not_equal(Tx x, Ty y, string name = null) + => math_ops.not_equal(x, y, name: name); + /// /// Divides x / y elementwise (using Python 2 division operator semantics). /// @@ -347,9 +366,40 @@ namespace Tensorflow public Tensor pow(T1 x, T2 y) => gen_math_ops.pow(x, y); + /// + /// Divides `x / y` elementwise, rounding toward the most negative integer. + /// + /// + /// + /// + /// `x / y` rounded down. + public Tensor floordiv(Tensor x, Tensor y, string name = null) + => math_ops.floordiv(x, y, name: name); + + /// + /// Divides x / y elementwise (using Python 3 division operator semantics). + /// + /// + /// + /// + /// `x / y` evaluated in floating point. + public static Tensor truediv(Tensor x, Tensor y, string name = null) + => math_ops.truediv(x, y, name: name); + 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); + /// + /// Computes the "logical and" of elements across dimensions of a tensor. + /// + /// + /// + /// + /// + /// The reduced tensor. + public Tensor reduce_all(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) + => math_ops.reduce_all(input_tensor, axis: axis, keepdims: keepdims, name: name); + /// /// Computes the sum of elements across dimensions of a tensor. ///