Skip to content

Commit f378640

Browse files
committed
tf.random_shuffle SciSharp#396
1 parent ccb8634 commit f378640

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/TensorFlowNET.Core/APIs/tf.random.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,18 @@ public Tensor truncated_normal(int[] shape,
4949
int? seed = null,
5050
string name = null)
5151
=> random_ops.truncated_normal(shape, mean, stddev, dtype, seed, name);
52+
53+
/// <summary>
54+
/// Randomly shuffles a tensor along its first dimension.
55+
/// </summary>
56+
/// <param name="value"></param>
57+
/// <param name="seed"></param>
58+
/// <param name="name"></param>
59+
/// <returns>
60+
/// A tensor of same shape and type as value, shuffled along its
61+
/// first dimension.
62+
/// </returns>
63+
public Tensor random_shuffle(Tensor value, int? seed = null, string name = null)
64+
=> random_ops.random_shuffle(value, seed: seed, name: name);
5265
}
5366
}

src/TensorFlowNET.Core/Operations/gen_random_ops.py.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ public static Tensor random_uniform(Tensor shape, TF_DataType dtype, int? seed =
9090
return _op.outputs[0];
9191
}
9292

93+
/// <summary>
94+
///
95+
/// </summary>
96+
/// <param name="value"></param>
97+
/// <param name="seed"></param>
98+
/// <param name="seed2"></param>
99+
/// <param name="name"></param>
100+
/// <returns></returns>
101+
public static Tensor random_shuffle(Tensor value, int seed = 0, int seed2 = 0, string name = null)
102+
{
103+
var _op = _op_def_lib._apply_op_helper("RandomShuffle",
104+
name: name,
105+
args: new { value, seed, seed2 });
106+
107+
return _op.output;
108+
}
109+
93110
/// <summary>
94111
/// Outputs random values from a truncated normal distribution.
95112
/// </summary>

src/TensorFlowNET.Core/Operations/random_ops.py.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ public static Tensor random_uniform(Tensor shape,
104104
});
105105
}
106106

107+
/// <summary>
108+
/// Randomly shuffles a tensor along its first dimension.
109+
/// </summary>
110+
/// <param name="value"></param>
111+
/// <param name="seed"></param>
112+
/// <param name="name"></param>
113+
/// <returns></returns>
114+
public static Tensor random_shuffle(Tensor value, int? seed = null, string name = null)
115+
{
116+
var (seed1, seed2) = random_seed.get_seed(seed);
117+
return gen_random_ops.random_shuffle(value, seed: seed1.Value, seed2: seed2.Value, name: name);
118+
}
119+
107120
public static Tensor truncated_normal(int[] shape,
108121
float mean = 0.0f,
109122
float stddev = 1.0f,

0 commit comments

Comments
 (0)