From d0fd75b20876e1ae6250817f0507d6e36fd9f658 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 8 Jan 2020 09:05:06 -0800 Subject: [PATCH] tensors.tensor-slice: make step-slice not extend slice. This caused a small regression in compiler.tree.cleanup on this test: { t } [ [ { array } declare 2 [ . . ] assoc-each ] \ nth-unsafe inlined? ] unit-test I'm not entirely sure why it wasn't able to infer the slice that was created for iteration stays a slice, and never becomes a step-slice, so perhaps there is some improvement to be made in type inference here. --- extra/tensors/tensor-slice/tensor-slice.factor | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/extra/tensors/tensor-slice/tensor-slice.factor b/extra/tensors/tensor-slice/tensor-slice.factor index 47124bf768..275d62600e 100644 --- a/extra/tensors/tensor-slice/tensor-slice.factor +++ b/extra/tensors/tensor-slice/tensor-slice.factor @@ -1,7 +1,12 @@ USING: accessors kernel locals math math.order sequences ; IN: tensors.tensor-slice -TUPLE: step-slice < slice { step integer read-only } ; +TUPLE: step-slice + { from integer read-only initial: 0 } + { to integer read-only initial: 0 } + { seq read-only } + { step integer read-only } ; + :: ( from to step seq -- step-slice ) step zero? [ "can't be zero" throw ] when seq length :> len @@ -17,10 +22,14 @@ TUPLE: step-slice < slice { step integer read-only } ; seq dup slice? [ collapse-slice ] when step step-slice boa ; +M: step-slice virtual-exemplar seq>> ; inline + M: step-slice virtual@ - [ step>> * ] [ from>> + ] [ seq>> ] tri ; + [ step>> * ] [ from>> + ] [ seq>> ] tri ; inline M: step-slice length [ to>> ] [ from>> - ] [ step>> ] tri dup 0 < [ [ neg 0 max ] dip neg ] when /mod - zero? [ 1 + ] unless ; \ No newline at end of file + zero? [ 1 + ] unless ; inline + +INSTANCE: step-slice virtual-sequence