| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ limitations under the License. | |||
| 21 | 21 | using System.ComponentModel; | |
| 22 | 22 | using System.Diagnostics; | |
| 23 | 23 | using System.Linq; | |
| 24 | + using NumSharp.Utilities; | ||
| 24 | 25 | ||
| 25 | 26 | namespace Tensorflow | |
| 26 | 27 | { | |
@@ -29,9 +30,37 @@ namespace Tensorflow | |||
| 29 | 30 | /// </summary> | |
| 30 | 31 | public static partial class Binding | |
| 31 | 32 | { | |
| 33 | + private static string _tostring(object obj) | ||
| 34 | + { | ||
| 35 | + switch (obj) | ||
| 36 | + { | ||
| 37 | + case NDArray nd: | ||
| 38 | + return nd.ToString(false); | ||
| 39 | + case Array arr: | ||
| 40 | + if (arr.Rank!=1 || arr.GetType().GetElementType()?.IsArray == true) | ||
| 41 | + arr = Arrays.Flatten(arr); | ||
| 42 | + var objs = toObjectArray(arr); | ||
| 43 | + return $"[{string.Join(", ", objs.Select(_tostring))}]"; | ||
| 44 | + default: | ||
| 45 | + return obj?.ToString() ?? "null"; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + object[] toObjectArray(Array arr) | ||
| 49 | + { | ||
| 50 | + var len = arr.LongLength; | ||
| 51 | + var ret = new object[len]; | ||
| 52 | + for (long i = 0; i < len; i++) | ||
| 53 | + { | ||
| 54 | + ret[i] = arr.GetValue(i); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + return ret; | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + | ||
| 32 | 61 | public static void print(object obj) | |
| 33 | 62 | { | |
| 34 | - Console.WriteLine(obj.ToString()); | ||
| 63 | + Console.WriteLine(_tostring(obj)); | ||
| 35 | 64 | } | |
| 36 | 65 | ||
| 37 | 66 | public static int len(object a) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments