Skip to content

Commit f2d8f1d

Browse files
authored
Add direct imports from NumPy for Array API support (#624)
1 parent 51e6133 commit f2d8f1d

File tree

2 files changed

+307
-1
lines changed

2 files changed

+307
-1
lines changed

sparse/__init__.py

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
1+
from numpy import (
2+
add,
3+
bitwise_and,
4+
bitwise_not,
5+
bitwise_or,
6+
bitwise_xor,
7+
can_cast,
8+
ceil,
9+
complex64,
10+
complex128,
11+
cos,
12+
cosh,
13+
divide,
14+
e,
15+
exp,
16+
expm1,
17+
finfo,
18+
float16,
19+
float32,
20+
float64,
21+
floor,
22+
floor_divide,
23+
greater,
24+
greater_equal,
25+
iinfo,
26+
inf,
27+
int8,
28+
int16,
29+
int32,
30+
int64,
31+
less,
32+
less_equal,
33+
log,
34+
log1p,
35+
log2,
36+
log10,
37+
logaddexp,
38+
logical_and,
39+
logical_not,
40+
logical_or,
41+
logical_xor,
42+
multiply,
43+
nan,
44+
negative,
45+
newaxis,
46+
not_equal,
47+
pi,
48+
positive,
49+
remainder,
50+
sign,
51+
sin,
52+
sinh,
53+
sqrt,
54+
square,
55+
subtract,
56+
tan,
57+
tanh,
58+
trunc,
59+
uint8,
60+
uint16,
61+
uint32,
62+
uint64,
63+
)
64+
from numpy import arccos as acos
65+
from numpy import arccosh as acosh
66+
from numpy import arcsin as asin
67+
from numpy import arcsinh as asinh
68+
from numpy import arctan as atan
69+
from numpy import arctan2 as atan2
70+
from numpy import arctanh as atanh
71+
from numpy import bool_ as bool
72+
from numpy import invert as bitwise_invert
73+
from numpy import left_shift as bitwise_left_shift
74+
from numpy import power as pow
75+
from numpy import right_shift as bitwise_right_shift
76+
177
from ._common import (
278
SparseArray,
379
abs,
@@ -82,6 +158,9 @@
82158
"GCXS",
83159
"SparseArray",
84160
"abs",
161+
"acos",
162+
"acosh",
163+
"add",
85164
"all",
86165
"any",
87166
"argmax",
@@ -90,63 +169,132 @@
90169
"asCOO",
91170
"as_coo",
92171
"asarray",
172+
"asin",
173+
"asinh",
93174
"asnumpy",
94175
"astype",
176+
"atan",
177+
"atan2",
178+
"atanh",
179+
"bitwise_and",
180+
"bitwise_invert",
181+
"bitwise_left_shift",
182+
"bitwise_not",
183+
"bitwise_or",
184+
"bitwise_right_shift",
185+
"bitwise_xor",
186+
"bool",
95187
"broadcast_arrays",
96188
"broadcast_to",
189+
"can_cast",
190+
"ceil",
97191
"clip",
192+
"complex128",
193+
"complex64",
98194
"concat",
99195
"concatenate",
196+
"cos",
197+
"cosh",
100198
"diagonal",
101199
"diagonalize",
200+
"divide",
102201
"dot",
202+
"e",
103203
"einsum",
104204
"elemwise",
105205
"empty",
106206
"empty_like",
107207
"equal",
208+
"exp",
209+
"expm1",
108210
"eye",
211+
"finfo",
212+
"float16",
213+
"float32",
214+
"float64",
215+
"floor",
216+
"floor_divide",
109217
"full",
110218
"full_like",
219+
"greater",
220+
"greater_equal",
221+
"iinfo",
222+
"inf",
223+
"int16",
224+
"int32",
225+
"int64",
226+
"int8",
111227
"isfinite",
112228
"isinf",
113229
"isnan",
114230
"isneginf",
115231
"isposinf",
116232
"kron",
233+
"less",
234+
"less_equal",
117235
"load_npz",
236+
"log",
237+
"log10",
238+
"log1p",
239+
"log2",
240+
"logaddexp",
241+
"logical_and",
242+
"logical_not",
243+
"logical_or",
244+
"logical_xor",
118245
"matmul",
119246
"max",
120247
"mean",
121248
"min",
122249
"moveaxis",
123-
"moveaxis",
250+
"multiply",
251+
"nan",
124252
"nanmax",
125253
"nanmean",
126254
"nanmin",
127255
"nanprod",
128256
"nanreduce",
129257
"nansum",
258+
"negative",
259+
"newaxis",
130260
"nonzero",
261+
"not_equal",
131262
"ones",
132263
"ones_like",
133264
"outer",
134265
"pad",
135266
"permute_dims",
267+
"pi",
268+
"positive",
269+
"pow",
136270
"prod",
137271
"random",
272+
"remainder",
138273
"reshape",
139274
"result_type",
140275
"roll",
141276
"round",
142277
"save_npz",
278+
"sign",
279+
"sin",
280+
"sinh",
281+
"sqrt",
282+
"square",
143283
"squeeze",
144284
"stack",
145285
"std",
286+
"subtract",
146287
"sum",
288+
"tan",
289+
"tanh",
147290
"tensordot",
148291
"tril",
149292
"triu",
293+
"trunc",
294+
"uint16",
295+
"uint32",
296+
"uint64",
297+
"uint8",
150298
"unique_counts",
151299
"unique_values",
152300
"where",

sparse/tests/test_namespace.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import sparse
2+
3+
4+
def test_namespace():
5+
assert set(sparse.__all__) == {
6+
"COO",
7+
"DOK",
8+
"GCXS",
9+
"SparseArray",
10+
"abs",
11+
"acos",
12+
"acosh",
13+
"add",
14+
"all",
15+
"any",
16+
"argmax",
17+
"argmin",
18+
"argwhere",
19+
"asCOO",
20+
"as_coo",
21+
"asarray",
22+
"asin",
23+
"asinh",
24+
"asnumpy",
25+
"astype",
26+
"atan",
27+
"atan2",
28+
"atanh",
29+
"bitwise_and",
30+
"bitwise_invert",
31+
"bitwise_left_shift",
32+
"bitwise_not",
33+
"bitwise_or",
34+
"bitwise_right_shift",
35+
"bitwise_xor",
36+
"bool",
37+
"broadcast_arrays",
38+
"broadcast_to",
39+
"can_cast",
40+
"ceil",
41+
"clip",
42+
"complex128",
43+
"complex64",
44+
"concat",
45+
"concatenate",
46+
"cos",
47+
"cosh",
48+
"diagonal",
49+
"diagonalize",
50+
"divide",
51+
"dot",
52+
"e",
53+
"einsum",
54+
"elemwise",
55+
"empty",
56+
"empty_like",
57+
"equal",
58+
"exp",
59+
"expm1",
60+
"eye",
61+
"finfo",
62+
"float16",
63+
"float32",
64+
"float64",
65+
"floor",
66+
"floor_divide",
67+
"full",
68+
"full_like",
69+
"greater",
70+
"greater_equal",
71+
"iinfo",
72+
"inf",
73+
"int16",
74+
"int32",
75+
"int64",
76+
"int8",
77+
"isfinite",
78+
"isinf",
79+
"isnan",
80+
"isneginf",
81+
"isposinf",
82+
"kron",
83+
"less",
84+
"less_equal",
85+
"load_npz",
86+
"log",
87+
"log10",
88+
"log1p",
89+
"log2",
90+
"logaddexp",
91+
"logical_and",
92+
"logical_not",
93+
"logical_or",
94+
"logical_xor",
95+
"matmul",
96+
"max",
97+
"mean",
98+
"min",
99+
"moveaxis",
100+
"multiply",
101+
"nan",
102+
"nanmax",
103+
"nanmean",
104+
"nanmin",
105+
"nanprod",
106+
"nanreduce",
107+
"nansum",
108+
"negative",
109+
"newaxis",
110+
"nonzero",
111+
"not_equal",
112+
"ones",
113+
"ones_like",
114+
"outer",
115+
"pad",
116+
"permute_dims",
117+
"pi",
118+
"positive",
119+
"pow",
120+
"prod",
121+
"random",
122+
"remainder",
123+
"reshape",
124+
"result_type",
125+
"roll",
126+
"round",
127+
"save_npz",
128+
"sign",
129+
"sin",
130+
"sinh",
131+
"sqrt",
132+
"square",
133+
"squeeze",
134+
"stack",
135+
"std",
136+
"subtract",
137+
"sum",
138+
"tan",
139+
"tanh",
140+
"tensordot",
141+
"tril",
142+
"triu",
143+
"trunc",
144+
"uint16",
145+
"uint32",
146+
"uint64",
147+
"uint8",
148+
"unique_counts",
149+
"unique_values",
150+
"where",
151+
"zeros",
152+
"zeros_like",
153+
}
154+
155+
for attr in sparse.__all__:
156+
assert hasattr(sparse, attr)
157+
158+
assert sorted(sparse.__all__) == sparse.__all__

0 commit comments

Comments
 (0)