module Data.Array.Parallel.Unlifted.Sequential.Segmented.Subarrays (
sliceSU, extractSU, takeCU, dropCU
) where
import Data.Array.Parallel.Unlifted.Sequential.Flat (
UA, (!:), sliceU, extractU, lengthU)
import Data.Array.Parallel.Unlifted.Sequential.Segmented.SUArr (
SUArr, sliceUSegd, extractUSegd, (>:), segdSU, lengthSU, indicesSU)
import Data.Array.Parallel.Unlifted.Sequential.Segmented.Basics (
concatSU)
sliceSU :: UA e => SUArr e -> Int -> Int -> SUArr e
sliceSU sa i n =
let
a = concatSU sa
i' = indicesSU sa !: i
j = if i+n == lengthSU sa then lengthU a else indicesSU sa !: (i+n)
in
sliceUSegd (segdSU sa) i n >: sliceU a i' j
extractSU :: UA e => SUArr e -> Int -> Int -> SUArr e
extractSU sa i n =
let
a = concatSU sa
i' = indicesSU sa !: i
j = if i+n == lengthSU sa then lengthU a else indicesSU sa !: (i+n)
in
extractUSegd (segdSU sa) i n >: extractU a i' j
takeCU:: (UA e) => Int -> SUArr e -> SUArr e
takeCU n xssArr = sliceSU xssArr 0 n
dropCU:: (UA e) => Int -> SUArr e -> SUArr e
dropCU n xssArr = sliceSU xssArr n (lengthSU xssArr n)