S-exp GPU
All pages
Docs · Function transformsMarkdown

Map over tensor trees

(tree-map function tree...) calls function on corresponding leaves and returns a tree with the first tree's list/vector/plist structure and keys. All trees must have identical structure, keys and shared-leaf relationships. A shared leaf is visited once and the result stays shared. Invalid trees or conflicting aliases produce E-TREE-001.

sexpgpu probe --expr '(let* ((p (list :w (full [] 4.0))) (g ((grad (lambda (q) (* (getf q :w) (getf q :w)))) p)) (next (tree-map (lambda (w dw) (- w (* 0.25 dw))) p g))) (getf next :w))' --max-elements 100

The updated weight is 2.0. It is an ordinary value; tree-map does not write model parameters or optimizer state. Use functional-call to apply a model to the resulting tree.