{-# LANGUAGE TypeOperators, ExplicitForAll, FlexibleContexts #-}moduleData.Array.Repa.Operators.Interleave(interleave2,interleave3,interleave4)whereimportData.Array.Repa.ShapeimportData.Array.Repa.IndeximportData.Array.Repa.BaseimportData.Array.Repa.Repr.DelayedimportData.Array.Repa.Operators.TraversalimportPreludehiding((++))-- Interleave ------------------------------------------------------------------- | 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,Sourcer1a,Sourcer2a)=>Arrayr1(sh:.Int)a->Arrayr2(sh:.Int)a->ArrayD(sh:.Int)a{-# INLINE [2] interleave2 #-}interleave2arr1arr2=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`2of0->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,Sourcer1a,Sourcer2a,Sourcer3a)=>Arrayr1(sh:.Int)a->Arrayr2(sh:.Int)a->Arrayr3(sh:.Int)a->ArrayD(sh:.Int)a{-# INLINE [2] interleave3 #-}interleave3arr1arr2arr3=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,Sourcer1a,Sourcer2a,Sourcer3a,Sourcer4a)=>Arrayr1(sh:.Int)a->Arrayr2(sh:.Int)a->Arrayr3(sh:.Int)a->Arrayr4(sh:.Int)a->ArrayD(sh:.Int)a{-# INLINE [2] interleave4 #-}interleave4arr1arr2arr3arr4=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"