Skip to content

Commit 6534271

Browse files
Esther2013Oceania2018
authored andcommitted
add gen_array_ops.pack eager
1 parent 77c6939 commit 6534271

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ private static TF_DataType _get_dtype_from_nested_lists(object[] list_or_tuple)
178178
return dtype;
179179
}
180180

181+
/// <summary>
182+
/// Converts the given list or tuple to a tensor by packing.
183+
/// </summary>
184+
/// <param name="list_or_tuple">A (possibly nested) list or tuple containing a tensor.</param>
185+
/// <param name="dtype"></param>
186+
/// <param name="name"></param>
187+
/// <returns>A `tf.Tensor` with value equivalent to `list_or_tuple`.</returns>
181188
public static Tensor _autopacking_helper(object[] list_or_tuple, TF_DataType dtype, string name)
182189
{
183190
var must_pack = false;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ public static Tensor pad(Tensor input, Tensor paddings, string name = null)
122122

123123
public static Tensor pack(Tensor[] values, int axis = 0, string name = null)
124124
{
125+
if(tf.context.executing_eagerly())
126+
{
127+
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, tf.context.device_name, "Pack", name, null, values, "axis", axis);
128+
return _result;
129+
}
130+
125131
var _op = _op_def_lib._apply_op_helper("Pack", name: name, args: new { values, axis });
126132

127133
return _op.outputs[0];

‎src/TensorFlowNET.Core/ops.cs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ public static Graph _get_graph_from_inputs(Tensor[] op_input_list, Graph graph =
9797
/// <returns></returns>
9898
public static Tensor convert_to_tensor(object value, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, TF_DataType preferred_dtype = TF_DataType.DtInvalid)
9999
{
100-
if (value is Tensor tensor)
101-
return tensor;
102-
103100
return convert_to_tensor_v2(value, dtype, preferred_dtype, name);
104101
}
105102

0 commit comments

Comments
 (0)