diff --git a/DOCS.md b/DOCS.md index 04e13aa..2978abe 100644 --- a/DOCS.md +++ b/DOCS.md @@ -42,10 +42,6 @@ argument. ; VEQ:$ ; [symbol] ; - ; $ names a macro: - ; Lambda-list: (A &REST REST) - ; Source file: src/array-utils.lisp - ; ; (SETF $) has a complex setf-expansion: ; Lambda-list: (A0 &OPTIONAL (I1 0)) ; Documentation: @@ -122,7 +118,7 @@ argument. ; start at row (start 0). ; negative start counts backwards from the last row ; use s to overrid output stream. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### $TO-LIST @@ -137,7 +133,7 @@ argument. ; (VALUES LIST &OPTIONAL)) ; Documentation: ; return array as a list of lists of length dim. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### \*EPS\* @@ -159,10 +155,6 @@ argument. ; VEQ:2$ ; [symbol] ; - ; 2$ names a macro: - ; Lambda-list: (A &REST REST) - ; Source file: src/array-utils.lisp - ; ; (SETF 2$) has a complex setf-expansion: ; Lambda-list: (A0 &OPTIONAL (I1 0)) ; Documentation: @@ -198,7 +190,7 @@ argument. ; Derived type: (FUNCTION (T &KEY (:N T) (:S T)) *) ; Documentation: ; pretty print 2d array. returns array. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### 2$TO-LIST @@ -212,7 +204,7 @@ argument. ; Derived type: (FUNCTION (T) *) ; Documentation: ; return array as a list of lists of length 2. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### 3$ @@ -221,10 +213,6 @@ argument. ; VEQ:3$ ; [symbol] ; - ; 3$ names a macro: - ; Lambda-list: (A &REST REST) - ; Source file: src/array-utils.lisp - ; ; (SETF 3$) has a complex setf-expansion: ; Lambda-list: (A0 &OPTIONAL (I1 0)) ; Documentation: @@ -260,7 +248,7 @@ argument. ; Derived type: (FUNCTION (T &KEY (:N T) (:S T)) *) ; Documentation: ; pretty print 3d array. returns array. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### 3$TO-LIST @@ -274,7 +262,7 @@ argument. ; Derived type: (FUNCTION (T) *) ; Documentation: ; return array as a list of lists of length 3. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### 4$ @@ -283,10 +271,6 @@ argument. ; VEQ:4$ ; [symbol] ; - ; 4$ names a macro: - ; Lambda-list: (A &REST REST) - ; Source file: src/array-utils.lisp - ; ; (SETF 4$) has a complex setf-expansion: ; Lambda-list: (A0 &OPTIONAL (I1 0)) ; Documentation: @@ -322,7 +306,7 @@ argument. ; Derived type: (FUNCTION (T &KEY (:N T) (:S T)) *) ; Documentation: ; pretty print 4d array. returns array. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### 4$TO-LIST @@ -336,7 +320,7 @@ argument. ; Derived type: (FUNCTION (T) *) ; Documentation: ; return array as a list of lists of length 4. - ; Source file: src/array-print.lisp + ; Source file: src/array-extra.lisp ``` #### ARRTYPE @@ -507,7 +491,7 @@ ex: (D$FXLSPACE (n a b) (lambda (i (:va 1 a b)) (vpr i a b))) ; find min and max for all dimensions of 1 array. ; ex: (D$MIMA &key n) returns (values xmin xmax ...). ; use n to limit to first n rows. - ; Source file: src/array-mima.lisp + ; Source file: src/array-extra.lisp ``` #### D$NUM @@ -707,7 +691,7 @@ ex: (D2$FXLSPACE (n a b) (lambda (i (:va 2 a b)) (vpr i a b))) ; find min and max for all dimensions of 2 array. ; ex: (D2$MIMA &key n) returns (values xmin xmax ...). ; use n to limit to first n rows. - ; Source file: src/array-mima.lisp + ; Source file: src/array-extra.lisp ``` #### D2$NUM @@ -1389,7 +1373,7 @@ ex: (D3$FXLSPACE (n a b) (lambda (i (:va 3 a b)) (vpr i a b))) ; find min and max for all dimensions of 3 array. ; ex: (D3$MIMA &key n) returns (values xmin xmax ...). ; use n to limit to first n rows. - ; Source file: src/array-mima.lisp + ; Source file: src/array-extra.lisp ``` #### D3$NUM @@ -3484,7 +3468,7 @@ ex: (F$FXLSPACE (n a b) (lambda (i (:va 1 a b)) (vpr i a b))) ; find min and max for all dimensions of 1 array. ; ex: (F$MIMA &key n) returns (values xmin xmax ...). ; use n to limit to first n rows. - ; Source file: src/array-mima.lisp + ; Source file: src/array-extra.lisp ``` #### F$NUM @@ -3713,7 +3697,7 @@ ex: (F2$FXLSPACE (n a b) (lambda (i (:va 2 a b)) (vpr i a b))) ; find min and max for all dimensions of 2 array. ; ex: (F2$MIMA &key n) returns (values xmin xmax ...). ; use n to limit to first n rows. - ; Source file: src/array-mima.lisp + ; Source file: src/array-extra.lisp ``` #### F2$NUM @@ -4547,7 +4531,7 @@ ex: (F3$FXLSPACE (n a b) (lambda (i (:va 3 a b)) (vpr i a b))) ; find min and max for all dimensions of 3 array. ; ex: (F3$MIMA &key n) returns (values xmin xmax ...). ; use n to limit to first n rows. - ; Source file: src/array-mima.lisp + ; Source file: src/array-extra.lisp ``` #### F3$NUM diff --git a/compile.sh b/compile.sh index bfebb05..3b551b3 100755 --- a/compile.sh +++ b/compile.sh @@ -6,4 +6,4 @@ time sbcl --quit \ --eval '(load "veq.asd")'\ --eval '(handler-case (time (ql:quickload :veq :verbose t)) (error (c) (print c) (sb-ext:quit :unix-status 2)))'\ - >compile.sh.tmp 2>&1 + > compile.sh.tmp 2>&1 diff --git a/make-docs.sh b/make-docs.sh index 02f127e..2b829b3 100755 --- a/make-docs.sh +++ b/make-docs.sh @@ -1,7 +1,6 @@ #!/bin/bash sbcl --quit \ - --eval '(load "~/quicklisp/setup.lisp")'\ --eval '(ql:quickload :veq :silent t)'\ --eval '(handler-case (veq:ext-symbols? :pretty) (error (c) (print c) (sb-ext:quit :unix-status 2)))'\ diff --git a/src/array-print.lisp b/src/array-extra.lisp similarity index 62% rename from src/array-print.lisp rename to src/array-extra.lisp index 3c3514c..2dc8198 100644 --- a/src/array-print.lisp +++ b/src/array-extra.lisp @@ -1,6 +1,42 @@ (in-package :veq) +(defun $to-list (a &key (dim 1)) + (declare (simple-array a) (pn dim)) + "return array as a list of lists of length dim." + (loop for i of-type pn from 0 below (length a) by dim + collect (loop for j of-type pn from i repeat dim + collect (aref a j)))) +(defun 2$to-list (a) "return array as a list of lists of length 2." ($to-list a :dim 2)) +(defun 3$to-list (a) "return array as a list of lists of length 3." ($to-list a :dim 3)) +(defun 4$to-list (a) "return array as a list of lists of length 4." ($to-list a :dim 4)) + +; TODO: make this a general macro instead? +(defmacro -xmima (dim type) + (let* ((exportname (vvsym type dim :$mima)) + (fxhead `(((:va ,dim x)))) + (vvop (vvsym type dim :x@$mima)) + (docs (format nil "find min and max for all dimensions of ~d array. +ex: (~a &key n) returns (values xmin xmax ...). +use n to limit to first n rows." dim exportname)) + (update-mima (loop for i from 0 repeat dim + for v = `(:vr x ,i) + for mi = `(:vr mi ,i) for ma = `(:vr ma ,i) + collect `(cond ((< ,v ,mi) (setf ,mi ,v)) + ((> ,v ,ma) (setf ,ma ,v)))))) + `(progn (export ',exportname) + (fvdef ,exportname (a &key (n (,(vvsym nil dim :$num) a)) inds) + (declare (,(arrtype type) a)) ,docs + (,(vvsym type 1 :vlet) + ((mm ,dim (,(vvsym type dim "$") a (if inds (car inds) 0))) + (mi ,dim (values mm)) (ma ,dim (values mm))) + (if inds (,vvop (l?@ a inds) (,@fxhead ,@update-mima)) + (,vvop (?@ a 0 n) (,@fxhead ,@update-mima))) + (values ,@(loop for i from 0 below dim + append `((:vr mi ,i) (:vr ma ,i))))))))) +(-xmima 1 ff) (-xmima 2 ff) (-xmima 3 ff) +(-xmima 1 df) (-xmima 2 df) (-xmima 3 df) + (defun $print (a &key (dim 1) (start 0) n (s t)) (declare (simple-array a) (pn dim) (fixnum start)) "pretty print n, or all, rows from vector array of dim. @@ -35,14 +71,3 @@ use s to overrid output stream." (defun 3$print (a &key n (s t)) "pretty print 3d array. returns array." ($print a :n n :dim 3 :s s)) (defun 4$print (a &key n (s t)) "pretty print 4d array. returns array." ($print a :n n :dim 4 :s s)) - -(defun $to-list (a &key (dim 1)) - (declare (simple-array a) (pn dim)) - "return array as a list of lists of length dim." - (loop for i of-type pn from 0 below (length a) by dim - collect (loop for j of-type pn from i repeat dim - collect (aref a j)))) -(defun 2$to-list (a) "return array as a list of lists of length 2." ($to-list a :dim 2)) -(defun 3$to-list (a) "return array as a list of lists of length 3." ($to-list a :dim 3)) -(defun 4$to-list (a) "return array as a list of lists of length 4." ($to-list a :dim 4)) - diff --git a/src/array-mima.lisp b/src/array-mima.lisp deleted file mode 100644 index 4fd56cd..0000000 --- a/src/array-mima.lisp +++ /dev/null @@ -1,29 +0,0 @@ - -(in-package :veq) - -; TODO: make this a general macro instead? -(defmacro -xmima (dim type) - (let* ((exportname (vvsym type dim :$mima)) - (fxhead `(((:va ,dim x)))) - (vvop (vvsym type dim :x@$mima)) - (docs (format nil "find min and max for all dimensions of ~d array. -ex: (~a &key n) returns (values xmin xmax ...). -use n to limit to first n rows." dim exportname)) - (update-mima (loop for i from 0 repeat dim - for v = `(:vr x ,i) - for mi = `(:vr mi ,i) for ma = `(:vr ma ,i) - collect `(cond ((< ,v ,mi) (setf ,mi ,v)) - ((> ,v ,ma) (setf ,ma ,v)))))) - `(progn (export ',exportname) - (fvdef ,exportname (a &key (n (,(vvsym nil dim :$num) a)) inds) - (declare (,(arrtype type) a)) ,docs - (,(vvsym type 1 :vlet) - ((mm ,dim (,(vvsym type dim "$") a (if inds (car inds) 0))) - (mi ,dim (values mm)) (ma ,dim (values mm))) - (if inds (,vvop (l?@ a inds) (,@fxhead ,@update-mima)) - (,vvop (?@ a 0 n) (,@fxhead ,@update-mima))) - (values ,@(loop for i from 0 below dim - append `((:vr mi ,i) (:vr ma ,i))))))))) -(-xmima 1 ff) (-xmima 2 ff) (-xmima 3 ff) -(-xmima 1 df) (-xmima 2 df) (-xmima 3 df) - diff --git a/src/array-utils.lisp b/src/array-utils.lisp index 3eb5b5f..b39a131 100644 --- a/src/array-utils.lisp +++ b/src/array-utils.lisp @@ -160,8 +160,8 @@ note that the number of values depends on the dimension." dim at name))) `(-$ ,,dim ,a :inds ,rest :atype ,',at))))))) (define-$) -(defmacro $ (a &rest rest) `(-$ 1 ,a :inds ,rest)) -(defmacro 2$ (a &rest rest) `(-$ 2 ,a :inds ,rest)) -(defmacro 3$ (a &rest rest) `(-$ 3 ,a :inds ,rest)) -(defmacro 4$ (a &rest rest) `(-$ 4 ,a :inds ,rest)) +; (defmacro $ (a &rest rest) `(-$ 1 ,a :inds ,rest)) +; (defmacro 2$ (a &rest rest) `(-$ 2 ,a :inds ,rest)) +; (defmacro 3$ (a &rest rest) `(-$ 3 ,a :inds ,rest)) +; (defmacro 4$ (a &rest rest) `(-$ 4 ,a :inds ,rest)) diff --git a/src/ops-vv-helpers.lisp b/src/ops-vv-helpers.lisp index 859fa6d..2d7f70f 100644 --- a/src/ops-vv-helpers.lisp +++ b/src/ops-vv-helpers.lisp @@ -2,10 +2,12 @@ (declaim (character *vv-dot* *vv-arr* *vv-bang*) (keyword *vv-!@* *vv-_@* *vv-?@* *vv-.@* - *vv-m@* *vv-r@* *vv-%@* *vv-x@*)) + *vv-m@* *vv-f@* + *vv-r@* *vv-%@* *vv-x@*)) (defvar *vv-!@* :!@) (defvar *vv-_@* :_@) -(defvar *vv-m@* :m@) (defvar *vv-r@* :r@) +(defvar *vv-m@* :m@) (defvar *vv-f@* :f@) +(defvar *vv-r@* :r@) (defvar *vv-%@* :%@) (defvar *vv-x@* :x@) (defvar *vv-.@* :.@) (defvar *vv-?@* :?@) (defvar *vv-dot* #\.) (defvar *vv-arr* #\$) (defvar *vv-bang* #\!) diff --git a/src/ops-vv.lisp b/src/ops-vv.lisp index 798284e..e9a2d2f 100644 --- a/src/ops-vv.lisp +++ b/src/ops-vv.lisp @@ -2,9 +2,12 @@ ; -- MVC ------------------------------------------------------------------------ -; (m@fx ...) -> (mvc fx (mvc #'values ...)) +; (m@fx ...) -> (mvc #'fx (mvc #'values ...)) (defun procm@fx (b p) `(mvc #',(gk p :fx*) (~ ,@(cdr b)))) +; almost the same: (f@fx ...) -> (mvc fx (mvc #'values ...)) +(defun procf@fx (b p) `(mvc (the function ,(gk p :fx*)) (~ ,@(cdr b)))) + ; -- 1ARY ----------------------------------------------------------------------- ; (2.@abs -1 -2) -> (abs -1) (abs -1) -> 1 2 @@ -221,7 +224,9 @@ expecting ~a or ~a, got: ~a)" b dim (1+ dim) l)) (defun vv-proc (body) (declare (optimize speed (safety 2))) (labels - ((m@ (b &aux (p (vvconf b #.(mkstr *vv-m@*)))) (procm@fx b p)) + ( + (m@ (b &aux (p (vvconf b #.(mkstr *vv-m@*)))) (procm@fx b p)) + (f@ (b &aux (p (vvconf b #.(mkstr *vv-f@*)))) (procf@fx b p)) (r@ (b &aux (p (vvconf b #.(mkstr *vv-r@*)))) (procr@$fx b p)) (x@ (b &aux (p (vvconf b #.(mkstr *vv-x@*)))) (procx@$fx b p)) (%@ (b &aux (p (vvconf b #.(mkstr *vv-%@*))) (l (length b))) @@ -277,6 +282,7 @@ expecting ~a or ~a, got: ~a)" b dim (1+ dim) l)) ((match-substr #.(mkstr *vv-%@*) s) (rec (%@ b))) ((match-substr #.(mkstr *vv-x@*) s) (rec (x@ b))) ((match-substr #.(mkstr *vv-m@*) s) (rec (m@ b))) + ((match-substr #.(mkstr *vv-f@*) s) (rec (f@ b))) (t (split b)))))) (rec body))) diff --git a/src/reader-macros.lisp b/src/reader-macros.lisp index 6f3f441..ef9d171 100644 --- a/src/reader-macros.lisp +++ b/src/reader-macros.lisp @@ -59,7 +59,8 @@ next symb: ~a" char (peek-char t stream t nil t))) (error "Delimiter ~S shouldn't be read alone. next symb: ~a" char (peek-char t stream t nil t))) -(set-macro-character #\} 'read-delimiter) +(set-macro-character #\} '-read-delimiter) +; (set-macro-character #\] '-read-delimiter) ; adapted from https://gist.github.com/chaitanyagupta/9324402 (defun read-next-object (sep del &optional (stream *standard-input*)) @@ -75,14 +76,14 @@ next symb: ~a" char (peek-char t stream t nil t))) o)))) ; adapted from https://gist.github.com/chaitanyagupta/9324402 -(defun -read-left-brace (stream char) +(defun -read-left-curly-brace (stream char) (declare (ignore char)) (let ((*readtable* (copy-readtable))) (set-macro-character #\Space '-read-separator) - (loop for object = (read-next-object #\Space #\} stream) + (loop for object = (read-next-object #\Space #\} stream) while object collect object into objects finally (return `(values ,@objects))))) -(set-macro-character #\{ '-read-left-brace) +(set-macro-character #\{ '-read-left-curly-brace) diff --git a/veq.asd b/veq.asd index 5be2265..a5ddd38 100644 --- a/veq.asd +++ b/veq.asd @@ -3,7 +3,7 @@ :description "reasonably fast operations for 1-4d vectors, matrices, and arrays of vectors." :author "anders hoff / @inconvergent / inconvergent@gmail.com" - :version "4.5.3" :licence "MIT" + :version "4.5.4" :licence "MIT" :in-order-to ((asdf:test-op (asdf:test-op #:veq/tests))) :pathname "src/" :serial nil :depends-on (#+SBCL #:sb-cltl2) @@ -14,37 +14,37 @@ arrays of vectors." (:file "generic-utils" :depends-on ("config")) (:file "types" :depends-on ("generic-utils")) (:file "utils" :depends-on ("types")) - (:file "array-utils" :depends-on ("utils")) (:file "docs" :depends-on ("utils")) - (:file "veq-ops" :depends-on ("docs")) (:file "vset" :depends-on ("utils")) (:file "lets" :depends-on ("veq-ops")) - (:file "array-rows" :depends-on ("veq-ops")) + (:file "macros-helpers" :depends-on ("utils" )) + (:file "veq-ops" :depends-on ("macros-helpers")) (:file "ops-1" :depends-on ("veq-ops")) (:file "ops-2" :depends-on ("veq-ops")) (:file "ops-3" :depends-on ("veq-ops")) (:file "ops-4" :depends-on ("veq-ops")) - (:file "ops-vv-helpers" :depends-on ("lets")) - (:file "ops-vv" :depends-on ("ops-vv-helpers")) - (:file "macros-helpers" :depends-on ("utils" )) (:file "macrolets" - :depends-on ("macros-helpers" "veq-ops" "array-rows" - "array-utils" "lets" - "ops-vv" "ops-1" "ops-2" "ops-3" "ops-4")) - (:file "select-dim" :depends-on ("macrolets")) + :depends-on ("macros-helpers" "veq-ops" + "ops-1" "ops-2" "ops-3" "ops-4")) + (:file "ops-vv-helpers" :depends-on ("macrolets")) + (:file "ops-vv" :depends-on ("ops-vv-helpers")) + + (:file "array-utils" :depends-on ("utils")) + (:file "array-rows" :depends-on ("utils")) + + (:file "select-dim" :depends-on ("utils")) (:file "fxlspace" :depends-on ("macrolets")) (:file "mat" :depends-on ("macrolets")) (:file "mat-inv" :depends-on ("macrolets")) (:file "mat-cam" :depends-on ("macrolets")) - (:file "array-print" :depends-on ("macrolets")) - (:file "array-mima" :depends-on ("macrolets")) - (:file "checks" :depends-on ("array-mima")) - (:file "shapes" :depends-on ("array-mima")) + (:file "array-extra" :depends-on ("macrolets")) + (:file "checks" :depends-on ("array-extra")) + (:file "shapes" :depends-on ("array-extra")) (:file "easing" :depends-on ("macrolets")))) (asdf:defsystem #:veq/tests :depends-on (#:veq #:prove #:asdf #:uiop) - :version "4.5.3" + :version "4.5.4" :perform (asdf:test-op (o s) (uiop:symbol-call ':veq-tests '#:run-tests)) :pathname "test/" :serial t :components ((:file "run")))