(rontolisp) docs
← torch Package Functions

torch:tensor

(torch:tensor x &key requires-grad element-type)

Returns a fresh leaf tensor -- the differentiable value of the torch package -- from a number (a rank-0 scalar tensor), a list (flat, or a list of equal-length rows), an array, a linalg array, or another tensor (whose data is copied). :requires-grad t marks it as a parameter whose gradient torch:backward should fill in. The data is built packed single-float (#f), torch's default width whatever the source array's own width was; :element-type 'double-float builds #d instead, and :element-type nil preserves a source array's width (see Element width).

A tensor prints as #<TENSOR data>, with :REQUIRES-GRAD T appended for a parameter -- the same text on every backend, since only the data is shown and never the backward closure it may carry. Read the values themselves back with torch:data, torch:item and torch:grad.

#<TENSOR #f(1.0 2.0 3.0)>
#<TENSOR #f(1.0) :REQUIRES-GRAD T>