From 20b41e727cb5f0711283dee7eed2553beba40c26 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:18:53 +0000 Subject: [PATCH 1/2] Initial plan From 30ca579132be34bac0219e23c47890cd497cc42b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:24:51 +0000 Subject: [PATCH 2/2] Add random_matrix utility function for creating random 2D matrices Co-authored-by: mplilly4395 <131011896+mplilly4395@users.noreply.github.com> --- pyscan/general/__init__.py | 1 + pyscan/general/random_matrix.py | 21 +++++++++++++++++ test/test_general/test_random_matrix.py | 31 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 pyscan/general/random_matrix.py create mode 100644 test/test_general/test_random_matrix.py diff --git a/pyscan/general/__init__.py b/pyscan/general/__init__.py index 4efd018d..5958fa4f 100644 --- a/pyscan/general/__init__.py +++ b/pyscan/general/__init__.py @@ -7,3 +7,4 @@ from .same_length import same_length from .set_difference import set_difference from .append_stack_or_contact import append_stack_or_contact +from .random_matrix import random_matrix diff --git a/pyscan/general/random_matrix.py b/pyscan/general/random_matrix.py new file mode 100644 index 00000000..91e92fe2 --- /dev/null +++ b/pyscan/general/random_matrix.py @@ -0,0 +1,21 @@ +import numpy as np + + +def random_matrix(rows, cols): + ''' + Creates a matrix with random numbers between 0 and 1. + + Parameters + ---------- + rows : int + Number of rows in the matrix. + cols : int + Number of columns in the matrix. + + Returns + ------- + numpy.ndarray + A matrix of shape (rows, cols) with random values between 0 and 1. + ''' + + return np.random.rand(rows, cols) diff --git a/test/test_general/test_random_matrix.py b/test/test_general/test_random_matrix.py new file mode 100644 index 00000000..a39f642e --- /dev/null +++ b/test/test_general/test_random_matrix.py @@ -0,0 +1,31 @@ +import pyscan as ps +import numpy as np + + +def test_random_matrix_shape(): + """Test that random_matrix returns the correct shape""" + matrix = ps.random_matrix(1000, 2) + assert matrix.shape == (1000, 2), f"Expected shape (1000, 2), got {matrix.shape}" + + +def test_random_matrix_values_in_range(): + """Test that all values are between 0 and 1""" + matrix = ps.random_matrix(1000, 2) + assert np.all(matrix >= 0), "Some values are less than 0" + assert np.all(matrix <= 1), "Some values are greater than 1" + + +def test_random_matrix_different_sizes(): + """Test random_matrix with various sizes""" + for rows, cols in [(1, 1), (5, 3), (100, 50), (1000, 2)]: + matrix = ps.random_matrix(rows, cols) + assert matrix.shape == (rows, cols), f"Expected shape ({rows}, {cols}), got {matrix.shape}" + assert np.all(matrix >= 0) and np.all(matrix <= 1), "Values not in [0, 1] range" + + +def test_random_matrix_is_random(): + """Test that random_matrix produces different results on successive calls""" + matrix1 = ps.random_matrix(100, 100) + matrix2 = ps.random_matrix(100, 100) + # It's extremely unlikely that two random matrices would be identical + assert not np.array_equal(matrix1, matrix2), "Two successive calls produced identical matrices"