Pythonã®ï¼ã¨ããã¤ã¤Cã§é度ã稼ãã§ããï¼Numpyã¨ããæ°å¤è¨ç®ç¨ã®ã©ã¤ãã©ãªããããåºã使ããã¦ããã®ã¯èª°ããç¥ãã¨ããã ã¨æããå®éã«ã¯ãWebã¨ã³ã¸ãã¢ããã¯Pandasã¨ãã£ããã¬ã¼ã ã¯ã¼ã¯ã被ãã¦ä½¿ããã¨ãå¤ãã
ãããªä¸ãNumpyã®Common Lispå®è£ ããããã¨ãç¥ã£ãããã®åãNumclã
READMEãªã©ãèªãéããNumclã¯ä»¥ä¸ã®ãããªæ¹éã§å®è£ ããã¦ããããã :
- å¯è½ãªéãNumpyã®APIã模å£ãããã¨ããã©ããããLispyãªæ¹æ³ã使ãã
- Portabilityãéè¦ãã¦ãNumpyã®ããã«æ°ããªãã¼ã¿æ§é ã¯å°å ¥ãããCommon Lispæ¨æºã®arrayã使ããï¼Common Lispã¯ãããã©ã«ãã§å¤æ¬¡å é åããµãã¼ããã¦ããï¼
- å¯è½ãªéãCommon Lispã®æ¢åã®é¢æ°ãæ¡å¼µãããããªååã使ããå°æ¥çã«æ¨æºé¢æ°ãç½®ãæãããã¨ãã§ããããã«ããããã
ãã¤ãã£ããªCommon Lispä¸ã§å®è£ ããã¦ããã®ãé¢ç½ãããã©ãCommon Lispã¯æå¤ã¨éãï¼å¤±ç¤¼ï¼ã®ã§ãããã§ããã¾ããªãããã ã
å®éã«éã¶
installation
ãã¤ãéããNumclã¯quicklispããã¤ã³ã¹ãã¼ã«ã§ãã:
(ql:quickload :numcl)
numclã¯å¤§ããã®ãã¼ããè¦æ±ããã®ã§ãå¦çç³»ããããããè¨å®ãã¦ããå¿ è¦ããããããããªããRoswellã使ã£ã¦ããå ´åã¯ä»¥ä¸ã®ã³ãã³ããã·ã§ã«ã§å®è¡ããã°ãã:
$ ros config set dynamic-space-size 4gb
ããã§4GBã®ãã¼ããå©ç¨å¯è½ã«ãªãã
使ã
Numpyã®APIã«æºæ ãã¦ããã®ã§ãå½ç¶ã¨ããã°å½ç¶ã ãNumpyã¨åããããªåä½ãããã
(defpackage :numcl-exercise (:use :cl)) (in-package :numcl-exercise) ;; numpyåæ§ã«arangeã使ããã¨ãã§ãã (defparameter arr (numcl:arange 100)) ;; => #(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ;; 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 ;; 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 ;; 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99) ;; numpyåæ§ã«ã¹ã«ã©ã¼æ¼ç®ãè¡ããã¨ãã§ãã ;; ãã ããæ¼ç®åã®åå空éã¯numclã®ãã¨ã«ãã (defparameter arr2 (numcl:+ arr 1)) ;; => #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ;; 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 ;; 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 ;; 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100) ;; numpyåæ§ã«é åå士ã®æ¼ç®ãè¡ããã¨ãã§ãã (defparameter arr3 (numcl:* arr arr)) ;; => #(0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400 441 484 ;; 529 576 625 676 729 784 841 900 961 1024 1089 1156 1225 1296 1369 1444 1521 ;; 1600 1681 1764 1849 1936 2025 2116 2209 2304 2401 2500 2601 2704 2809 2916 ;; 3025 3136 3249 3364 3481 3600 3721 3844 3969 4096 4225 4356 4489 4624 4761 ;; 4900 5041 5184 5329 5476 5625 5776 5929 6084 6241 6400 6561 6724 6889 7056 ;; 7225 7396 7569 7744 7921 8100 8281 8464 8649 8836 9025 9216 9409 9604 9801) ;; numpyã§ããªãã¿ã®æä½ãç¨æããã¦ãã (defparameter arr4 (numcl:reshape arr '(9 9))) ;; => #2A((0 1 2 3 4 5 6 7 8) ;; (9 10 11 12 13 14 15 16 17) ;; (18 19 20 21 22 23 24 25 26) ;; (27 28 29 30 31 32 33 34 35) ;; (36 37 38 39 40 41 42 43 44) ;; (45 46 47 48 49 50 51 52 53) ;; (54 55 56 57 58 59 60 61 62) ;; (63 64 65 66 67 68 69 70 71) ;; (72 73 74 75 76 77 78 79 80)) ;; numpyã«ãããrange accessã¯arefã使ã ;; è¡ãæåã«æå®ããã (numcl:aref arr4 4) ;; => #(36 37 38 39 40 41 42 43 44) (numcl:aref arr4 '(4 6)) ;; => #2A((36 37 38 39 40 41 42 43 44) (45 46 47 48 49 50 51 52 53)) ;; å ¨ã¦æå®ããã«ã¯tã使ã (numcl:aref arr4 t 3) ;; #(3 12 21 30 39 48 57 66 75) ;; transposeããã (numcl:transpose arr4) ;; è¡åç©(matrix multiply) (numcl:matmul arr4 (numcl:transpose arr4)) ;; å¹³æ¹æ ¹ (numcl:sqrt arr4)
æå ã«å·¨å¤§ãªãã¼ã¿ã»ããããªãã®ã§ãæå ã§ãã³ããã¼ã¯ããããã¨ãã§ããªãã®ã ããCommon Lispã®å ´åé度ãå¿ è¦ãªç®æãæé©åãããã¨ãã£ãææ³ãé©ç¨ã§ããã®ã§ãããªãã®é度ãåºãã®ã ããã¨æãã
ã¾ããç¹æ®ãªãã¼ã¿å½¢å¼ã§ã¯ãªãCommon Lispã®æ¨æºçãªarrayã使ã£ã¦ããã®ã§ãCSVãªã©ã®å ¥åºåé¢é£ã®é¢æ°ã¯æä¾ããã¦ããããå¥éã©ããã«ãããã¼ãµãæã£ã¦ãã¦ãarrayã«å¤æãã¦ããã¨ãããã¨ãããã
Pandasã®Common Lispå®è£ ãTeddy
ã¨ããã§ãNumpyã®Common Lispå®è£ ããããªãPandasã®Common Lispå®è£ ãããã®ã§ã¯ãªããã¨æã£ã¦èª¿ã¹ãã¨ãããTeddyã¨ããã®ããããããã
ã ãã2å¹´åã«éçºãæ¢ã¾ã£ã¦ããã*1ãã·ã³ãã«ã®exportã¾ãããããããã®ã§ã¡ããã¨åããªããããã°ãã°åãã¿ãããªå®æ度ã®ç¶æ ã«ãªã£ã¦ããã
Common Lispã®è¨ç®ç³»ã©ã¤ãã©ãªãä»ã«ãæ¢ãã¨ãä»ã«ãæ©æ¢°å¦ç¿ç³»ã®ã©ã¤ãã©ãªã§ããMGLï¼ãã¡ãã¯Numclã使ããcl-cudaã«ä¾åãã¦ããï¼ãªã©ããããç´°ã ã¨æ´æ°ããã¦ããããã ã
Common Lispã«ã¯å¼·åãªREPLãããã®ã§ããã®ã¾ã¾é å¼µã£ã¦ã»ããã
*1:Numclã8ã¶æåã«æ´æ°ãåæ¢ãã¦ãããâ¦â¦â¦â¦