Skip to content

Commit ba499ab

Browse files
committed
have to invoke pywrap_tfe_src.cc
1 parent 126ed27 commit ba499ab

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,25 @@ public static Tensor pow(Tensor x, double y)
3535
public static Tensor reduce_sum(Tensor input, int[] axis = null)
3636
{
3737
Tensor rank;
38+
string name;
3839
using (var namescop = new ops.name_scope<Tensor>("", "Rank", new List<Tensor> { input }))
3940
{
40-
string name = namescop;
41-
rank = gen_array_ops.rank(input, name);
41+
name = namescop;
42+
rank = gen_array_ops.rank(input, namescop);
4243
}
44+
45+
using (var namescope = new ops.name_scope<Tensor>("range", "Range", new List<Tensor> { 0D, input, 1D }))
46+
{
47+
name = namescope;
48+
var start = ops.convert_to_tensor(0D);
49+
var limit = ops.convert_to_tensor(input);
50+
var delta = ops.convert_to_tensor(1D);
51+
52+
var t = gen_math_ops.range(start, limit, delta, name);
53+
}
54+
4355
var s = gen_math_ops.sum(input, rank);
44-
return gen_math_ops.range(0, s);
56+
return s;
4557
}
4658
}
4759
}

src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static void _GradientsHelper(object ys,
5757
// cluster ops for compilation.
5858
var gradient_uid = ops.get_default_graph().unique_name("uid");
5959

60+
// Initialize the pending count for ops in the connected subgraph from ys
61+
// to the xs.
6062
var to_ops = ys1.Select(x => x.op).ToList();
6163
var from_ops = xs1.Select(x => x.op).ToList();
6264
var stop_gradient_ops = stop_gradients1.Select(x => x.op).ToList();

src/TensorFlowNET.Core/Operations/Operation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public NodeDef GetNodeDef()
163163

164164
public override string ToString()
165165
{
166-
return $"'{Name}' type={OpType}";
166+
return _handle == IntPtr.Zero ? "Undefined" : $"'{Name}' type={OpType}";
167167
}
168168

169169
public static implicit operator Operation(IntPtr handle) => new Operation(handle);

src/TensorFlowNET.Core/Operations/gen_math_ops.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,16 @@ public static Tensor sum(Tensor input, Tensor axis = null)
9898
/// <param name="delta"></param>
9999
/// <param name="name"></param>
100100
/// <returns></returns>
101-
public static Tensor range(int start, Tensor limit, int delta = 1)
101+
public static Tensor range(Tensor start, Tensor limit, Tensor delta, string name = "")
102102
{
103-
using (var namescope = new ops.name_scope<Tensor>("", "Range", new List<Tensor> { start, limit, delta }))
104-
{
105-
var start1 = ops.convert_to_tensor(start, "start");
106-
var limit1 = ops.convert_to_tensor(limit, "limit");
107-
var delta1 = ops.convert_to_tensor(delta, "delta");
108-
109-
var keywords = new Dictionary<string, object>();
110-
keywords.Add("start", start1);
111-
keywords.Add("limit", limit1);
112-
keywords.Add("delta", delta1);
103+
var keywords = new Dictionary<string, object>();
104+
keywords.Add("start", start);
105+
keywords.Add("limit", limit);
106+
keywords.Add("delta", delta);
113107

114-
var _op = _op_def_lib._apply_op_helper("Range", namescope, keywords);
108+
var _op = _op_def_lib._apply_op_helper("Range", name, keywords);
115109

116-
return _op.outputs[0];
117-
}
110+
return _op.outputs[0];
118111
}
119112
}
120113
}

src/TensorFlowNET.Core/Variables/RefVariable.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ private void _init_from_args(object initial_value,
9191
_snapshot = gen_array_ops.identity(_variable, name = "read");
9292
}
9393

94-
// clear g._name_stack
95-
ops.get_default_graph().old_stack = "";
96-
9794
ops.add_to_collections(collections, this);
9895
}
9996
}

src/TensorFlowNET.Core/ops.name_scope.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public void Dispose()
4646
{
4747
var g = get_default_graph();
4848
g._name_stack = g.old_stack;
49+
// clear g._name_stack
50+
g.old_stack = "";
4951
}
5052

5153
/// <summary>
@@ -54,7 +56,10 @@ public void Dispose()
5456
/// <param name="ns"></param>
5557
public static implicit operator string(name_scope<T> ns)
5658
{
57-
return ns.__enter__();
59+
if (string.IsNullOrEmpty(ns._name_scope))
60+
return ns.__enter__();
61+
else
62+
return ns._name_scope;
5863
}
5964
}
6065
}

src/TensorFlowNET.Core/ops.py.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ public static Graph _get_graph_from_inputs(List<Tensor> op_input_list, Graph gra
4747

4848
public static Tensor convert_to_tensor(object value, string name = "")
4949
{
50-
var nd = tensor_util.convert_to_numpy_ndarray(value);
51-
return tf.constant(nd, name);
50+
switch (value)
51+
{
52+
case Tensor val:
53+
return val;
54+
default:
55+
var nd = tensor_util.convert_to_numpy_ndarray(value);
56+
return tf.constant(nd, name);
57+
}
5258
}
5359

5460
public static unsafe IntPtr _create_c_op(Graph graph, NodeDef node_def, List<Tensor> inputs)
@@ -90,7 +96,7 @@ public static unsafe IntPtr _create_c_op(Graph graph, NodeDef node_def, List<Ten
9096

9197
var c_op = c_api.TF_FinishOperation(op_desc, status);
9298

93-
if (status.Code != TF_Code.TF_OK) throw new Exception(status.Message);
99+
status.Check(true);
94100

95101
return c_op;
96102
}

0 commit comments

Comments
 (0)