Handbook
Glossary
reshape-dimensions ( size shape -- dimensions )
Vocabulary
arrays
.
shaped
.
private
Inputs
size
an
object
shape
an
object
Outputs
dimensions
an
object
Definition
USING:
accessors
arrays
arrays.shaped
kernel
math
sequences
;
IN:
arrays.shaped.private
::
reshape-dimensions
( size shape -- dimensions )
shape
dup
integer?
[
1array
]
when
dup
uniform-shape?
[
shape>>
]
when
>array
:>
dimensions dimensions
[
integer?
]
all?
[
dimensions
noninteger-shape-components
]
unless
dimensions
[
-1
<
]
any?
[
dimensions
invalid-reshape
]
when
dimensions
[
-1
=
]
count
:>
inferred inferred 1
>
[
dimensions
invalid-reshape
]
when
inferred 1
=
[
dimensions
[
dup
-1
=
[
drop
1
]
when
]
map
product
:>
known known
zero?
[
dimensions
invalid-reshape
]
when
size known
mod
zero?
[
dimensions
invalid-reshape
]
unless
dimensions
[
dup
-1
=
[
drop
size known
/i
]
when
]
map
]
[
dimensions
]
if
;