1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
-- Tensor type stubs (for IDE/LSP support)
---@diagnostic disable:missing-return
---@class Tensor
---@overload fun(tbl: table): Tensor
Tensor =
---Constructs a Tensor from a nested Lua table.
---The table must represent a rectangular n-dimensional array.
---@param tbl table Nested table of numbers
---@return Tensor
---Computes layer_norm along a specific axis
---@param axis integer Axis to compute layer_norm along
---@param eps number epsilon value
---@return Tensor
---Truncates a tensor along a specific axis.
---@param axis integer Axis to truncate along
---@param len integer Length to truncate each slice to
---@return Tensor
---Returns a new tensor with values clamped between `min` and `max`.
---If `min` is nil, no lower bound is applied.
---If `max` is nil, no upper bound is applied.
---Equivalent to `torch.clamp`.
---@param min number|nil Lower bound (optional)
---@param max number|nil Upper bound (optional)
---@return Tensor
---Computes the standard deviation of all elements.
---`ddof` specifies the degrees-of-freedom adjustment.
---@param ddof integer
---@return number
---Computes the arithmetic mean of all elements.
---@return number|nil Mean value, or nil if the tensor is empty
---Returns the number of dimensions (rank) of the tensor.
---@return integer
---Computes the softmax along the specified axis.
---The result is normalized so values along that axis sum to 1.
---@param axis integer Axis index (1-based)
---@return Tensor
---Returns a version of the tensor with the last two axes swapped.
---@return Tensor
---Normalizes values along an axis using the Lp norm.
---Each slice is divided by its Lp norm so that its magnitude becomes 1.
---@param lp number Norm order (e.g., 1 or 2)
---@param axis integer Axis index (1-based)
---@return Tensor
---Returns the minimum scalar value in the tensor.
---@return number
---Returns the maximum scalar value in the tensor.
---@return number
---Applies the exponential function elementwise.
---@return Tensor
---Sums values along the specified axis.
---@param axis integer Axis index (1-based)
---@return Tensor Tensor with the axis removed
---Returns the sum of all elements in the tensor.
---@return number
---Applies a function to each slice along an axis.
---`func` receives a Tensor containing one slice and must return a Tensor.
---@param axis integer Axis index (1-based)
---@param func fun(t: Tensor): Tensor
---@return Tensor
---Reduces each slice along an axis using a binary function.
---The function is called as `func(accumulator, value)` for each scalar.
---@param axis integer Axis index (1-based)
---@param func fun(acc: number, x: number): number
---@return Tensor 1-D tensor of reduction results
---Mean pools a tensor using a mask.
---The mask must be 1 rank smaller than the tensor itself.
---@param mask Tensor Mask tensor
---@return Tensor
---Elementwise equality comparison.
---@param other number|Tensor
---@return boolean
---Returns the total number of elements in the tensor.
---@return integer
---Elementwise addition or broadcasting addition.
---@param other number|Tensor
---@return Tensor
---Elementwise subtraction or broadcasting subtraction.
---@param other number|Tensor
---@return Tensor
---Elementwise multiplication or broadcasting multiplication.
---@param other number|Tensor
---@return Tensor
---Elementwise division or broadcasting division.
---@param other number|Tensor
---@return Tensor
---Converts the tensor into a human-readable string representation.
---@return string