Skip to content

Commit

Permalink
Update random sampling in tests to impove test reliability (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverholworthy authored Nov 15, 2022
1 parent df8590a commit 5c6746f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions tests/unit/systems/dag/ops/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import random
from distutils.spawn import find_executable

import numpy as np
Expand All @@ -38,7 +39,7 @@ def test_softmax_sampling(tmpdir):
)

combined_features = {
"movie_ids": np.random.randint(0, 10000, 100).astype(np.int32),
"movie_ids": np.array(random.sample(range(10000), 100), dtype=np.int32),
"output_1": np.random.random(100).astype(np.float32),
}

Expand All @@ -65,7 +66,7 @@ def test_filter_candidates_with_triton(tmpdir):
]
)

candidate_ids = np.random.randint(1, 100000, 100).astype(np.int32)
candidate_ids = np.array(random.sample(range(100000), 100), dtype=np.int32)
movie_ids_1 = np.zeros(100, dtype=np.int32)
movie_ids_1[:20] = np.unique(candidate_ids)[:20]

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/systems/dag/test_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import random

import numpy as np

from merlin.dag.executors import LocalExecutor
Expand All @@ -30,7 +32,7 @@ def test_ensemble_save_load(tmpdir):
]
)

candidate_ids = np.random.randint(1, 100000, 100).astype(np.int32)
candidate_ids = np.array(random.sample(range(100000), 100), dtype=np.int32)
movie_ids_1 = np.zeros(100, dtype=np.int32)
movie_ids_1[:20] = np.unique(candidate_ids)[:20]

Expand Down
7 changes: 4 additions & 3 deletions tests/unit/systems/dag/test_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import random
from distutils.spawn import find_executable

import numpy as np
Expand All @@ -38,7 +39,7 @@ def test_run_dag_on_dictarray_with_local_executor():
]
)

candidate_ids = np.random.randint(1, 100000, 100).astype(np.int32)
candidate_ids = np.array(random.sample(range(100000), 100), dtype=np.int32)
movie_ids_1 = np.zeros(100, dtype=np.int32)
movie_ids_1[:20] = np.unique(candidate_ids)[:20]

Expand Down Expand Up @@ -72,7 +73,7 @@ def test_run_dag_on_dataframe_with_local_executor():
]
)

candidate_ids = np.random.randint(1, 100000, 100).astype(np.int32)
candidate_ids = np.array(random.sample(range(100000), 100), dtype=np.int32)
movie_ids_1 = np.zeros(100, dtype=np.int32)
movie_ids_1[:20] = np.unique(candidate_ids)[:20]

Expand Down Expand Up @@ -105,7 +106,7 @@ def test_run_dag_on_dataframe_with_dask_executor():
]
)

candidate_ids = np.random.randint(1, 100000, 100).astype(np.int32)
candidate_ids = np.array(random.sample(range(100000), 100), dtype=np.int32)
movie_ids_1 = np.zeros(100, dtype=np.int32)
movie_ids_1[:20] = np.unique(candidate_ids)[:20]

Expand Down

0 comments on commit 5c6746f

Please sign in to comment.