def test_properties(nps_app_inst): import nums.numpy as nps assert nps_app_inst is not None A: BlockArray = nps.random.randn(10, 20, 1) assert A.shape == nps.shape(A) assert A.size == nps.size(A) assert A.ndim == nps.ndim(A) assert A.squeeze().shape == nps.squeeze(A).shape assert nps.allclose(A.T, nps.transpose(A)) A_copy = nps.copy(A) assert A_copy is not A
def test_modin(nps_app_inst): import nums import nums.numpy as nps import modin.pandas as mpd from nums.core import settings from nums.core.systems.systems import RaySystem if not isinstance(nps_app_inst.cm.system, RaySystem): return filename = settings.pj(settings.project_root, "tests", "core", "storage", "test.csv") ba1 = nums.read_csv(filename, has_header=True) df = mpd.read_csv(filename) ba2: BlockArray = nums.from_modin(df) assert nps.allclose(ba1, ba2)
def test_reshape(nps_app_inst): import nums.numpy as nps assert nps_app_inst is not None ba = nps.arange(2*3*4).reshape((2, 3, 4), block_shape=(2, 3, 4)) assert nps.allclose(ba.reshape(shape=(6, 4), block_shape=(6, 4)), nps.reshape(ba, shape=(6, 4)))
def test_array_eq(nps_app_inst): import nums.numpy as nps assert nps_app_inst is not None int_array_1 = np.array([[1, 2, 3], [4, 5, 6]]) int_array_2 = np.array([[3, 9, 1], [8, 4, 2]]) bool_array_1 = np.array([[True, False, True], [True, False, True]]) bool_array_2 = np.array([[False, False, True], [False, False, True]]) float_array_1 = np.array([[1e10, 1e-8, 1e-8], [1e10, 1e-8, 1e-8]]) float_array_2 = np.array([[1.00001e10, 1e-9, 1e-9], [1.00001e10, 1e-9, 1e-9]]) checks = [ (int_array_1, int_array_2), (bool_array_1, bool_array_2), (float_array_1, float_array_2), ] for check in checks: nps_array_1 = nps.array(check[0]).reshape(block_shape=(2, 2)) nps_array_2 = nps.array(check[1]).reshape(block_shape=(2, 2)) assert nps.array_equal(nps_array_1, nps_array_1).get() == np.array_equal( check[0], check[0]) assert nps.array_equal(nps_array_1, nps_array_2).get() == np.array_equal( check[0], check[1]) assert nps.array_equiv(nps_array_1, nps_array_1).get() == np.array_equiv( check[0], check[0]) assert nps.array_equiv(nps_array_1, nps_array_2).get() == np.array_equiv( check[0], check[1]) assert nps.allclose(nps_array_1, nps_array_1).get() == np.allclose( check[0], check[0]) assert nps.allclose(nps_array_1, nps_array_2).get() == np.allclose( check[0], check[1]) assert nps.array_equal(nps_array_1, nps_array_2).dtype is bool assert nps.array_equiv(nps_array_1, nps_array_2).dtype is bool assert nps.allclose(nps_array_1, nps_array_2).dtype is bool # False interaction test checks_1 = [ np.array([False]), np.array([False]), np.array([0]), np.array([0]), np.array([0.0]), np.array([0.0]), ] checks_2 = [ np.array([0]), np.array([0.0]), np.array([False]), np.array([0.0]), np.array([False]), np.array([0]), ] for check_1, check_2 in zip(checks_1, checks_2): nps_check_1 = nps.array(check_1) nps_check_2 = nps.array(check_2) assert nps.array_equal(nps_check_1, nps_check_2) == np.array_equal( check_1, check_2) assert nps.array_equiv(nps_check_1, nps_check_2) == np.array_equiv( check_1, check_2) # Infinity interaction test assert nps.array_equal(nps.array([nps.inf, nps.NINF]), nps.array([nps.NINF, nps.inf])) == np.array_equal( np.array([np.inf, np.NINF]), np.array([np.NINF, np.inf]))