Skip to content

Commit

Permalink
change argument name
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Jan 20, 2025
1 parent 508bfa2 commit d6503ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
4 changes: 2 additions & 2 deletions arkouda/numpy/random/_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def permutation(self, x, method="Argsort"):
make a copy and shuffle the elements randomly.
method: str = "Argsort"
The method for generating the permutation.
Allowed values: Serial, Argsort
Allowed values: FisherYates, Argsort
If Argsort is selected, the permutation will be generated by
an argsort performed on randomly generated floats.
Returns
Expand All @@ -643,7 +643,7 @@ def permutation(self, x, method="Argsort"):
else:
raise TypeError("permutation only accepts a pdarray or int scalar.")

if method.lower() == "serial":
if method.lower() == "fisheryates":
# we have to use the int version since we permute the domain
name = self._name_dict[to_numpy_dtype(akint64)]
rep_msg = generic_msg(
Expand Down
50 changes: 38 additions & 12 deletions tests/numpy/random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_shuffle(self, data_type):
assert check(pda, pda_prime, data_type)

@pytest.mark.parametrize("data_type", INT_FLOAT)
@pytest.mark.parametrize("method", ["Serial", "Argsort"])
@pytest.mark.parametrize("method", ["FisherYates", "Argsort"])
def test_permutation(self, data_type, method):

# ints are checked for equality; floats are checked for closeness
Expand Down Expand Up @@ -206,7 +206,10 @@ def test_logistic(self):
log_sample = rng.logistic(loc=loc, scale=scale, size=num_samples).to_list()

rng = ak.random.default_rng(17)
assert rng.logistic(loc=loc, scale=scale, size=num_samples).to_list() == log_sample
assert (
rng.logistic(loc=loc, scale=scale, size=num_samples).to_list()
== log_sample
)

def test_lognormal(self):
scal = 2
Expand All @@ -215,25 +218,40 @@ def test_lognormal(self):
for mean, sigma in product([scal, arr], [scal, arr]):
rng = ak.random.default_rng(17)
num_samples = 5
log_sample = rng.lognormal(mean=mean, sigma=sigma, size=num_samples).to_list()
log_sample = rng.lognormal(
mean=mean, sigma=sigma, size=num_samples
).to_list()

rng = ak.random.default_rng(17)
assert rng.lognormal(mean=mean, sigma=sigma, size=num_samples).to_list() == log_sample
assert (
rng.lognormal(mean=mean, sigma=sigma, size=num_samples).to_list()
== log_sample
)

def test_normal(self):
rng = ak.random.default_rng(17)
both_scalar = rng.normal(loc=10, scale=2, size=10).to_list()
scale_scalar = rng.normal(loc=ak.array([0, 10, 20]), scale=1, size=3).to_list()
loc_scalar = rng.normal(loc=10, scale=ak.array([1, 2, 3]), size=3).to_list()
both_array = rng.normal(loc=ak.array([0, 10, 20]), scale=ak.array([1, 2, 3]), size=3).to_list()
both_array = rng.normal(
loc=ak.array([0, 10, 20]), scale=ak.array([1, 2, 3]), size=3
).to_list()

# redeclare rng with same seed to test reproducibility
rng = ak.random.default_rng(17)
assert rng.normal(loc=10, scale=2, size=10).to_list() == both_scalar
assert rng.normal(loc=ak.array([0, 10, 20]), scale=1, size=3).to_list() == scale_scalar
assert rng.normal(loc=10, scale=ak.array([1, 2, 3]), size=3).to_list() == loc_scalar
assert (
rng.normal(loc=ak.array([0, 10, 20]), scale=ak.array([1, 2, 3]), size=3).to_list()
rng.normal(loc=ak.array([0, 10, 20]), scale=1, size=3).to_list()
== scale_scalar
)
assert (
rng.normal(loc=10, scale=ak.array([1, 2, 3]), size=3).to_list()
== loc_scalar
)
assert (
rng.normal(
loc=ak.array([0, 10, 20]), scale=ak.array([1, 2, 3]), size=3
).to_list()
== both_array
)

Expand Down Expand Up @@ -280,8 +298,12 @@ def test_exponential(self):

# reset rng with same seed and ensure we get same results
rng = ak.random.default_rng(17)
assert rng.exponential(scale=scal_scale, size=num_samples).to_list() == scal_sample
assert rng.exponential(scale=arr_scale, size=num_samples).to_list() == arr_sample
assert (
rng.exponential(scale=scal_scale, size=num_samples).to_list() == scal_sample
)
assert (
rng.exponential(scale=arr_scale, size=num_samples).to_list() == arr_sample
)

def test_choice_hypothesis_testing(self):
# perform a weighted sample and use chisquare to test
Expand Down Expand Up @@ -360,7 +382,9 @@ def test_lognormal_hypothesis_testing(self, method):

mean = rng.uniform(-10, 10)
deviation = rng.uniform(0, 10)
sample = rng.lognormal(mean=mean, sigma=deviation, size=num_samples, method=method)
sample = rng.lognormal(
mean=mean, sigma=deviation, size=num_samples, method=method
)

log_sample_list = np.log(sample.to_ndarray()).tolist()

Expand Down Expand Up @@ -571,7 +595,9 @@ def test_legacy_uniform(self):
uArray.to_list(),
)

uArray = ak.random.uniform(size=np.int64(3), low=np.int64(0), high=np.int64(5), seed=np.int64(0))
uArray = ak.random.uniform(
size=np.int64(3), low=np.int64(0), high=np.int64(5), seed=np.int64(0)
)
assert np.allclose(
[0.30013431967121934, 0.47383036230759112, 1.0441791878997098],
uArray.to_list(),
Expand Down

0 comments on commit d6503ed

Please sign in to comment.