Browse Source

tf.state

tags/v0.12
Oceania2018 6 years ago
parent
commit
d9c5cc0078
5 changed files with 45 additions and 4 deletions
  1. +7
    -0
      src/TensorFlowNET.Core/APIs/tf.control.cs
  2. +25
    -0
      src/TensorFlowNET.Core/APIs/tf.state.cs
  3. +4
    -0
      src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs
  4. +1
    -1
      src/TensorFlowNET.Core/Variables/gen_state_ops.py.cs
  5. +8
    -3
      src/TensorFlowNET.Core/Variables/state_ops.cs

+ 7
- 0
src/TensorFlowNET.Core/APIs/tf.control.cs View File

@@ -20,6 +20,13 @@ namespace Tensorflow
{
public partial class tensorflow
{
public Tensor cond(Tensor pred,
Func<ITensorOrOperation> true_fn = null,
Func<ITensorOrOperation> false_fn = null,
bool strict = false,
string name = null)
=> control_flow_ops.cond(pred, true_fn, false_fn, strict: strict, name: name);

public Tensor while_loop(Func<Tensor, Tensor> cond, Func<Tensor, Tensor> body, Tensor[] loop_vars,
TensorShape shape_invariants = null,
int parallel_iterations = 10,


+ 25
- 0
src/TensorFlowNET.Core/APIs/tf.state.cs View File

@@ -0,0 +1,25 @@
/*****************************************************************************
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.
******************************************************************************/

namespace Tensorflow
{
public partial class tensorflow
{
public Tensor assign_add<T>(RefVariable @ref, T value,
bool use_locking = false, string name = null)
=> state_ops.assign_add(@ref, value, use_locking: use_locking, name: name);
}
}

+ 4
- 0
src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs View File

@@ -29,6 +29,10 @@ namespace Tensorflow
public static Tensor operator -(RefVariable x, double y) => op_helper("sub", x, y);
public static Tensor operator -(RefVariable x, Tensor y) => op_helper("sub", x, y);

public static Tensor operator <(RefVariable x, Tensor y) => op_helper("Less", x, y);

public static Tensor operator >(RefVariable x, Tensor y) => op_helper("Greater", x, y);

private static Tensor op_helper<T>(string default_name, RefVariable x, T y)
{
var tensor1 = x.value();


+ 1
- 1
src/TensorFlowNET.Core/Variables/gen_state_ops.py.cs View File

@@ -126,7 +126,7 @@ namespace Tensorflow
// name: A name for the operation(optional).
// Returns:
// A mutable `Tensor`. Has the same type as `ref`.
public static Tensor assign_add(RefVariable @ref, Tensor value, bool use_locking = false, string name = null)
public static Tensor assign_add<T>(RefVariable @ref, T value, bool use_locking = false, string name = null)
{
var _op = _op_def_lib._apply_op_helper("AssignAdd", name: name, args: new { @ref, value, use_locking });
return _op.outputs[0];


+ 8
- 3
src/TensorFlowNET.Core/Variables/state_ops.cs View File

@@ -94,10 +94,15 @@ namespace Tensorflow
// Returns:
// Same as "ref". Returned as a convenience for operations that want
// to use the new value after the variable has been updated.
public static Tensor assign_add(RefVariable @ref,
Tensor value,
public static Tensor assign_add<T>(RefVariable @ref,
T value,
bool use_locking = false,
string name = null) => gen_state_ops.assign_add(@ref, value, use_locking: use_locking, name: name);
string name = null)
{
if (@ref.dtype.is_ref_dtype())
return gen_state_ops.assign_add(@ref, value, use_locking: use_locking, name: name);
throw new NotImplementedException("assign_add");
}
public static Tensor scatter_add(RefVariable @ref, Tensor indices, Tensor updates, bool use_locking = false, string name = null)
{


Loading…
Cancel
Save