Skip to content

Commit f9959ef

Browse files
committed
Chagne return type to Tensor for assign_add.
1 parent d1503ca commit f9959ef

7 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/TensorFlowNET.Core/APIs/tf.nn.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,7 @@ public Tensor sigmoid_cross_entropy_with_logits(Tensor labels, Tensor logits, st
182182
=> nn_impl.sigmoid_cross_entropy_with_logits(labels: labels, logits: logits, name: name);
183183

184184
public Tensor softmax(Tensor logits, int axis = -1, string name = null)
185-
{
186-
if (axis == -1)
187-
return gen_nn_ops.softmax(logits, name);
188-
else
189-
throw new NotImplementedException("");
190-
}
185+
=> gen_nn_ops.softmax(logits, name);
191186

192187

193188
/// <summary>

src/TensorFlowNET.Core/APIs/tf.train.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public Optimizer AdamOptimizer(float learning_rate, float epsilon = 1e-8f, strin
4444
public Optimizer AdamOptimizer(float learning_rate, TF_DataType dtype, string name = "Adam")
4545
=> new AdamOptimizer(learning_rate, name: name, dtype: dtype);
4646

47+
public Optimizer AdamOptimizer(IVariableV1 learning_rate, string name = "Adam")
48+
=> new AdamOptimizer(learning_rate.AsTensor(), name: name);
49+
4750
public Optimizer AdamOptimizer(Tensor learning_rate, string name = "Adam")
4851
=> new AdamOptimizer(learning_rate, name: name);
4952

src/TensorFlowNET.Core/Training/Optimizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public Operation apply_gradients(Tuple<Tensor, IVariableV1>[] grads_and_vars, IV
207207
{
208208
apply_updates = state_ops.assign_add(global_step,
209209
ops.convert_to_tensor(1, dtype: global_step.dtype),
210-
name: name) as Operation;
210+
name: name);
211211
}
212212
});
213213
}

src/TensorFlowNET.Core/Variables/BaseResourceVariable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void __init__(bool trainable = true,
7373
// handle_deleter
7474
}
7575

76-
public ITensorOrOperation assign<T>(T value, bool use_locking = false, string name = null, bool read_value = true)
76+
public Tensor assign<T>(T value, bool use_locking = false, string name = null, bool read_value = true)
7777
{
7878
if(value.GetType() == typeof(Tensor))
7979
{
@@ -134,7 +134,7 @@ Tensor read_value()
134134
return array_ops.identity(value);
135135
});
136136

137-
public ITensorOrOperation assign_add<T>(T delta, bool use_locking = false, string name = null, bool read_value = true)
137+
public Tensor assign_add<T>(T delta, bool use_locking = false, string name = null, bool read_value = true)
138138
{
139139
var assign_add_op = gen_resource_variable_ops.assign_add_variable_op(Handle,
140140
ops.convert_to_tensor(delta, dtype: dtype), name: name);

src/TensorFlowNET.Core/Variables/IVariableV1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public interface IVariableV1
4747
public Graph Graph { get; }
4848
public TF_DataType dtype { get; }
4949
public TensorShape shape { get; }
50-
ITensorOrOperation assign_add<T>(T delta, bool use_locking = false, string name = null, bool read_value = true);
51-
ITensorOrOperation assign<T>(T value, bool use_locking = false, string name = null, bool read_value = true);
50+
Tensor assign_add<T>(T delta, bool use_locking = false, string name = null, bool read_value = true);
51+
Tensor assign<T>(T value, bool use_locking = false, string name = null, bool read_value = true);
5252
Tensor AsTensor();
5353
}
5454
}

src/TensorFlowNET.Core/Variables/RefVariable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private Operation _find_initialized_value_for_variable(Operation variable_op)
335335
/// A `Tensor` that will hold the new value of this variable after
336336
/// the assignment has completed.
337337
/// </returns>
338-
public ITensorOrOperation assign<T>(T value, bool use_locking = false, string name = null, bool read_value = true)
338+
public Tensor assign<T>(T value, bool use_locking = false, string name = null, bool read_value = true)
339339
{
340340
var assign = gen_state_ops.assign(_variable, value, use_locking: use_locking, name: name);
341341
if (read_value)
@@ -418,7 +418,7 @@ public Tensor initialized_value()
418418
// name: A name for the operation(optional).
419419
// Returns:
420420
// A mutable `Tensor`. Has the same type as `ref`.
421-
public ITensorOrOperation assign_add<T>(T value, bool use_locking = false, string name = null, bool read_value = true)
421+
public Tensor assign_add<T>(T value, bool use_locking = false, string name = null, bool read_value = true)
422422
{
423423
var variable = this;
424424
var _op = tf.OpDefLib._apply_op_helper("AssignAdd", name: name, args: new { variable, value, use_locking });

src/TensorFlowNET.Core/Variables/state_ops.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static Tensor assign_sub(IVariableV1 @ref,
9595
// Returns:
9696
// Same as "ref". Returned as a convenience for operations that want
9797
// to use the new value after the variable has been updated.
98-
public static ITensorOrOperation assign_add<T>(IVariableV1 @ref,
98+
public static Tensor assign_add<T>(IVariableV1 @ref,
9999
T value,
100100
bool use_locking = false,
101101
string name = null)

0 commit comments

Comments
 (0)