Skip to content

Commit 9bc0c86

Browse files
committed
Attempting to use uninitialized value v1 SciSharp#172
1 parent d8f8a7f commit 9bc0c86

16 files changed

Lines changed: 48 additions & 44 deletions

File tree

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public static Tensor[] _GradientsHelper(Tensor[] ys,
9595
{
9696
// 'ready' handles the case where one output gradient relies on
9797
// another output's gradient.
98-
if (!pending_count.ContainsKey(op.Name))
99-
pending_count[op.Name] = 0;
100-
bool ready = pending_count[op.Name] == 0;
98+
if (!pending_count.ContainsKey(op.name))
99+
pending_count[op.name] = 0;
100+
bool ready = pending_count[op.name] == 0;
101101
if(ready && !to_ops_set.Contains(op) && reachable_to_ops.Contains(op))
102102
{
103103
to_ops_set.Add(op);
@@ -131,7 +131,7 @@ public static Tensor[] _GradientsHelper(Tensor[] ys,
131131
// for ops that do not have gradients.
132132
var grad_fn = ops.get_gradient_function(op);
133133

134-
Python.with<ops.name_scope>(new ops.name_scope(op.Name + "_grad"), scope1 =>
134+
Python.with<ops.name_scope>(new ops.name_scope(op.name + "_grad"), scope1 =>
135135
{
136136
string name1 = scope1;
137137
if (grad_fn != null)
@@ -193,12 +193,12 @@ private static void _UpdatePendingAndEnqueueReady(Dictionary<string, Tensor[][]>
193193
{
194194
foreach(var x in _NonEagerInputs(op, xs))
195195
{
196-
if (!pending_count.ContainsKey(x.op.Name))
197-
pending_count[x.op.Name] = 0;
196+
if (!pending_count.ContainsKey(x.op.name))
197+
pending_count[x.op.name] = 0;
198198

199-
pending_count[x.op.Name] -= 1;
199+
pending_count[x.op.name] -= 1;
200200

201-
var ready = pending_count[x.op.Name] == 0;
201+
var ready = pending_count[x.op.name] == 0;
202202

203203
if(loop_state != null && !ready)
204204
{
@@ -281,10 +281,10 @@ private static Operation[] _StopOps(List<Operation> from_ops, List<Operation> st
281281
bool is_stop_op = true;
282282
foreach(var inp in _NonEagerInputs(op, xs))
283283
{
284-
if (!pending_count.ContainsKey(inp.op.Name))
285-
pending_count[inp.op.Name] = 0;
284+
if (!pending_count.ContainsKey(inp.op.name))
285+
pending_count[inp.op.name] = 0;
286286

287-
if (pending_count[inp.op.Name] > 0)
287+
if (pending_count[inp.op.name] > 0)
288288
{
289289
is_stop_op = false;
290290
break;
@@ -300,17 +300,17 @@ private static Operation[] _StopOps(List<Operation> from_ops, List<Operation> st
300300
private static Tensor _GetGrad(Dictionary<string, Tensor[][]> grads, Tensor t)
301301
{
302302
var op = t.op;
303-
if (!grads.ContainsKey(op.Name))
303+
if (!grads.ContainsKey(op.name))
304304
return null;
305-
Tensor[][] op_grads = grads[op.Name];
305+
Tensor[][] op_grads = grads[op.name];
306306
var t_grad = op_grads[t.value_index];
307307
return t_grad[0];
308308
}
309309

310310
private static Tensor[][] _GetGrads(Dictionary<string, Tensor[][]> grads, Operation op)
311311
{
312-
if (grads.ContainsKey(op.Name))
313-
return grads[op.Name];
312+
if (grads.ContainsKey(op.name))
313+
return grads[op.name];
314314
else
315315
return op.outputs.Select(x => new Tensor[0]).ToArray();
316316
}
@@ -324,11 +324,11 @@ private static Tensor[][] _GetGrads(Dictionary<string, Tensor[][]> grads, Operat
324324
private static void _SetGrad(Dictionary<string, Tensor[][]> grads, Tensor t, Tensor grad)
325325
{
326326
var op = t.op;
327-
Tensor[][] op_grads = grads.ContainsKey(op.Name) ? grads[op.Name] : null;
327+
Tensor[][] op_grads = grads.ContainsKey(op.name) ? grads[op.name] : null;
328328
if (op_grads == null)
329329
{
330330
op_grads = op.outputs.Select(x => new Tensor[1]).ToArray();
331-
grads[op.Name] = op_grads;
331+
grads[op.name] = op_grads;
332332
}
333333
var t_grads = op_grads[t.value_index];
334334
t_grads[0] = grad;
@@ -421,10 +421,10 @@ private static (Operation[], Dictionary<string, int>, object) _PendingCount(List
421421
{
422422
if (between_ops.Contains(x.op))
423423
{
424-
if (!pending_count.ContainsKey(x.op.Name))
425-
pending_count[x.op.Name] = 0;
424+
if (!pending_count.ContainsKey(x.op.name))
425+
pending_count[x.op.name] = 0;
426426

427-
pending_count[x.op.Name] += 1;
427+
pending_count[x.op.name] += 1;
428428
}
429429
}
430430
}

src/TensorFlowNET.Core/Graphs/Graph.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ public unsafe Operation create_op(string op_type, Tensor[] inputs, TF_DataType[]
150150
_create_op_helper(op, true);
151151

152152
Console.Write($"create_op: {op_type} '{node_def.Name}'");
153-
Console.Write($", inputs: {(inputs.Length == 0 ? "empty" : String.Join(",", inputs.Select(x => x.name)))}");
154-
Console.Write($", outputs: {(op.outputs.Length == 0 ? "empty" : String.Join(",", op.outputs.Select(x => x.name)))}");
153+
Console.Write($", inputs: {(inputs.Length == 0 ? "empty" : String.Join(", ", inputs.Select(x => x.name)))}");
154+
Console.Write($", control_inputs: {(control_inputs.Length == 0 ? "empty" : String.Join(", ", control_inputs.Select(x => x.name)))}");
155+
Console.Write($", outputs: {(op.outputs.Length == 0 ? "empty" : String.Join(", ", op.outputs.Select(x => x.name)))}");
155156
Console.WriteLine();
156157

157158
return op;
@@ -182,7 +183,7 @@ public bool is_fetchable<T>(T tensor_or_op)
182183
}
183184
else if (tensor_or_op is Operation)
184185
{
185-
return !_unfetchable_ops.Contains((tensor_or_op as Operation).Name);
186+
return !_unfetchable_ops.Contains((tensor_or_op as Operation).name);
186187
}
187188

188189
return false;

src/TensorFlowNET.Core/ITensorOrOperation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public interface ITensorOrOperation
1212
{
1313
string Device { get; }
1414
Operation op { get; }
15+
string name { get; }
1516
}
1617
}

src/TensorFlowNET.Core/Operations/Operation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class Operation : ITensorOrOperation
2020

2121
private Status status = new Status();
2222

23-
public string Name => c_api.StringPiece(c_api.TF_OperationName(_handle));
23+
public string name => c_api.StringPiece(c_api.TF_OperationName(_handle));
2424
public string OpType => c_api.StringPiece(c_api.TF_OperationOpType(_handle));
2525
public string Device => c_api.StringPiece(c_api.TF_OperationDevice(_handle));
2626

@@ -210,7 +210,7 @@ private NodeDef GetNodeDef()
210210

211211
public override string ToString()
212212
{
213-
return _handle == IntPtr.Zero ? "tf.Operation Undefined" : $"tf.Operation '{Name}' type={OpType}";
213+
return _handle == IntPtr.Zero ? "tf.Operation Undefined" : $"tf.Operation '{name}' type={OpType}";
214214
}
215215

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

src/TensorFlowNET.Core/Sessions/_FetchHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private void _assert_fetchable(Graph graph, Operation op)
7373
{
7474
if (!graph.is_fetchable(op))
7575
{
76-
throw new Exception($"Operation {op.Name} has been marked as not fetchable.");
76+
throw new Exception($"Operation {op.name} has been marked as not fetchable.");
7777
}
7878
}
7979

src/TensorFlowNET.Core/Tensors/Tensor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class Tensor : IDisposable, ITensorOrOperation
2525
/// <summary>
2626
/// The string name of this tensor.
2727
/// </summary>
28-
public string name => $"{(op == null ? "Operation was not named" : $"{op.Name}:{value_index}")}";
28+
public string name => $"{(op == null ? "Operation was not named" : $"{op.name}:{value_index}")}";
2929

3030
public int value_index { get; }
3131

src/TensorFlowNET.Core/Train/Optimizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public Operation apply_gradients(Tuple<Tensor, RefVariable>[] grads_and_vars, Te
9797
if (grad == null)
9898
continue;
9999

100-
var scope_name = var.op.Name;
100+
var scope_name = var.op.name;
101101
Python.with<ops.name_scope>(new ops.name_scope("update_" + scope_name), scope2 =>
102102
{
103103
update_ops.Add(processor.update_op(this, grad));

src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public virtual SaverDef _build_internal(RefVariable[] names_to_saveables,
116116
{
117117
FilenameTensorName = filename_tensor.name,
118118
SaveTensorName = save_tensor.name,
119-
RestoreOpName = restore_op.Name,
119+
RestoreOpName = restore_op.name,
120120
MaxToKeep = max_to_keep,
121121
Sharded = sharded,
122122
KeepCheckpointEveryNHours = keep_checkpoint_every_n_hours,

src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public static Dictionary<string, Tensor> op_list_to_dict(RefVariable[] op_list,
8484
}
8585

8686
if (var.op.type == "ReadVariableOp")
87-
name = var.op.inputs[0].op.Name;
87+
name = var.op.inputs[0].op.name;
8888
else
89-
name = var.op.Name;
89+
name = var.op.name;
9090

9191
if (names_to_saveables.ContainsKey(name))
9292
throw new ValueError($"At least two variables have the same name: {name}");

src/TensorFlowNET.Core/Variables/RefVariable.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ private Tensor _try_guard_against_uninitialized_dependencies(Tensor initial_valu
143143
private Tensor _safe_initial_value_from_tensor(Tensor tensor, Dictionary<string, Operation> op_cache)
144144
{
145145
var op = tensor.op;
146-
var new_op = op_cache.ContainsKey(op.Name) ? op_cache[op.Name] : null;
146+
var new_op = op_cache.ContainsKey(op.name) ? op_cache[op.name] : null;
147147
if(new_op == null)
148148
{
149149
new_op = _safe_initial_value_from_op(op, op_cache);
150-
op_cache[op.Name] = new_op;
150+
op_cache[op.name] = new_op;
151151
}
152152
return new_op.outputs[tensor.value_index];
153153
}
@@ -185,7 +185,7 @@ private Operation _safe_initial_value_from_op(Operation op, Dictionary<string, O
185185
/// A `Tensor` that will hold the new value of this variable after
186186
/// the assignment has completed.
187187
/// </returns>
188-
public ITensorOrOperation assign(Tensor value, bool use_locking = false, string name = "", bool read_value = true)
188+
public ITensorOrOperation assign(object value, bool use_locking = false, string name = "", bool read_value = true)
189189
{
190190
var assign = gen_state_ops.assign(_variable, value, use_locking: use_locking, name: name);
191191
if (read_value)

0 commit comments

Comments
 (0)