Skip to content

Commit

Permalink
Add TARGET argument for SCALE (quil-lang#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
digikar99 committed Apr 7, 2023
1 parent e904b43 commit 9f46483
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/high-level/abstract-tensor.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,17 @@ If LAYOUT is specified then traverse TENSOR in the specified order (column major
(lambda (tensor factor)
(map! (lambda (x) (* x factor)) tensor)))

(define-backend-function scale (tensor factor)
"Scale TENSOR by FACTOR, returning a new tensor of the same type as TENSOR")
(define-backend-function scale (tensor factor &optional target)
"Scale TENSOR by FACTOR.
If TARGET is specified then the result is stored in TARGET,
otherwise a new tensor of the same type as TENSOR is used for the result.")

(define-backend-implementation scale :lisp
(lambda (tensor factor)
(scale! (deep-copy-tensor tensor) factor)))
(lambda (tensor factor &optional (target nil targetp))
(scale! (if targetp
target
(deep-copy-tensor tensor))
factor)))

(defgeneric slice (tensor from to)
(:documentation "Slice a tensor from FROM to TO, returning a new tensor with the contained elements")
Expand Down

0 comments on commit 9f46483

Please sign in to comment.