99
1010def test (dtype ):
1111 rng = np .random .default_rng ()
12- mat = np .array ( np . ones ((rows , cols )). astype ( np . int32 ), dtype = dtype )
12+ mat = np .ones ((rows , cols ), dtype = dtype )
1313 mat = rng .random ((rows , cols )).astype (dtype )
1414 mat_copy = mat .copy ()
1515 assert (mat == mat_copy ).all ()
@@ -44,6 +44,11 @@ def test(dtype):
4444 mat2 = np .matmul (mat , mat .T )
4545 assert np .isclose (mat2 .astype (np .double ), mat2_ref ).all ()
4646
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
51+
4752
4853def test_cast (from_dtype , to_dtype ):
4954 np .can_cast (from_dtype , to_dtype )
@@ -63,8 +68,17 @@ def test_cast(from_dtype, to_dtype):
6368test_cast (user_type .CustomDouble , np .int32 )
6469test_cast (np .int32 , user_type .CustomDouble )
6570
66- test (user_type .CustomFloat )
67-
6871v = user_type .CustomDouble (1 )
6972a = np .array (v )
7073assert type (v ) is a .dtype .type
74+
75+ test (user_type .CustomFloat )
76+
77+ test_cast (user_type .CustomFloat , np .float32 )
78+ test_cast (np .double , user_type .CustomFloat )
79+
80+ test_cast (user_type .CustomFloat , np .int64 )
81+ test_cast (np .int64 , user_type .CustomFloat )
82+
83+ test_cast (user_type .CustomFloat , np .int32 )
84+ test_cast (np .int32 , user_type .CustomFloat )
0 commit comments