Skip to content

Commit f189838

Browse files
committed
gen_math_ops.floor_mod SciSharp#160
1 parent 0045838 commit f189838

8 files changed

Lines changed: 32 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,23 @@ public static Tensor[] _GradientsHelper(Tensor[] ys,
129129
// for ops that do not have gradients.
130130
var grad_fn = ops.get_gradient_function(op);
131131

132-
Python.with<ops.name_scope>(new ops.name_scope(op.Name + "_grad"), delegate
132+
Python.with<ops.name_scope>(new ops.name_scope(op.Name + "_grad"), scope1 =>
133133
{
134+
string name1 = scope1;
134135
if (grad_fn != null)
135136
{
136137
in_grads = _MaybeCompile(grad_scope, op, out_grads[0], null, grad_fn);
137138
_VerifyGeneratedGradients(in_grads, op);
138139
}
140+
141+
if (gate_gradients)
142+
{
143+
144+
}
139145
});
140-
146+
147+
// temp fix name scope
148+
op.Graph._name_stack = "gradients";
141149
}
142150
}
143151
else

‎src/TensorFlowNET.Core/Operations/OpDefLibrary.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public Operation _apply_op_helper(string op_type_name, string name = "", dynamic
9393
foreach (var attr_def in op_def.Attr)
9494
{
9595
var key = attr_def.Name;
96+
if (!attrs.ContainsKey(key))
97+
Console.WriteLine($"{key} not found in attr_def.");
9698
var value = attrs[key];
9799
var attr_value = new AttrValue();
98100

‎src/TensorFlowNET.Core/Operations/array_ops.py.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private static Tensor shape_internal(Tensor input, string name = "", bool optimi
9999
// result = gen_array_ops.shape();
100100
}
101101

102-
return null;
102+
return gen_array_ops.shape(input);
103103
});
104104
}
105105

‎src/TensorFlowNET.Core/Operations/gen_array_ops.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public static Tensor reshape(Tensor tensor, Tensor shape, string name = "")
8080
return _op.outputs[0];
8181
}
8282

83+
public static Tensor shape(Tensor input, TF_DataType out_type = TF_DataType.TF_INT32, string name = "")
84+
{
85+
var _op = _op_def_lib._apply_op_helper("Shape", name, new { input, out_type });
86+
return _op.outputs[0];
87+
}
88+
8389
public static Tensor size(Tensor input, TF_DataType out_type = TF_DataType.TF_INT32, string name = "")
8490
{
8591
var _op = _op_def_lib._apply_op_helper("Size", name, new { input, out_type });

‎src/TensorFlowNET.Core/Operations/gen_math_ops.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public static Tensor real_div(Tensor x, Tensor y, string name = "")
4545
return _op.outputs[0];
4646
}
4747

48+
public static Tensor floor_mod(Tensor x, Tensor y, string name = "")
49+
{
50+
var _op = _op_def_lib._apply_op_helper("FloorMod", name, args: new { x, y });
51+
52+
return _op.outputs[0];
53+
}
54+
4855
/// <summary>
4956
/// Multiply the matrix "a" by the matrix "b".
5057
/// </summary>

‎src/TensorFlowNET.Core/Operations/math_ops.py.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static Tensor reduced_shape(Tensor input_shape, Tensor axes)
1919

2020
var input_rank = array_ops.size(input_shape);
2121
axes = (axes + input_rank) % input_rank;
22+
var axes_shape = array_ops.shape(axes);
2223

2324
return null;
2425
}

‎src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ public partial class Tensor
7979

8080
public static Tensor operator %(Tensor x, Tensor y)
8181
{
82-
throw new NotImplementedException("math mod is not implemented");
82+
return Python.with<ops.name_scope, Tensor>(new ops.name_scope("", "mod", new object[] { x, y }), scope =>
83+
{
84+
return gen_math_ops.floor_mod(x, y, scope);
85+
});
8386
}
8487
}
8588
}

‎src/TensorFlowNET.Core/Tensors/TensorShape.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public TensorShape(params int[] dims) : base(dims)
2323
/// <returns></returns>
2424
public bool is_fully_defined()
2525
{
26-
return Dimensions != null && Dimensions.Count(x => x > 0) > 0;
26+
return Dimensions != null && Dimensions.Count(x => x < 1) == 0;
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)