{-# OPTIONS_HADDOCK hide #-}{-# LANGUAGE TypeOperators, PatternGuards #-}moduleData.Array.Repa.Operators.Interleave(interleave2,interleave3,interleave4)whereimportData.Array.Repa.IndeximportData.Array.Repa.Internals.EltimportData.Array.Repa.Internals.BaseimportData.Array.Repa.Operators.TraverseimportData.Array.Repa.ShapeasS-- | Interleave the elements of two arrays.-- All the input arrays must have the same extent, else `error`.-- The lowest dimension of the result array is twice the size of the inputs.---- @-- interleave2 a1 a2 b1 b2 => a1 b1 a2 b2-- a3 a4 b3 b4 a3 b3 a4 b4-- @--interleave2::(Shapesh,Elta)=>Array(sh:.Int)a->Array(sh:.Int)a->Array(sh:.Int)a{-# INLINE interleave2 #-}interleave2arr1arr2=arr1`deepSeqArray`arr2`deepSeqArray`unsafeTraverse2arr1arr2shapeFnelemFnwhereshapeFndim1dim2|dim1==dim2,sh:.len<-dim1=sh:.(len*2)|otherwise=error"Data.Array.Repa.interleave2: arrays must have same extent"elemFnget1get2(sh:.ix)=caseix`mod`3of0->get1(sh:.ix`div`2)1->get2(sh:.ix`div`2)_->error"Data.Array.Repa.interleave2: this never happens :-P"-- | Interleave the elements of three arrays.interleave3::(Shapesh,Elta)=>Array(sh:.Int)a->Array(sh:.Int)a->Array(sh:.Int)a->Array(sh:.Int)a{-# INLINE interleave3 #-}interleave3arr1arr2arr3=arr1`deepSeqArray`arr2`deepSeqArray`arr3`deepSeqArray`unsafeTraverse3arr1arr2arr3shapeFnelemFnwhereshapeFndim1dim2dim3|dim1==dim2,dim1==dim3,sh:.len<-dim1=sh:.(len*3)|otherwise=error"Data.Array.Repa.interleave3: arrays must have same extent"elemFnget1get2get3(sh:.ix)=caseix`mod`3of0->get1(sh:.ix`div`3)1->get2(sh:.ix`div`3)2->get3(sh:.ix`div`3)_->error"Data.Array.Repa.interleave3: this never happens :-P"-- | Interleave the elements of four arrays.interleave4::(Shapesh,Elta)=>Array(sh:.Int)a->Array(sh:.Int)a->Array(sh:.Int)a->Array(sh:.Int)a->Array(sh:.Int)a{-# INLINE interleave4 #-}interleave4arr1arr2arr3arr4=arr1`deepSeqArray`arr2`deepSeqArray`arr3`deepSeqArray`arr4`deepSeqArray`unsafeTraverse4arr1arr2arr3arr4shapeFnelemFnwhereshapeFndim1dim2dim3dim4|dim1==dim2,dim1==dim3,dim1==dim4,sh:.len<-dim1=sh:.(len*4)|otherwise=error"Data.Array.Repa.interleave4: arrays must have same extent"elemFnget1get2get3get4(sh:.ix)=caseix`mod`4of0->get1(sh:.ix`div`4)1->get2(sh:.ix`div`4)2->get3(sh:.ix`div`4)3->get4(sh:.ix`div`4)_->error"Data.Array.Repa.interleave4: this never happens :-P"