Skip to content

Commit e0fa47b

Browse files
committed
fix(random): correct size parameter delegation in np.random.* functions
Fixed circular delegation and incorrect type conversion in 18 RandomSampling files. All overloads now properly delegate to Shape constructor: - int[] → new Shape(size) - params long[] → new Shape(size) - int → new int[] { size } to int[] overload Shape constructor accepts both int[] and long[], eliminating need for Array.ConvertAll or Shape.ToIntArray in delegation chain. Files fixed: dirichlet, gumbel, hypergeometric, laplace, logistic, logseries, multivariate_normal, negative_binomial, noncentral_chisquare, pareto, power, rayleigh, standard_cauchy, standard_exponential, standard_gamma, standard_t, vonmises, zipf
1 parent 1bccd96 commit e0fa47b

14 files changed

Lines changed: 14 additions & 14 deletions

src/NumSharp.Core/RandomSampling/np.random.dirichlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public NDArray dirichlet(double[] alpha, params long[] size)
154154
/// <param name="size">Number of samples to draw.</param>
155155
/// <returns>Drawn samples from the Dirichlet distribution.</returns>
156156
public NDArray dirichlet(double[] alpha, int size)
157-
=> dirichlet(alpha, new Shape(size));
157+
=> dirichlet(alpha, new int[] { size });
158158

159159
/// <summary>
160160
/// Sample a single Dirichlet vector and store at the given offset.

src/NumSharp.Core/RandomSampling/np.random.gumbel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public NDArray gumbel(double loc, double scale, params long[] size)
7676
/// <param name="size">Output shape as single int.</param>
7777
/// <returns>Drawn samples from the parameterized Gumbel distribution.</returns>
7878
public NDArray gumbel(double loc, double scale, int size)
79-
=> gumbel(loc, scale, new Shape(size));
79+
=> gumbel(loc, scale, new int[] { size });
8080

8181
/// <summary>
8282
/// Sample from the Gumbel distribution using the same algorithm as NumPy.

src/NumSharp.Core/RandomSampling/np.random.hypergeometric.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public NDArray hypergeometric(long ngood, long nbad, long nsample, params long[]
6969
/// <param name="size">Output shape as single int.</param>
7070
/// <returns>Drawn samples from the hypergeometric distribution.</returns>
7171
public NDArray hypergeometric(long ngood, long nbad, long nsample, int size)
72-
=> hypergeometric(ngood, nbad, nsample, new Shape(size));
72+
=> hypergeometric(ngood, nbad, nsample, new int[] { size });
7373

7474
/// <summary>
7575
/// Draw a single sample from a Hypergeometric distribution.

src/NumSharp.Core/RandomSampling/np.random.laplace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public NDArray laplace(double loc, double scale, params long[] size)
7676
/// <param name="size">Output shape as single int.</param>
7777
/// <returns>Drawn samples from the parameterized Laplace distribution.</returns>
7878
public NDArray laplace(double loc, double scale, int size)
79-
=> laplace(loc, scale, new Shape(size));
79+
=> laplace(loc, scale, new int[] { size });
8080

8181
/// <summary>
8282
/// Sample from the Laplace distribution using the same algorithm as NumPy.

src/NumSharp.Core/RandomSampling/np.random.logistic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public NDArray logistic(double loc, double scale, params long[] size)
7474
/// <param name="size">Output shape as single int.</param>
7575
/// <returns>Drawn samples from the parameterized logistic distribution.</returns>
7676
public NDArray logistic(double loc, double scale, int size)
77-
=> logistic(loc, scale, new Shape(size));
77+
=> logistic(loc, scale, new int[] { size });
7878

7979
/// <summary>
8080
/// Sample from the logistic distribution using inverse transform method.

src/NumSharp.Core/RandomSampling/np.random.logseries.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public NDArray logseries(double p, Shape size)
9191
/// <param name="size">Output shape as single int.</param>
9292
/// <returns>Drawn samples from the parameterized logarithmic series distribution.</returns>
9393
public NDArray logseries(double p, int size)
94-
=> logseries(p, new Shape(size));
94+
=> logseries(p, new int[] { size });
9595

9696
private static void ValidateLogseriesP(double p)
9797
{

src/NumSharp.Core/RandomSampling/np.random.negative_binomial.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public NDArray negative_binomial(double n, double p, params long[] size)
7777
/// <param name="size">Output shape as single int.</param>
7878
/// <returns>Drawn samples from the parameterized negative binomial distribution.</returns>
7979
public NDArray negative_binomial(double n, double p, int size)
80-
=> negative_binomial(n, p, new Shape(size));
80+
=> negative_binomial(n, p, new int[] { size });
8181

8282
/// <summary>
8383
/// Sample from the negative binomial distribution using gamma-Poisson mixture.

src/NumSharp.Core/RandomSampling/np.random.noncentral_chisquare.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public NDArray noncentral_chisquare(double df, double nonc, params long[] size)
6666
/// <param name="size">Output shape as single int.</param>
6767
/// <returns>Drawn samples from the parameterized noncentral chi-square distribution.</returns>
6868
public NDArray noncentral_chisquare(double df, double nonc, int size)
69-
=> noncentral_chisquare(df, nonc, new Shape(size));
69+
=> noncentral_chisquare(df, nonc, new int[] { size });
7070

7171
/// <summary>
7272
/// Draw a single sample from a noncentral chi-square distribution.

src/NumSharp.Core/RandomSampling/np.random.pareto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public NDArray pareto(double a, params long[] size)
6565
/// <param name="size">Output shape as single int.</param>
6666
/// <returns>Drawn samples from the parameterized Pareto distribution.</returns>
6767
public NDArray pareto(double a, int size)
68-
=> pareto(a, new Shape(size));
68+
=> pareto(a, new int[] { size });
6969

7070
/// <summary>
7171
/// Draw a single sample from a Pareto II or Lomax distribution.

src/NumSharp.Core/RandomSampling/np.random.power.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public NDArray power(double a, params long[] size)
6262
/// <param name="size">Output shape as single int.</param>
6363
/// <returns>Drawn samples from the parameterized power distribution, in range [0, 1].</returns>
6464
public NDArray power(double a, int size)
65-
=> power(a, new Shape(size));
65+
=> power(a, new int[] { size });
6666

6767
/// <summary>
6868
/// Draw a single sample from a power distribution.

0 commit comments

Comments
 (0)