diff yetilab/vector.yeti @ 276:39b5f3fed12d

Make slice return partial slices when range extents overlap vector ends
author Chris Cannam
date Sat, 25 May 2013 18:31:10 +0100
parents 197d23954a4e
children 21ec05237c1a
line wrap: on
line diff
--- a/yetilab/vector.yeti	Sat May 25 18:18:10 2013 +0100
+++ b/yetilab/vector.yeti	Sat May 25 18:31:10 2013 +0100
@@ -72,7 +72,15 @@
 
 //!!! doc note: argument order chosen for consistency with std module function
 slice v start end is ~double[] -> number -> number -> ~double[] =
-    Arrays#copyOfRange(v, start, end);
+    if start < 0 then slice v 0 end
+    elif start > length' v then slice v (length' v) end
+    else
+        if end < start then slice v start start
+        elif end > length' v then slice v start (length' v)
+        else
+            Arrays#copyOfRange(v, start, end);
+        fi
+    fi;
 
 resizedTo n v is number -> ~double[] -> ~double[] =
     Arrays#copyOf(v, n);