11 rng = np.random.default_rng()
12 mat = np.ones((rows, cols), dtype=dtype)
13 mat = rng.random((rows, cols)).astype(dtype)
15 assert (mat == mat_copy).all()
16 assert not (mat != mat_copy).all()
26 mat_op = mat.copy(order=
"F") + mat.copy(order=
"C")
30 mat_op = mat.dot(mat.T)
35 assert (mat >= mat).all()
36 assert (mat <= mat).all()
37 assert not (mat > mat).all()
38 assert not (mat < mat).all()
41 mat2_ref = mat.astype(np.double).dot(mat.T.astype(np.double))
42 assert np.isclose(mat2.astype(np.double), mat2_ref).all()
43 if np.__version__ >=
"1.17.0":
44 mat2 = np.matmul(mat, mat.T)
45 assert np.isclose(mat2.astype(np.double), mat2_ref).all()
47 vec = np.ones((rows,), dtype=dtype)
48 norm = np.linalg.norm(vec)
49 norm_ref = np.linalg.norm(vec.astype(np.double))
50 assert norm == norm_ref
54 np.can_cast(from_dtype, to_dtype)
56 from_mat = np.zeros((rows, cols), dtype=from_dtype)
57 to_mat = from_mat.astype(dtype=to_dtype)
60 test(user_type.CustomDouble)
62 test_cast(user_type.CustomDouble, np.double)
63 test_cast(np.double, user_type.CustomDouble)
65 test_cast(user_type.CustomDouble, np.int64)
66 test_cast(np.int64, user_type.CustomDouble)
68 test_cast(user_type.CustomDouble, np.int32)
69 test_cast(np.int32, user_type.CustomDouble)
71 v = user_type.CustomDouble(1)
73 assert type(v)
is a.dtype.type
75 test(user_type.CustomFloat)
77 test_cast(user_type.CustomFloat, np.float32)
78 test_cast(np.double, user_type.CustomFloat)
80 test_cast(user_type.CustomFloat, np.int64)
81 test_cast(np.int64, user_type.CustomFloat)
83 test_cast(user_type.CustomFloat, np.int32)
84 test_cast(np.int32, user_type.CustomFloat)