├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── matlib.sc ├── numpy.sc └── test └── test.sc /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sc linguist-language=Scheme 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ss~ 2 | *.ss#* 3 | .#*.ss 4 | 5 | *.scm~ 6 | *.scm#* 7 | .#*.scm 8 | 9 | 10 | *.sc~ 11 | *.sc#* 12 | .#*.sc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 - 2019 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NumPy for Chez Scheme 2 | 3 | ![image](https://github.com/guenchi/numpy/blob/gh-pages/img/NumPy.jpeg) 4 | 5 | ### and it's faster than the Native NumPy of Python 6 | 7 | 8 | ``` 9 | (define get-sin 10 | (lambda (lst) 11 | (plist->list 12 | (np-tolist 13 | (np-sin 14 | (py-div 15 | (py-mul pi 16 | (np-array 17 | (list->plist lst) 18 | ('dtype (str "float")))) 19 | (int 180))))))) 20 | 21 | (display (get-sin '(1 2 3 4 5 6 7 8))) 22 | 23 | => 24 | 25 | (0.01745240643728351 0.03489949670250097 0.05233595624294383 0.0697564737441253 26 | 0.08715574274765817 0.10452846326765346 0.12186934340514748 0.13917310096006544) 27 | ``` 28 | 29 | 30 | ### Depencies: 31 | 32 | https://guenchi.github.io/Darkart 33 | 34 | https://github.com/python/cpython 35 | 36 | https://github.com/numpy/numpy 37 | 38 | ### The Darkart ecosystem: 39 | 40 | https://guenchi.github.io/NumPy 41 | 42 | https://guenchi.github.io/SciPy 43 | 44 | https://guenchi.github.io/SymPy 45 | 46 | https://guenchi.github.io/Matplotlib 47 | 48 | https://guenchi.github.io/Pandas -------------------------------------------------------------------------------- /matlib.sc: -------------------------------------------------------------------------------- 1 | ; MIT License 2 | 3 | ; Copyright guenchi (c) 2018 - 2019 4 | 5 | ; Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ; of this software and associated documentation files (the "Software"), to deal 7 | ; in the Software without restriction, including without limitation the rights 8 | ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ; copies of the Software, and to permit persons to whom the Software is 10 | ; furnished to do so, subject to the following conditions: 11 | 12 | ; The above copyright notice and this permission notice shall be included in all 13 | ; copies or substantial portions of the Software. 14 | 15 | ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | ; SOFTWARE. 22 | 23 | 24 | 25 | 26 | 27 | 28 | (library (numpy matlib) 29 | (export 30 | matlib 31 | ) 32 | (import 33 | (chezscheme) 34 | (darkart py call)) 35 | 36 | (define matlib (py-import 'numpy.matlib)) 37 | 38 | (define *empty (py-get matlib 'empty)) 39 | (define *zeros (py-get matlib 'zeros)) 40 | (define *ones (py-get matlib 'ones)) 41 | (define *eye (py-get matlib 'eye)) 42 | (define *identity (py-get matlib 'identity)) 43 | (define *rand (py-get matlib 'rand)) 44 | 45 | ) -------------------------------------------------------------------------------- /numpy.sc: -------------------------------------------------------------------------------- 1 | ; MIT License 2 | 3 | ; Copyright guenchi (c) 2018 - 2019 4 | 5 | ; Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ; of this software and associated documentation files (the "Software"), to deal 7 | ; in the Software without restriction, including without limitation the rights 8 | ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ; copies of the Software, and to permit persons to whom the Software is 10 | ; furnished to do so, subject to the following conditions: 11 | 12 | ; The above copyright notice and this permission notice shall be included in all 13 | ; copies or substantial portions of the Software. 14 | 15 | ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | ; SOFTWARE. 22 | 23 | 24 | 25 | 26 | 27 | 28 | (library (numpy numpy) 29 | (export 30 | numpy 31 | ndarray 32 | char 33 | fft 34 | linalg 35 | pi 36 | np-array 37 | np-asarray 38 | np-empty 39 | np-ones 40 | np-zeros 41 | np-from-buffer 42 | np-from-iter 43 | np-linspace 44 | np-logspace 45 | np-sin 46 | np-tolist 47 | np-shape 48 | np-size 49 | np-arange 50 | np-exp 51 | np-negative 52 | ) 53 | 54 | (import 55 | (chezscheme) 56 | (darkart py call)) 57 | 58 | (define numpy (py-import 'numpy)) 59 | (define ndarray (py-get numpy 'ndarray)) 60 | (define char (py-get numpy 'char)) 61 | (define fft (py-get numpy 'fft)) 62 | (define linalg (py-get numpy 'linalg)) 63 | (define pi (py-get numpy 'pi)) 64 | 65 | (define *array (py-get numpy 'array)) 66 | (define *asarray (py-get numpy 'asarray)) 67 | 68 | (define *empty (py-get numpy 'empty)) 69 | (define *ones (py-get numpy 'ones)) 70 | (define *zeros (py-get numpy 'zeros)) 71 | (define *from-buffer (py-get numpy 'frombuffer)) 72 | (define *from-iter (py-get numpy 'fromiter)) 73 | (define *linspace (py-get numpy 'linspace)) 74 | (define *logspace (py-get numpy 'logspace)) 75 | 76 | (define *reshape (py-get numpy 'reshape)) 77 | (define *flatten (py-get ndarray 'flatten)) 78 | (define *ravel (py-get numpy 'ravel)) 79 | 80 | (define *rollaxis (py-get numpy 'rollaxis)) 81 | (define *swapaxes (py-get numpy 'swapaxes)) 82 | (define *transpose (py-get numpy 'transpose)) 83 | 84 | (define *broadcast (py-get numpy 'broadcast)) 85 | (define *broadcast-to (py-get numpy 'broadcast_to)) 86 | (define *expand-dims (py-get numpy 'expand_dims)) 87 | (define *squeeze (py-get numpy 'squeeze)) 88 | 89 | (define *concatenate (py-get numpy 'concatenate)) 90 | (define *stack (py-get numpy 'stack)) 91 | (define *hstack (py-get numpy 'hstack)) 92 | (define *vstack (py-get numpy 'vstack)) 93 | 94 | (define *split (py-get numpy 'split)) 95 | (define *hsplit (py-get numpy 'hsplit)) 96 | (define *vsplit (py-get numpy 'vsplit)) 97 | 98 | (define *resize (py-get numpy 'resize)) 99 | (define *append (py-get numpy 'append)) 100 | (define *insert (py-get numpy 'insert)) 101 | (define *delete (py-get numpy 'delete)) 102 | (define *unique (py-get numpy 'unique)) 103 | 104 | (define *bitwise-and (py-get numpy 'bitwise_and)) 105 | (define *bitwise-or (py-get numpy 'bitwise_or)) 106 | (define *invert (py-get numpy 'invert)) 107 | (define *left-shift (py-get numpy 'left_shift)) 108 | (define *right-shift (py-get numpy 'right_shift)) 109 | 110 | (define *char-add (py-get char 'add)) 111 | (define *char-multiply (py-get char 'multiply)) 112 | (define *char-center (py-get char 'center)) 113 | (define *char-capitalize (py-get char 'capitalize)) 114 | (define *char-title (py-get char 'title)) 115 | (define *char-lower (py-get char 'lower)) 116 | (define *char-upper (py-get char 'upper)) 117 | (define *char-split (py-get char 'split)) 118 | (define *char-splitlines (py-get char 'splitlines)) 119 | (define *char-strip (py-get char 'strip)) 120 | (define *char-join (py-get char 'join)) 121 | (define *char-replace (py-get char 'replace)) 122 | (define *char-encode (py-get char 'encode)) 123 | (define *char-decode (py-get char 'decode)) 124 | 125 | (define *cos (py-get numpy 'cos)) 126 | (define *tan (py-get numpy 'tan)) 127 | (define *arcsin (py-get numpy 'arcsin)) 128 | (define *arccos (py-get numpy 'arccos)) 129 | (define *arctan (py-get numpy 'arctan)) 130 | 131 | (define *hypot (py-get numpy 'hypot)) 132 | (define *arctan2 (py-get numpy 'arctan2)) 133 | (define *degrees (py-get numpy 'degrees)) 134 | (define *radians (py-get numpy 'radians)) 135 | (define *unwrap (py-get numpy 'unwrap)) 136 | (define *deg2rad (py-get numpy 'deg2rad)) 137 | (define *rad2deg (py-get numpy 'rad2deg)) 138 | 139 | (define *sinh (py-get numpy 'sinh)) 140 | (define *cosh (py-get numpy 'cosh)) 141 | (define *tanh (py-get numpy 'tanh)) 142 | (define *arcsinh (py-get numpy 'arcsinh)) 143 | (define *arccosh (py-get numpy 'arccosh)) 144 | (define *arctanh (py-get numpy 'arctanh)) 145 | 146 | (define *around (py-get numpy 'around)) 147 | (define *round (py-get numpy 'round_)) 148 | (define *rint (py-get numpy 'rint)) 149 | 150 | (define *fix (py-get numpy 'fix)) 151 | (define *floor (py-get numpy 'floor)) 152 | (define *ceil (py-get numpy 'ceil)) 153 | (define *trunc (py-get numpy 'trunc)) 154 | 155 | (define *prod (py-get numpy 'prod)) 156 | (define *sum (py-get numpy 'sum)) 157 | (define *nanprod (py-get numpy 'nanprod)) 158 | (define *nansum (py-get numpy 'nansum)) 159 | (define *cumprod (py-get numpy 'cumprod)) 160 | (define *cumsum (py-get numpy 'cumsum)) 161 | (define *nancumprod (py-get numpy 'nancumprod)) 162 | (define *nancumsum (py-get numpy 'nancumsum)) 163 | (define *diff (py-get numpy 'diff)) 164 | (define *ediff1d (py-get numpy 'ediff1d)) 165 | (define *gradient (py-get numpy 'gradient)) 166 | (define *cross (py-get numpy 'cross)) 167 | (define *trapz (py-get numpy 'trapz)) 168 | 169 | (define *expm1 (py-get numpy 'expm1)) 170 | (define *exp2 (py-get numpy 'exp2)) 171 | (define *log (py-get numpy 'log)) 172 | (define *log10 (py-get numpy 'log10)) 173 | (define *log2 (py-get numpy 'log2)) 174 | (define *log1p (py-get numpy 'log1p)) 175 | (define *logaddexp (py-get numpy 'logaddexp)) 176 | (define *logaddexp2 (py-get numpy 'logaddexp2)) 177 | 178 | (define *i0 (py-get numpy 'i0)) 179 | (define *sinc (py-get numpy 'sinc)) 180 | 181 | (define *signbit (py-get numpy 'signbit)) 182 | (define *copysign (py-get numpy 'copysign)) 183 | (define *frexp (py-get numpy 'frexp)) 184 | (define *ldexp (py-get numpy 'ldexp)) 185 | (define *nextafter (py-get numpy 'nextafter)) 186 | (define *spacing (py-get numpy 'spacing)) 187 | 188 | (define *lcm (py-get numpy 'lcm)) 189 | (define *gcd (py-get numpy 'gcd)) 190 | 191 | (define *add (py-get numpy 'add)) 192 | (define *subtract (py-get numpy 'subtract)) 193 | (define *multiply (py-get numpy 'multiply)) 194 | (define *divide (py-get numpy 'divide)) 195 | (define *reciprocal (py-get numpy 'reciprocal)) 196 | (define *power (py-get numpy 'power)) 197 | (define *positive (py-get numpy 'positive)) 198 | (define *true-divide (py-get numpy 'true_divide)) 199 | (define *floor-divide (py-get numpy 'floor_divide)) 200 | (define *float-power (py-get numpy 'float_power)) 201 | (define *mod (py-get numpy 'mod)) 202 | (define *fmod (py-get numpy 'fmod)) 203 | (define *modf (py-get numpy 'modf)) 204 | (define *remainder (py-get numpy 'remainder)) 205 | (define *divmod (py-get numpy 'divmod)) 206 | 207 | (define *angle (py-get numpy 'angle)) 208 | (define *real (py-get numpy 'real)) 209 | (define *imag (py-get numpy 'imag)) 210 | (define *conj (py-get numpy 'conj)) 211 | 212 | (define *convolve (py-get numpy 'convolve)) 213 | (define *clip (py-get numpy 'clip)) 214 | (define *sqrt (py-get numpy 'sqrt)) 215 | (define *cbrt (py-get numpy 'cbrt)) 216 | (define *square (py-get numpy 'square)) 217 | (define *absolute (py-get numpy 'absolute)) 218 | (define *fabs (py-get numpy 'fabs)) 219 | (define *sign (py-get numpy 'sign)) 220 | (define *heaviside (py-get numpy 'heaviside)) 221 | (define *maximum (py-get numpy 'maximum)) 222 | (define *minimum (py-get numpy 'minimum)) 223 | (define *fmax (py-get numpy 'fmax)) 224 | (define *fmin (py-get numpy 'fmin)) 225 | (define *nan-to-num (py-get numpy 'nan_to_num)) 226 | (define *real-if-close (py-get numpy 'real_if_close)) 227 | (define *interp (py-get numpy 'interp)) 228 | 229 | (define *amin (py-get numpy 'amin)) 230 | (define *amax (py-get numpy 'amax)) 231 | (define *ptp (py-get numpy 'ptp)) 232 | (define *percentile (py-get numpy 'percentile)) 233 | (define *median (py-get numpy 'median)) 234 | (define *mean (py-get numpy 'mean)) 235 | (define *average (py-get numpy 'average)) 236 | (define *std (py-get numpy 'std)) 237 | (define *var (py-get numpy 'var)) 238 | (define *sort (py-get numpy 'sort)) 239 | (define *argsort (py-get numpy 'argsort)) 240 | (define *lexsort (py-get numpy 'lexsort)) 241 | (define *msort (py-get numpy 'msort)) 242 | (define *sort-complex (py-get numpy 'sort_complex)) 243 | (define *partition (py-get numpy 'partition)) 244 | (define *argpartition (py-get numpy 'argpartition)) 245 | (define *argmax (py-get numpy 'argmax)) 246 | (define *argmin (py-get numpy 'argmin)) 247 | (define *nonzero (py-get numpy 'nonzero)) 248 | (define *where (py-get numpy 'where)) 249 | (define *extract (py-get numpy 'extract)) 250 | 251 | (define *dot (py-get numpy 'dot)) 252 | (define *vdot (py-get numpy 'vdot)) 253 | (define *inner (py-get numpy 'inner)) 254 | (define *matmul (py-get numpy 'matmul)) 255 | 256 | (define *det (py-get linalg 'det)) 257 | (define *solve (py-get linalg 'solve)) 258 | (define *inv (py-get linalg 'inv)) 259 | 260 | (define *fft (py-get fft 'fft)) 261 | (define *ifft (py-get fft 'ifft)) 262 | (define *fft2 (py-get fft 'fft2)) 263 | (define *ifft2 (py-get fft 'ifft2)) 264 | (define *fftn (py-get fft 'fftn)) 265 | (define *ifftn (py-get fft 'ifftn)) 266 | 267 | (define *rfft (py-get fft 'rfft)) 268 | (define *irfft (py-get fft 'irfft)) 269 | (define *rfft2 (py-get fft 'rfft2)) 270 | (define *irfft2 (py-get fft 'irfft2)) 271 | (define *rfftn (py-get fft 'rfftn)) 272 | (define *irfftn (py-get fft 'irfftn)) 273 | 274 | (define *hfft (py-get fft 'hfft)) 275 | (define *ihfft (py-get fft 'ihfft)) 276 | 277 | (define *fftfreq (py-get fft 'fftfreq)) 278 | (define *rfftfreq (py-get fft 'rfftfreq)) 279 | (define *fftshift (py-get fft 'fftshift)) 280 | (define *ifftshift (py-get fft 'ifftshift)) 281 | 282 | (define-syntax np-array 283 | (syntax-rules () 284 | ((_ e)(py-call *array e)) 285 | ((_ e (k v) ...) 286 | ((py-call* *array e) 287 | (list (cons k v) ...))))) 288 | 289 | (define-syntax np-asarray 290 | (syntax-rules () 291 | ((_ e)(py-call *asarray e)) 292 | ((_ e (k v) ...) 293 | ((py-call* *asarray e) 294 | (list (cons k v) ...))))) 295 | 296 | (define-syntax np-empty 297 | (syntax-rules () 298 | ((_ e)(py-call *empty e)) 299 | ((_ e (k v) ...) 300 | ((py-call* *empty e) 301 | (list (cons k v) ...))))) 302 | 303 | (define-syntax np-ones 304 | (syntax-rules () 305 | ((_ e)(py-call *ones e)) 306 | ((_ e (k v) ...) 307 | ((py-call* *ones e) 308 | (list (cons k v) ...))))) 309 | 310 | (define-syntax np-zeros 311 | (syntax-rules () 312 | ((_ e)(py-call *zeros e)) 313 | ((_ e (k v) ...) 314 | ((py-call* *zeros e) 315 | (list (cons k v) ...))))) 316 | 317 | (define-syntax np-from-buffer 318 | (syntax-rules () 319 | ((_ e)(py-call *from-buffer e)) 320 | ((_ e (k v) ...) 321 | ((py-call* *from-buffer e) 322 | (list (cons k v) ...))))) 323 | 324 | (define-syntax np-from-iter 325 | (syntax-rules () 326 | ((_ e)(py-call *from-iter e)) 327 | ((_ e (k v) ...) 328 | ((py-call* *from-iter e) 329 | (list (cons k v) ...))))) 330 | 331 | (define-syntax np-linspace 332 | (syntax-rules () 333 | ((_ e1 e2 e3)(py-call *linspace e1 e2 e3)) 334 | ((_ e1 e2 e3 (k v) ...) 335 | ((py-call* *linspace e1 e2 e3) 336 | (list (cons k v) ...))))) 337 | 338 | (define-syntax np-logspace 339 | (syntax-rules () 340 | ((_ e)(py-call *logspace e)) 341 | ((_ e (k v) ...) 342 | ((py-call* *logspace e) 343 | (list (cons k v) ...))))) 344 | 345 | 346 | 347 | 348 | (define np-sin (py-func numpy 'sin)) 349 | (define np-tolist (py-func ndarray 'tolist)) 350 | (define np-shape (py-func numpy 'shape)) 351 | (define np-size (py-func numpy 'size)) 352 | (define np-arange (py-func numpy 'arange)) 353 | (define np-exp (py-func numpy 'exp)) 354 | (define np-negative (py-func numpy 'negative)) 355 | 356 | 357 | 358 | ) 359 | 360 | 361 | -------------------------------------------------------------------------------- /test/test.sc: -------------------------------------------------------------------------------- 1 | (import (darkart py call) 2 | (numpy numpy)) 3 | 4 | 5 | 6 | (py-init) 7 | 8 | 9 | 10 | 11 | (define get-sin 12 | (lambda (lst) 13 | (plist->list 14 | (np-tolist 15 | (np-sin 16 | (py-div 17 | (py-mul pi 18 | (np-array (list->plist lst) ('dtype (str "float")))) 19 | (int 180))))))) 20 | 21 | (display (get-sin '(1 2 3 4 5 6 7 8))) 22 | 23 | (newline) 24 | (py-fin) 25 | 26 | 27 | (exit) 28 | --------------------------------------------------------------------------------