Skip to content

Commit

Permalink
minor improvements to vv vector. other minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
inconvergent committed Jun 15, 2023
1 parent 3ed1167 commit 1cf5088
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 100 deletions.
44 changes: 14 additions & 30 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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\*
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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$
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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$
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion make-docs.sh
Original file line number Diff line number Diff line change
@@ -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)))'\
Expand Down
47 changes: 36 additions & 11 deletions src/array-print.lisp → src/array-extra.lisp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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))

29 changes: 0 additions & 29 deletions src/array-mima.lisp

This file was deleted.

8 changes: 4 additions & 4 deletions src/array-utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))

6 changes: 4 additions & 2 deletions src/ops-vv-helpers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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* #\!)
Expand Down
10 changes: 8 additions & 2 deletions src/ops-vv.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))

Expand Down
9 changes: 5 additions & 4 deletions src/reader-macros.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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*))
Expand All @@ -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)

Loading

0 comments on commit 1cf5088

Please sign in to comment.