8000 reorganized npfuncs.py and ufuncs.py · larray-project/larray@5d2ab01 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d2ab01

Browse files
committed
reorganized npfuncs.py and ufuncs.py
1 parent 02aca3e commit 5d2ab01

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

larray/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
from larray.core.session import Session, local_arrays, global_arrays, arrays
1313
from larray.core.constants import nan, inf, pi, e, euler_gamma
1414
from larray.core.metadata import Metadata
15-
from larray.core.npfuncs import (where, clip, degrees, radians, unwrap, angle, real, imag,
16-
round, around, round_, fix, i0, sinc, convolve, nan_to_num,
17-
real_if_close, inverse, interp, )
15+
from larray.core.npfuncs import (round, around, round_, where, inverse, i0, sinc, clip,
16+
angle, real, imag, convolve, nan_to_num, real_if_close, interp)
1817
from larray.core.ufuncs import (sin, cos, tan, arcsin, arccos, arctan, hypot, arctan2, sinh, cosh,
1918
tanh, arcsinh, arccosh, arctanh, conj, rint, floor, ceil, trunc,
2019
exp, expm1, exp2, log, log10, log2, log1p, logaddexp, logaddexp2,
2120
signbit, copysign, frexp, ldexp, sqrt, absolute, fabs, sign,
22-
fmax, fmin, isnan, isinf, maximum, minimum)
21+
fmax, fmin, isnan, isinf, maximum, minimum, degrees, radians,
22+
unwrap, fix)
2323

2424
from larray.inout.misc import from_lists, from_string
2525
from larray.inout.pandas import from_frame, from_series
@@ -58,14 +58,13 @@
5858
'maximum', 'minimum',
5959
'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'hypot', 'arctan2', 'degrees', 'radians',
6060
'unwrap', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh',
61-
'angle', 'real', 'imag', 'conj',
62-
'round', 'around', 'round_', 'rint', 'fix', 'floor', 'ceil', 'trunc',
63-
'exp', 'expm1', 'exp2', 'log', 'log10', 'log2', 'log1p', 'logaddexp', 'logaddexp2',
64-
'i0', 'sinc', 'signbit', 'copysign', 'frexp', 'ldexp',
65-
'convolve', 'sqrt', 'absolute', 'fabs', 'sign', 'fmax', 'fmin', 'nan_to_num',
66-
'real_if_close', 'interp', 'isnan', 'isinf', 'inverse',
61+
'conj', 'rint', 'fix', 'floor', 'ceil', 'trunc', 'exp', 'expm1', 'exp2',
62+
'log', 'log10', 'log2', 'log1p', 'logaddexp', 'logaddexp2',
63+
'signbit', 'copysign', 'frexp', 'ldexp', 'sqrt', 'absolute', 'fabs',
64+
'sign', 'fmax', 'fmin', 'isnan', 'isinf',
6765
# npfuncs
68-
'where', 'clip',
66+
'round', 'around', 'round_', 'where', 'inverse', 'i0', 'sinc', 'angle', 'real', 'imag',
67+
'convolve', 'nan_to_num', 'real_if_close', 'interp', 'clip',
6968
# inout
7069
'from_lists', 'from_string', 'from_frame', 'from_series', 'read_csv', 'read_tsv',
7170
'read_eurostat', 'read_excel', 'read_hdf', 'read_sas', 'open_excel', 'Workbook',

larray/core/npfuncs.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# numpy ufuncs -- this module is excluded from pytest
2-
# http://docs.scipy.org/doc/numpy/reference/routines.math.html
1+
# numpy funcs which are not ufuncs -- this module is excluded from pytest
32

43
import numpy as np
54

@@ -14,25 +13,13 @@ def wrapper(*args, **kwargs):
1413
_copy_npfunc_doc(wrapper, npfunc)
1514
return wrapper
1615

17-
# Trigonometric functions
18-
19-
degrees = broadcastify(np.degrees)
20-
radians = broadcastify(np.radians)
21-
unwrap = broadcastify(np.unwrap)
22-
23-
# Handling complex numbers
24-
25-
angle = broadcastify(np.angle)
26-
real = broadcastify(np.real)
27-
imag = broadcastify(np.imag)
2816

2917
# Rounding
3018

3119
# all 3 are equivalent, I am unsure I should support around and round_
32-
round = broadcastify(np.round)
3320
around = broadcastify(np.around)
3421
round_ = broadcastify(np.round_)
35-
fix = broadcastify(np.fix)
22+
round = broadcastify(np.round)
3623

3724
# Sums, products, differences
3825

@@ -50,14 +37,22 @@ def wrapper(*args, **kwargs):
5037
# cross = broadcastify(np.cross)
5138
# trapz = broadcastify(np.trapz)
5239

53-
5440
# Other special functions
5541

5642
i0 = broadcastify(np.i0)
5743
sinc = broadcastify(np.sinc)
5844

45+
# Handling complex numbers
46+
47+
angle = broadcastify(np.angle)
48+
real = broadcastify(np.real)
49+
imag = broadcastify(np.imag)
50+
5951
# Miscellaneous
6052

53+
# put clip here even it is a ufunc because it ends up within a recursion loop with LArray.clip
54+
clip = broadcastify(np.clip)
55+
6156
where = broadcastify(np.where, copy_doc=False)
6257
where.__doc__ = r"""
6358
Return elements, either from `x` or `y`, depending on `condition`.
@@ -116,10 +111,9 @@ def wrapper(*args, **kwargs):
116111
a3 9.0 10.0 5.0 7.75
117112
"""
118113

119-
clip = broadcastify(np.clip)
120-
convolve = broadcastify(np.convolve)
121114
nan_to_num = broadcastify(np.nan_to_num)
122115
real_if_close = broadcastify(np.real_if_close)
116+
convolve = broadcastify(np.convolve)
123117
inverse = broadcastify(np.linalg.inv)
124118

125119
# XXX: create a new LArray method instead ?

larray/core/ufuncs.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# numpy ufuncs
1+
# numpy ufuncs -- this module is excluded from pytest
22
# http://docs.scipy.org/doc/numpy/reference/routines.math.html
3+
# https://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs
34

45
import numbers
56

@@ -114,22 +115,6 @@ def wrapper(*args, **kwargs):
114115
# list of available Numpy ufuncs
115116
# https://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs
116117

117-
# Arithmetic operations
118-
119-
# add = make_ufunc_shortcut(np.add)
120-
# reciprocal = make_ufunc_shortcut(np.reciprocal)
121-
# negative = make_ufunc_shortcut(np.negative)
122-
# multiply = make_ufunc_shortcut(np.multiply)
123-
# divide = make_ufunc_shortcut(np.divide)
124-
# power = make_ufunc_shortcut(np.power)
125-
# subtract = make_ufunc_shortcut(np.subtract)
126-
# true_divide = make_ufunc_shortcut(np.true_divide)
127-
# floor_divide = make_ufunc_shortcut(np.floor_divide)
128-
# fmod = make_ufunc_shortcut(np.fmod)
129-
# mod = make_ufunc_shortcut(np.mod)
130-
# remainder = make_ufunc_shortcut(np.remainder)
131-
# square = make_ufunc_shortcut(np.square)
132-
133118
# Trigonometric functions
134119

135120
sin = make_ufunc_shortcut(np.sin)
@@ -140,6 +125,9 @@ def wrapper(*args, **kwargs):
140125
arctan = make_ufunc_shortcut(np.arctan)
141126
arctan2 = make_ufunc_shortcut(np.arctan2)
142127
hypot = make_ufunc_shortcut(np.hypot)
128+
degrees = make_ufunc_shortcut(np.degrees)
129+
radians = make_ufunc_shortcut(np.radians)
130+
unwrap = make_ufunc_shortcut(np.unwrap)
143131
# deg2rad = make_ufunc_shortcut(np.deg2rad)
144132
# rad2deg = make_ufunc_shortcut(np.rad2deg)
145133

@@ -155,20 +143,12 @@ def wrapper(*args, **kwargs):
155143
# Rounding
156144

157145
rint = make_ufunc_shortcut(np.rint)
158-
159-
# Floating functions
160-
161-
isnan = make_ufunc_shortcut(np.isnan)
162-
isinf = make_ufunc_shortcut(np.isinf)
163-
signbit = make_ufunc_shortcut(np.signbit)
164-
copysign = make_ufunc_shortcut(np.copysign)
165-
ldexp = make_ufunc_shortcut(np.ldexp)
166-
frexp = make_ufunc_shortcut(np.frexp)
146+
# TODO: fix fails because of its 'out' argument
147+
fix = make_ufunc_shortcut(np.fix)
167148
# TODO: add examples for round, floor, ceil and trunc
168149
floor = make_ufunc_shortcut(np.floor)
169150
ceil = make_ufunc_shortcut(np.ceil)
170151
trunc = make_ufunc_shortcut(np.trunc)
171-
# modf = make_ufunc_shortcut(np.modf)
172152

173153
# Exponents and logarithms
174154

@@ -183,18 +163,43 @@ def wrapper(*args, **kwargs):
183163
logaddexp = make_ufunc_shortcut(np.logaddexp)
184164
logaddexp2 = make_ufunc_shortcut(np.logaddexp2)
185165

166+
# Floating functions
167+
168+
signbit = make_ufunc_shortcut(np.signbit)
169+
copysign = make_ufunc_shortcut(np.copysign)
170+
# TODO: understand why frexp fails
171+
frexp = make_ufunc_shortcut(np.frexp)
172+
ldexp = make_ufunc_shortcut(np.ldexp)
173+
174+
# Arithmetic operations
175+
176+
# add = make_ufunc_shortcut(np.add)
177+
# reciprocal = make_ufunc_shortcut(np.reciprocal)
178+
# positive = make_ufunc_shortcut(np.positive)
179+
# negative = make_ufunc_shortcut(np.negative)
180+
# multiply = make_ufunc_shortcut(np.multiply)
181+
# divide = make_ufunc_shortcut(np.divide)
182+
# power = make_ufunc_shortcut(np.power)
183+
# subtract = make_ufunc_shortcut(np.subtract)
184+
# true_divide = make_ufunc_shortcut(np.true_divide)
185+
# floor_divide = make_ufunc_shortcut(np.floor_divide)
186+
# fmod = make_ufunc_shortcut(np.fmod)
187+
# mod = make_ufunc_shortcut(np.mod)
188+
# modf = make_ufunc_shortcut(np.modf)
189+
# remainder = make_ufunc_shortcut(np.remainder)
190+
# divmod = make_ufunc_shortcut(np.divmod)
191+
186192
# Handling complex numbers
187193

188194
conj = make_ufunc_shortcut(np.conj)
189195

190196
# Miscellaneous
191197

192198
sqrt = make_ufunc_shortcut(np.sqrt)
199+
square = make_ufunc_shortcut(np.square)
193200
absolute = make_ufunc_shortcut(np.absolute)
194201
fabs = make_ufunc_shortcut(np.fabs)
195202
sign = make_ufunc_shortcut(np.sign)
196-
fmax = make_ufunc_shortcut(np.fmax)
197-
fmin = make_ufunc_shortcut(np.fmin)
198203

199204

200205
def maximum(x1, x2, out=None, dtype=None):
@@ -336,3 +341,7 @@ def minimum(x1, x2, out=None, dtype=None):
336341
"""
337342
return np.minimum(x1, x2, out=out, dtype=dtype)
338343

344+
fmax = make_ufunc_shortcut(np.fmax)
345+
fmin = make_ufunc_shortcut(np.fmin)
346+
isnan = make_ufunc_shortcut(np.isnan)
347+
isinf = make_ufunc_shortcut(np.isinf)

0 commit comments

Comments
 (0)
0