Handbook
Glossary
transpose ( tensor: tensor -- tensor': tensor )
Tensors
ยป
Manipulating Tensors
Prev:
matmul ( tensor1: tensor tensor2: tensor -- tensor3: tensor )
Next:
stack ( seq -- tensor )
Vocabulary
tensors
Inputs
tensor
a
tensor
Outputs
tensor'
a
tensor
Word description
Performs n-dimensional matrix transposition on
tensor
.
Definition
USING:
accessors
kernel
math
sequences
sequences.extras
sequences.private
specialized-arrays.instances.alien.c-types.float
tensors.private
typed
;
IN:
tensors
TYPED::
transpose
( tensor: tensor -- tensor': tensor )
tensor
shape>>
length
2
=
[
tensor
2d-transpose
]
[
tensor
shape>>
:>
old-shape tensor
vec>>
:>
vec
old-shape
reverse
:>
new-shape old-shape
ind-mults
:>
mults new-shape
dup
product
<iota>
[
old-shape mults
[
[
/mod
]
dip
*
]
2map-sum
nip
vec
nth-unsafe
]
float-array{
}
map-as
<tensor>
]
if
;