Skip to content

Commit

Permalink
linspace* fx
Browse files Browse the repository at this point in the history
  • Loading branch information
inconvergent committed Feb 6, 2024
1 parent 706105f commit 6aba29b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
15 changes: 15 additions & 0 deletions docs/lqn.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,21 @@
; Source file: /data/x/lqn/src/io.lisp
```

#### LQN:LINSPACE\*

```
; LQN:LINSPACE*
; [symbol]
;
; LINSPACE* names a compiled function:
; Lambda-list: (N &OPTIONAL (A 0.0) (B 1.0) (END T))
; Derived type: (FUNCTION (FIXNUM &OPTIONAL REAL REAL BOOLEAN)
; (VALUES (AND (VECTOR T) (NOT SIMPLE-ARRAY)) &OPTIONAL))
; Documentation:
; n floats from a to b.
; Source file: /data/x/lqn/src/qry-utils.lisp
```

#### LQN:LPAD

```
Expand Down
2 changes: 1 addition & 1 deletion src/basic-utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(defvar *fxns* '(:err :wrn :nope :noop :lst :lit :qt :hld :ghv :pnum :inum :cnt
:fmt :out :jsnstr
:fn :fi :ctx :par :itr :compct :?? :@@ :@* :smth? :ind* :sel* :seq* :apply* :join
:new* :new$ :cat* :cat$ :head* :tail* :size? :range* :pop* :psh*
:new* :new$ :cat* :cat$ :head* :tail* :size? :range* :linspace* :pop* :psh*
:flatn* :flatall* :flatn$ :uniq
:pref? :suf? :sub? :subx? :ipref? :isuf? :isub? :isubx? :lpad :rpad :nstr
:sup :sdwn :mkstr :repl :strcat :splt
Expand Down
5 changes: 3 additions & 2 deletions src/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#:qry #:qryd #:jsnqryf #:qryl #:proc-qry
#:jsnloads #:jsnloadf #:jsnout #:ldnout #:fmt #:out #:jsnstr #:@* #:@@ #:??
#:some? #:none? #:all? #:empty? #:size? #:is?
#:path? #:subdir #:subfiles #:ls #:dir? #:file? #:cwd #:now #:cmd #:some? #:all? #:none? #:cd
#:new* #:new$ #:cat$ #:cat* #:head* #:tail* #:apply* #:range* #:psh* #:pop*
#:path? #:subdir #:subfiles #:ls #:dir? #:file? #:cwd #:now #:cmd
#:some? #:all? #:none? #:cd
#:new* #:new$ #:cat$ #:cat* #:head* #:tail* #:apply* #:range* #:linspace* #:psh* #:pop*
#:flatn* #:compct #:flatall* #:flatn$ #:uniq
#:pnum #:inum #:cnt
#:noop #:kv? #:kw? #:ssym? #:msym? #:trim #:sym!
Expand Down
10 changes: 10 additions & 0 deletions src/qry-utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ match. If b is an expression, a is compared to the evaluated value of b."
(make-array (length init) :initial-contents init
:adjustable t :fill-pointer t)))

(defun linspace* (n &optional (a 0.0) (b 1.0) (end t))
(declare #.*opt* (fixnum n) (real a b) (boolean end)) "n floats from a to b."
(let ((res (make-array n :initial-element 0.0 :adjustable t
:fill-pointer t :element-type 'float)))
(if (> n 1) (loop with ban = (/ (- b a) (if end (1- n) n))
for i of-type fixnum from 0 below n
do (setf (aref res i) (coerce (+ a (* i ban)) 'float)))
(setf (aref res 0) a))
res))

; TODO: fx to convert non-fill-ptr array to fpa?
(defmacro psh* (a o) (declare (symbol a)) "extend a with o. return a. destructive."
`(progn (vector-push-extend ,o ,a) ,a))
Expand Down

0 comments on commit 6aba29b

Please sign in to comment.