|
| 1 | +# numpy ufuncs -- this module is excluded from pytest |
| 2 | +# http://docs.scipy.org/doc/numpy/reference/routines.math.html |
| 3 | + |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from larray.core.ufuncs import broadcastify |
| 7 | + |
| 8 | + |
| 9 | +__all__ = [ |
| 10 | + # Trigonometric functions |
| 11 | + 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'hypot', 'arctan2', 'degrees', 'radians', 'unwrap', |
| 12 | + # 'deg2rad', 'rad2deg', |
| 13 | + |
| 14 | + # Hyperbolic functions |
| 15 | + 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh', |
| 16 | + |
| 17 | + # Rounding |
| 18 | + 'round', 'around', 'round_', 'rint', 'fix', 'floor', 'ceil', 'trunc', |
| 19 | + |
| 20 | + # Sums, products, differences |
| 21 | + # 'prod', 'sum', 'nansum', 'cumprod', 'cumsum', |
| 22 | + |
| 23 | + # cannot use a simple wrapped ufunc because those ufuncs do not preserve shape or dimensions so labels are wrong |
| 24 | + # 'diff', 'ediff1d', 'gradient', 'cross', 'trapz', |
| 25 | + |
| 26 | + # Exponents and logarithms |
| 27 | + 'exp', 'expm1', 'exp2', 'log', 'log10', 'log2', 'log1p', 'logaddexp', 'logaddexp2', |
| 28 | + |
| 29 | + # Other special functions |
| 30 | + 'i0', 'sinc', |
| 31 | + |
| 32 | + # Floating point routines |
| 33 | + 'signbit', 'copysign', 'frexp', 'ldexp', |
| 34 | + |
| 35 | + # Arithmetic operations |
| 36 | + # 'add', 'reciprocal', 'negative', 'multiply', 'divide', 'power', 'subtract', 'true_divide', 'floor_divide', |
| 37 | + # 'fmod', 'mod', 'modf', 'remainder', |
| 38 | + |
| 39 | + # Handling complex numbers |
| 40 | + 'angle', 'real', 'imag', 'conj', |
| 41 | + |
| 42 | + # Miscellaneous |
| 43 | + 'convolve', 'clip', 'sqrt', |
| 44 | + # 'square', |
| 45 | + 'absolute', 'fabs', 'sign', 'fmax', 'fmin', 'nan_to_num', 'real_if_close', |
| 46 | + 'interp', 'isnan', 'isinf', 'inverse', |
| 47 | +] |
| 48 | + |
| 49 | + |
| 50 | +# Trigonometric functions |
| 51 | + |
| 52 | +sin = broadcastify(np.sin) |
| 53 | +cos = broadcastify(np.cos) |
| 54 | +tan = broadcastify(np.tan) |
| 55 | +arcsin = broadcastify(np.arcsin) |
| 56 | +arccos = broadcastify(np.arccos) |
| 57 | +arctan = broadcastify(np.arctan) |
| 58 | +hypot = broadcastify(np.hypot) |
| 59 | +arctan2 = broadcastify(np.arctan2) |
| 60 | +degrees = broadcastify(np.degrees) |
| 61 | +radians = broadcastify(np.radians) |
| 62 | +unwrap = broadcastify(np.unwrap) |
| 63 | +# deg2rad = broadcastify(np.deg2rad) |
| 64 | +# rad2deg = broadcastify(np.rad2deg) |
| 65 | + |
| 66 | +# Hyperbolic functions |
| 67 | + |
| 68 | +sinh = broadcastify(np.sinh) |
| 69 | +cosh = broadcastify(np.cosh) |
| 70 | +tanh = broadcastify(np.tanh) |
| 71 | +arcsinh = broadcastify(np.arcsinh) |
| 72 | +arccosh = broadcastify(np.arccosh) |
| 73 | +arctanh = broadcastify(np.arctanh) |
| 74 | + |
| 75 | +# Rounding |
| 76 | + |
| 77 | +# TODO: add examples for round, floor, ceil and trunc |
| 78 | +# all 3 are equivalent, I am unsure I should support around and round_ |
| 79 | +round = broadcastify(np.round) |
| 80 | +around = broadcastify(np.around) |
| 81 | +round_ = broadcastify(np.round_) |
| 82 | +rint = broadcastify(np.rint) |
| 83 | +fix = broadcastify(np.fix) |
| 84 | +floor = broadcastify(np.floor) |
| 85 | +ceil = broadcastify(np.ceil) |
| 86 | +trunc = broadcastify(np.trunc) |
| 87 | + |
| 88 | +# Sums, products, differences |
| 89 | + |
| 90 | +# prod = broadcastify(np.prod) |
| 91 | +# sum = broadcastify(np.sum) |
| 92 | +# nansum = broadcastify(np.nansum) |
| 93 | +# cumprod = broadcastify(np.cumprod) |
| 94 | +# cumsum = broadcastify(np.cumsum) |
| 95 | + |
| 96 | +# cannot use a simple wrapped ufunc because those ufuncs do not preserve |
| 97 | +# shape or dimensions so labels are wrong |
| 98 | +# diff = broadcastify(np.diff) |
| 99 | +# ediff1d = broadcastify(np.ediff1d) |
| 100 | +# gradient = broadcastify(np.gradient) |
| 101 | +# cross = broadcastify(np.cross) |
| 102 | +# trapz = broadcastify(np.trapz) |
| 103 | + |
| 104 | +# Exponents and logarithms |
| 105 | + |
| 106 | +# TODO: add examples for exp and log |
| 107 | +exp = broadcastify(np.exp) |
| 108 | +expm1 = broadcastify(np.expm1) |
| 109 | +exp2 = broadcastify(np.exp2) |
| 110 | +log = broadcastify(np.log) |
| 111 | +log10 = broadcastify(np.log10) |
| 112 | +log2 = broadcastify(np.log2) |
| 113 | +log1p = broadcastify(np.log1p) |
| 114 | +logaddexp = broadcastify(np.logaddexp) |
| 115 | +logaddexp2 = broadcastify(np.logaddexp2) |
| 116 | + |
| 117 | +# Other special functions |
| 118 | + |
| 119 | +i0 = broadcastify(np.i0) |
| 120 | +sinc = broadcastify(np.sinc) |
| 121 | + |
| 122 | +# Floating point routines |
| 123 | + |
| 124 | +signbit = broadcastify(np.signbit) |
| 125 | +copysign = broadcastify(np.copysign) |
| 126 | +frexp = broadcastify(np.frexp) |
| 127 | +ldexp = broadcastify(np.ldexp) |
| 128 | + |
| 129 | +# Arithmetic operations |
| 130 | + |
| 131 | +# add = broadcastify(np.add) |
| 132 | +# reciprocal = broadcastify(np.reciprocal) |
| 133 | +# negative = broadcastify(np.negative) |
| 134 | +# multiply = broadcastify(np.multiply) |
| 135 | +# divide = broadcastify(np.divide) |
| 136 | +# power = broadcastify(np.power) |
| 137 | +# subtract = broadcastify(np.subtract) |
| 138 | +# true_divide = broadcastify(np.true_divide) |
| 139 | +# floor_divide = broadcastify(np.floor_divide) |
| 140 | +# fmod = broadcastify(np.fmod) |
| 141 | +# mod = broadcastify(np.mod) |
| 142 | +# modf = broadcastify(np.modf) |
| 143 | +# remainder = broadcastify(np.remainder) |
| 144 | + |
| 145 | +# Handling complex numbers |
| 146 | + |
| 147 | +angle = broadcastify(np.angle) |
| 148 | +real = broadcastify(np.real) |
| 149 | +imag = broadcastify(np.imag) |
| 150 | +conj = broadcastify(np.conj) |
| 151 | + |
| 152 | +# Miscellaneous |
| 153 | + |
| 154 | +convolve = broadcastify(np.convolve) |
| 155 | +clip = broadcastify(np.clip) |
| 156 | +# square = broadcastify(np.square) |
| 157 | +absolute = broadcastify(np.absolute) |
| 158 | +fabs = broadcastify(np.fabs) |
| 159 | +sign = broadcastify(np.sign) |
| 160 | +fmax = broadcastify(np.fmax) |
| 161 | +fmin = broadcastify(np.fmin) |
| 162 | +nan_to_num = broadcastify(np.nan_to_num) |
| 163 | +real_if_close = broadcastify(np.real_if_close) |
| 164 | + |
| 165 | +# TODO: add examples for functions below |
| 166 | +sqrt = broadcastify(np.sqrt) |
| 167 | +isnan = broadcastify(np.isnan) |
| 168 | +isinf = broadcastify(np.isinf) |
| 169 | +inverse = broadcastify(np.linalg.inv) |
| 170 | + |
| 171 | +# XXX: create a new LArray method instead ? |
| 172 | +# TODO: should appear in the API doc if it actually works with LArrays, |
| 173 | +# which I have never tested (and I doubt is the case). |
| 174 | +# Might be worth having specific documentation if it works well. |
| 175 | +# My guess is that we should rather make a new LArray method for that one. |
| 176 | +interp = broadcastify(np.interp) |
0 commit comments