@@ -27,6 +27,58 @@ def testvov():
2727 return VovColl (v2d , v3d , v4d )
2828
2929
30+ def test_nb_fill ():
31+ # test 1d array of int
32+ aoa_in = np .arange (5 , dtype = "int32" ).reshape (1 , 5 )
33+ len_in = np .array ([5 ])
34+ nan_val = np .array ([0 ], dtype = aoa_in .dtype )
35+ flattened_array_out = np .empty (5 , dtype = aoa_in .dtype )
36+
37+ vovutils ._nb_fill (aoa_in , len_in , nan_val , flattened_array_out )
38+ assert np .array_equal (
39+ flattened_array_out , np .array ([0 , 1 , 2 , 3 , 4 ], dtype = aoa_in .dtype )
40+ )
41+ # test 1d array of uint
42+ aoa_in = np .arange (5 , dtype = "uint16" ).reshape (1 , 5 )
43+ len_in = np .array ([5 ])
44+ nan_val = np .array ([0 ], dtype = aoa_in .dtype )
45+ flattened_array_out = np .empty (5 , dtype = aoa_in .dtype )
46+
47+ vovutils ._nb_fill (aoa_in , len_in , nan_val , flattened_array_out )
48+ assert np .array_equal (
49+ flattened_array_out , np .array ([0 , 1 , 2 , 3 , 4 ], dtype = aoa_in .dtype )
50+ )
51+ # test 1d array of float
52+ aoa_in = np .arange (5 , dtype = "float32" ).reshape (1 , 5 )
53+ len_in = np .array ([5 ])
54+ nan_val = np .array ([0 ], dtype = aoa_in .dtype )
55+ flattened_array_out = np .empty (5 , dtype = aoa_in .dtype )
56+
57+ vovutils ._nb_fill (aoa_in , len_in , nan_val , flattened_array_out )
58+ assert np .array_equal (
59+ flattened_array_out , np .array ([0 , 1 , 2 , 3 , 4 ], dtype = aoa_in .dtype )
60+ )
61+ # test 2d array of int
62+ aoa_in = np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ]], dtype = "int32" )
63+ len_in = np .array ([3 , 3 ])
64+ nan_val = np .array ([0 ], dtype = aoa_in .dtype )
65+ flattened_array_out = np .empty (6 , dtype = aoa_in .dtype )
66+ vovutils ._nb_fill (aoa_in , len_in , nan_val , flattened_array_out )
67+ assert np .array_equal (
68+ flattened_array_out ,
69+ np .array ([1 , 2 , 3 , 4 , 5 , 6 ], dtype = aoa_in .dtype ),
70+ )
71+ # test nan value addition
72+ aoa_in = np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ]], dtype = "int32" )
73+ len_in = np .array ([4 , 3 ])
74+ flattened_array_out = np .empty (7 , dtype = aoa_in [0 ].dtype )
75+ vovutils ._nb_fill (aoa_in , len_in , nan_val , flattened_array_out )
76+ assert np .array_equal (
77+ flattened_array_out ,
78+ np .array ([1 , 2 , 3 , 0 , 4 , 5 , 6 ], dtype = aoa_in [0 ].dtype ),
79+ )
80+
81+
3082def test_ak_input_validity (testvov ):
3183 for v in testvov :
3284 assert vovutils ._ak_is_jagged (v ) is True
0 commit comments