| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 00003a6 commit b71b4a2
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,10 +62,6 @@ public NDArray pad_sequences(NDArray sequences, | |||
| 62 | 62 | { | |
| 63 | 63 | switch(sequences[i]) | |
| 64 | 64 | { | |
| 65 | - case int[] data: | ||
| 66 | - for (int j = 0; j < nd.shape[1]; j++) | ||
| 67 | - nd[i, j] = j < data.Length ? data[j] : value; | ||
| 68 | - break; | ||
| 69 | 65 | default: | |
| 70 | 66 | throw new NotImplementedException("pad_sequences"); | |
| 71 | 67 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,7 +291,7 @@ private static Tensor _may_reduce_to_scalar(bool keepdims, Tensor axis, Tensor o | |||
| 291 | 291 | !keepdims && | |
| 292 | 292 | axis == null) | |
| 293 | 293 | // We want set_shape to be reflected in the C API graph for when we run it. | |
| 294 | - output.shape = new long[0]; | ||
| 294 | + output.shape = new int[0]; | ||
| 295 | 295 | return output; | |
| 296 | 296 | } | |
| 297 | 297 | ||
@@ -300,7 +300,7 @@ private static Tensor _may_reduce_to_scalar(bool keepdims, int[] axis, Tensor ou | |||
| 300 | 300 | if (!common_shapes.has_fully_defined_shape(output) && | |
| 301 | 301 | !keepdims && | |
| 302 | 302 | axis == null) | |
| 303 | - output.shape = new long[0]; | ||
| 303 | + output.shape = new int[0]; | ||
| 304 | 304 | return output; | |
| 305 | 305 | } | |
| 306 | 306 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,24 @@ public NDArray build_results(BaseSession session, NDArray[] tensor_values) | |||
| 52 | 52 | { | |
| 53 | 53 | if (is_op) | |
| 54 | 54 | { | |
| 55 | - full_values.Add(null); | ||
| 55 | + if(tensor_values.Length > 0) | ||
| 56 | + { | ||
| 57 | + switch (tensor_values[0].dtype.Name) | ||
| 58 | + { | ||
| 59 | + case "Int32": | ||
| 60 | + full_values.Add(float.NaN); | ||
| 61 | + break; | ||
| 62 | + case "Single": | ||
| 63 | + full_values.Add(float.NaN); | ||
| 64 | + break; | ||
| 65 | + default: | ||
| 66 | + throw new NotImplementedException($"build_results tensor_values[0] {tensor_values[0].dtype.Name}"); | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + else | ||
| 70 | + { | ||
| 71 | + full_values.Add(null); | ||
| 72 | + } | ||
| 56 | 73 | } | |
| 57 | 74 | else | |
| 58 | 75 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | using NumSharp; | |
| 2 | 2 | using System; | |
| 3 | 3 | using System.Collections.Generic; | |
| 4 | + using System.Linq; | ||
| 4 | 5 | using System.Text; | |
| 5 | 6 | ||
| 6 | 7 | namespace Tensorflow | |
@@ -21,7 +22,17 @@ public static _FetchMapper for_fetch(object fetch) | |||
| 21 | 22 | ||
| 22 | 23 | public virtual NDArray build_results(List<object> values) | |
| 23 | 24 | { | |
| 24 | - return values.ToArray(); | ||
| 25 | + var type = values[0].GetType(); | ||
| 26 | + var nd = new NDArray(type, values.Count); | ||
| 27 | + | ||
| 28 | + switch (type.Name) | ||
| 29 | + { | ||
| 30 | + case "Single": | ||
| 31 | + nd.SetData(values.Select(x => (float)x).ToArray()); | ||
| 32 | + break; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + return nd; | ||
| 25 | 36 | } | |
| 26 | 37 | ||
| 27 | 38 | public virtual List<object> unique_fetches() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,7 @@ public partial class Tensor : Python, IDisposable, ITensorOrOperation | |||
| 46 | 46 | ||
| 47 | 47 | private TF_Output? _tf_output; | |
| 48 | 48 | ||
| 49 | - public long[] shape | ||
| 49 | + public int[] shape | ||
| 50 | 50 | { | |
| 51 | 51 | get | |
| 52 | 52 | { | |
@@ -63,15 +63,15 @@ public long[] shape | |||
| 63 | 63 | dims[i] = c_api.TF_Dim(_handle, i); | |
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | - return dims; | ||
| 66 | + return dims.Select(x => Convert.ToInt32(x)).ToArray(); | ||
| 67 | 67 | } | |
| 68 | 68 | ||
| 69 | 69 | set | |
| 70 | 70 | { | |
| 71 | 71 | if (value == null) | |
| 72 | 72 | c_api.TF_GraphSetTensorShape(this.graph, this._as_tf_output(), null, -1, status); | |
| 73 | 73 | else | |
| 74 | - c_api.TF_GraphSetTensorShape(this.graph, this._as_tf_output(), value, value.Length, status); | ||
| 74 | + c_api.TF_GraphSetTensorShape(this.graph, this._as_tf_output(), value.Select(x => Convert.ToInt64(x)).ToArray(), value.Length, status); | ||
| 75 | 75 | } | |
| 76 | 76 | } | |
| 77 | 77 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -321,6 +321,11 @@ public static TensorShape to_shape(long[] dims) | |||
| 321 | 321 | return new TensorShape(dims.Select(x => (int)x).ToArray()); | |
| 322 | 322 | } | |
| 323 | 323 | ||
| 324 | + public static TensorShape to_shape(int[] dims) | ||
| 325 | + { | ||
| 326 | + return new TensorShape(dims); | ||
| 327 | + } | ||
| 328 | + | ||
| 324 | 329 | public static TensorShape as_shape(this Shape shape) | |
| 325 | 330 | { | |
| 326 | 331 | return new TensorShape(shape.Dimensions); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ public class gen_state_ops | |||
| 21 | 21 | /// <param name="container"></param> | |
| 22 | 22 | /// <param name="shared_name"></param> | |
| 23 | 23 | /// <returns></returns> | |
| 24 | - public static Tensor variable_v2(long[] shape, TF_DataType dtype, string name = null, string container = "", string shared_name = "") | ||
| 24 | + public static Tensor variable_v2(int[] shape, TF_DataType dtype, string name = null, string container = "", string shared_name = "") | ||
| 25 | 25 | { | |
| 26 | 26 | var _op = _op_def_lib._apply_op_helper("VariableV2", name: name, args: new { dtype, shape, container, shared_name }); | |
| 27 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ public class state_ops | |||
| 15 | 15 | /// <param name="container"></param> | |
| 16 | 16 | /// <param name="shared_name"></param> | |
| 17 | 17 | /// <returns></returns> | |
| 18 | - public static Tensor variable_op_v2(long[] shape, | ||
| 18 | + public static Tensor variable_op_v2(int[] shape, | ||
| 19 | 19 | TF_DataType dtype, | |
| 20 | 20 | string name = "Variable", | |
| 21 | 21 | string container = "", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments