| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2001619 commit a4a4da9
19 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,9 @@ public partial class tensorflow | |||
| 21 | 21 | public MathApi math { get; } = new MathApi(); | |
| 22 | 22 | public class MathApi | |
| 23 | 23 | { | |
| 24 | + public Tensor argmax(Tensor input, Axis axis = null, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64) | ||
| 25 | + => gen_math_ops.arg_max(input, axis, name: name, output_type: output_type); | ||
| 26 | + | ||
| 24 | 27 | public Tensor log(Tensor x, string name = null) | |
| 25 | 28 | => gen_math_ops.log(x, name); | |
| 26 | 29 | ||
@@ -539,15 +542,12 @@ public Tensor reduce_mean(Tensor input_tensor, Axis? axis = null, bool keepdims | |||
| 539 | 542 | public Tensor round(Tensor x, string name = null) | |
| 540 | 543 | => gen_math_ops.round(x, name: name); | |
| 541 | 544 | ||
| 542 | - public Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null) | ||
| 545 | + public Tensor cast(Tensor x, TF_DataType dtype, string name = null) | ||
| 543 | 546 | => math_ops.cast(x, dtype, name); | |
| 544 | 547 | ||
| 545 | 548 | public Tensor cumsum(Tensor x, int axis = 0, bool exclusive = false, bool reverse = false, string name = null) | |
| 546 | 549 | => math_ops.cumsum(x, axis: axis, exclusive: exclusive, reverse: reverse, name: name); | |
| 547 | 550 | ||
| 548 | - public Tensor argmax(Tensor input, int axis = -1, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64) | ||
| 549 | - => gen_math_ops.arg_max(input, axis, name: name, output_type: output_type); | ||
| 550 | - | ||
| 551 | 551 | public Tensor square(Tensor x, string name = null) | |
| 552 | 552 | => gen_math_ops.square(x, name: name); | |
| 553 | 553 | public Tensor squared_difference(Tensor x, Tensor y, string name = null) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -549,6 +549,8 @@ public static TF_DataType GetDataType(this object data) | |||
| 549 | 549 | return tensors.dtype; | |
| 550 | 550 | case IEnumerable<Tensor> tensors: | |
| 551 | 551 | return tensors.First().dtype; | |
| 552 | + case RefVariable variable: | ||
| 553 | + return variable.dtype; | ||
| 552 | 554 | case ResourceVariable variable: | |
| 553 | 555 | return variable.dtype; | |
| 554 | 556 | default: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Collections.Generic; | |
| 3 | + using System.Diagnostics; | ||
| 3 | 4 | using System.Text; | |
| 4 | 5 | using static Tensorflow.Binding; | |
| 5 | 6 | ||
@@ -11,11 +12,13 @@ public class ExecuteOpArgs | |||
| 11 | 12 | public object[] OpInputArgs { get; set; } | |
| 12 | 13 | public Dictionary<string, object> OpAttrs { get; set; } | |
| 13 | 14 | ||
| 15 | + [DebuggerStepThrough] | ||
| 14 | 16 | public ExecuteOpArgs(params object[] inputArgs) | |
| 15 | 17 | { | |
| 16 | 18 | OpInputArgs = inputArgs; | |
| 17 | 19 | } | |
| 18 | 20 | ||
| 21 | + [DebuggerStepThrough] | ||
| 19 | 22 | public ExecuteOpArgs SetAttributes(object attrs) | |
| 20 | 23 | { | |
| 21 | 24 | OpAttrs = ConvertToDict(attrs); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,7 +56,7 @@ public static implicit operator Tensor(Axis axis) | |||
| 56 | 56 | => constant_op.constant(axis); | |
| 57 | 57 | ||
| 58 | 58 | public override string ToString() | |
| 59 | - => $"({string.Join(", ", axis)})"; | ||
| 59 | + => IsScalar ? $"{axis[0]}" : $"({string.Join(", ", axis)})"; | ||
| 60 | 60 | } | |
| 61 | 61 | } | |
| 62 | 62 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Runtime.InteropServices; | ||
| 4 | + using System.Text; | ||
| 5 | + | ||
| 6 | + namespace Tensorflow.NumPy | ||
| 7 | + { | ||
| 8 | + public class RandomizedImpl | ||
| 9 | + { | ||
| 10 | + [AutoNumPy] | ||
| 11 | + public NDArray permutation(int x) => new NDArray(random_ops.random_shuffle(math_ops.range(0, x))); | ||
| 12 | + | ||
| 13 | + [AutoNumPy] | ||
| 14 | + public NDArray permutation(NDArray x) => new NDArray(random_ops.random_shuffle(x)); | ||
| 15 | + | ||
| 16 | + [AutoNumPy] | ||
| 17 | + public void shuffle(NDArray x) | ||
| 18 | + { | ||
| 19 | + var y = random_ops.random_shuffle(x); | ||
| 20 | + Marshal.Copy(y.BufferToArray(), 0, x.TensorDataPointer, (int)x.bytesize); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public NDArray rand(params int[] shape) | ||
| 24 | + => throw new NotImplementedException(""); | ||
| 25 | + | ||
| 26 | + public NDArray randint(long x) | ||
| 27 | + => throw new NotImplementedException(""); | ||
| 28 | + } | ||
| 29 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,8 @@ public NDArray this[NDArray mask] | |||
| 45 | 45 | { | |
| 46 | 46 | if(mask.dtype == TF_DataType.TF_INT32) | |
| 47 | 47 | return GetData(mask.ToArray<int>()); | |
| 48 | + else if (mask.dtype == TF_DataType.TF_INT64) | ||
| 49 | + return GetData(mask.ToArray<long>().Select(x => Convert.ToInt32(x)).ToArray()); | ||
| 48 | 50 | ||
| 49 | 51 | throw new NotImplementedException(""); | |
| 50 | 52 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,13 @@ public static NDArray argsort(NDArray a, Axis axis = null) | |||
| 17 | 17 | => new NDArray(math_ops.argmax(a, axis ?? -1)); | |
| 18 | 18 | ||
| 19 | 19 | [AutoNumPy] | |
| 20 | - public static NDArray unique(NDArray a) | ||
| 21 | - => throw new NotImplementedException(""); | ||
| 20 | + public static (NDArray, NDArray) unique(NDArray a) | ||
| 21 | + { | ||
| 22 | + var(u, indice) = array_ops.unique(a); | ||
| 23 | + return (new NDArray(u), new NDArray(indice)); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + [AutoNumPy] | ||
| 27 | + public static void shuffle(NDArray x) => np.random.shuffle(x); | ||
| 22 | 28 | } | |
| 23 | 29 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,6 @@ public partial class np | |||
| 13 | 13 | public static NDArray amin(NDArray x, int axis = 0) => new NDArray(tf.arg_min(x, axis)); | |
| 14 | 14 | ||
| 15 | 15 | [AutoNumPy] | |
| 16 | - public static NDArray amax(NDArray x, int axis = 0) => new NDArray(tf.arg_max(x, axis)); | ||
| 16 | + public static NDArray amax(NDArray x, int axis = 0) => new NDArray(tf.math.argmax(x, axis)); | ||
| 17 | 17 | } | |
| 18 | 18 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,9 @@ public NDArray(Shape shape, TF_DataType dtype = TF_DataType.TF_DOUBLE) | |||
| 25 | 25 | public NDArray(byte[] bytes, Shape shape, TF_DataType dtype) | |
| 26 | 26 | : base(bytes, shape, dtype) { NewEagerTensorHandle(); } | |
| 27 | 27 | ||
| 28 | + public NDArray(long[] value, Shape? shape = null) | ||
| 29 | + : base(value, shape) { NewEagerTensorHandle(); } | ||
| 30 | + | ||
| 28 | 31 | public NDArray(IntPtr address, Shape shape, TF_DataType dtype) | |
| 29 | 32 | : base(address, shape, dtype) { NewEagerTensorHandle(); } | |
| 30 | 33 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,11 +42,9 @@ public NDIterator<T> AsIterator<T>(bool autoreset = false) where T : unmanaged | |||
| 42 | 42 | public NDArray reshape(Shape newshape) => new NDArray(tf.reshape(this, newshape)); | |
| 43 | 43 | public NDArray astype(TF_DataType dtype) => new NDArray(math_ops.cast(this, dtype)); | |
| 44 | 44 | public NDArray ravel() => throw new NotImplementedException(""); | |
| 45 | - public void shuffle(NDArray nd) => throw new NotImplementedException(""); | ||
| 45 | + public void shuffle(NDArray nd) => np.random.shuffle(nd); | ||
| 46 | 46 | public Array ToMuliDimArray<T>() => throw new NotImplementedException(""); | |
| 47 | 47 | public byte[] ToByteArray() => BufferToArray(); | |
| 48 | - public static string[] AsStringArray(NDArray arr) => throw new NotImplementedException(""); | ||
| 49 | - | ||
| 50 | 48 | public override string ToString() => NDArrayRender.ToString(this); | |
| 51 | 49 | } | |
| 52 | 50 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments