hikettei / cl-waffe2

[Experimental] Graph and Tensor Abstraction for Deep Learning all in Common Lisp
https://hikettei.github.io/cl-waffe2/
MIT License
142 stars 6 forks source link

[Add] lazy, lazy-reduce #129

Closed hikettei closed 1 year ago

hikettei commented 1 year ago

Changes

Added: lazy, lazy-reduce

With the lazy and lazy-reduce functions, users can benefit from loop optimization of cl-waffe2 without adding new backend.

;; Example:
(lazy #'sin (randn `(3 3)) :diff #'cos)
(defun topk (k)
  #'(lambda (&rest args)
      (let ((topN (sort args #'>)))
    (apply #'values (loop for n upfrom 0 below K collect (nth n topN))))))

(lazy-reduce (topk 3) (ax+b `(10 10) 1 0) :reduce-to 3)

(defun my-topk (tensor k)
    (lazy-reduce (topk K) tensor :reduce-to k))

(my-topk (ax+b `(10 10) 1 0) 3)

APIs