├── .authorspellings ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── Makefile ├── README.md ├── RELEASE-CHECKLIST.md ├── cabal.project ├── icebox ├── abandoned │ ├── DirectFlow.hs │ ├── repa-coflow │ │ └── Data │ │ │ └── Array │ │ │ └── Repa │ │ │ └── CoFlow │ │ │ ├── Base.hs │ │ │ └── Seq │ │ │ └── Base.hs │ ├── repa-flow │ │ ├── Data │ │ │ └── Array │ │ │ │ └── Repa │ │ │ │ └── Flow │ │ │ │ ├── Base.hs │ │ │ │ ├── Par.hs │ │ │ │ ├── Par │ │ │ │ ├── Distro.hs │ │ │ │ ├── Flow.hs │ │ │ │ ├── Operator │ │ │ │ │ ├── Append.hs │ │ │ │ │ ├── Fold.hs │ │ │ │ │ ├── Generate.hs │ │ │ │ │ ├── Map.hs │ │ │ │ │ ├── Pack.hs │ │ │ │ │ └── Project.hs │ │ │ │ ├── Segd.hs │ │ │ │ └── SegdSplit.hs │ │ │ │ ├── Seq.hs │ │ │ │ └── Seq │ │ │ │ ├── Base.hs │ │ │ │ ├── Operator │ │ │ │ ├── Append.hs │ │ │ │ ├── Combine.hs │ │ │ │ ├── Dup.hs │ │ │ │ ├── Fold.hs │ │ │ │ ├── Generate.hs │ │ │ │ ├── Map.hs │ │ │ │ ├── Pack.hs │ │ │ │ ├── Project.hs │ │ │ │ ├── Slurp.hs │ │ │ │ └── Zip.hs │ │ │ │ ├── Report.hs │ │ │ │ ├── Sink.hs │ │ │ │ └── Source.hs │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── NOTES │ │ ├── Setup.hs │ │ ├── repa-flow.cabal │ │ └── test │ │ │ ├── fusion │ │ │ ├── TestPar.hs │ │ │ └── TestSeq.hs │ │ │ ├── props │ │ │ ├── TestPar.hs │ │ │ └── TestSeq.hs │ │ │ └── seq │ │ │ └── Unboxed.hs │ ├── repa-plugin │ │ ├── Data │ │ │ └── Array │ │ │ │ └── Repa │ │ │ │ ├── Plugin.hs │ │ │ │ └── Plugin │ │ │ │ ├── FatName.hs │ │ │ │ ├── GHC │ │ │ │ └── Pretty.hs │ │ │ │ ├── Pass │ │ │ │ ├── Dump.hs │ │ │ │ └── Lower.hs │ │ │ │ ├── Pipeline.hs │ │ │ │ ├── Primitives.hs │ │ │ │ ├── Primitives │ │ │ │ └── Selectors.hs │ │ │ │ ├── ToDDC.hs │ │ │ │ ├── ToDDC │ │ │ │ ├── Convert.hs │ │ │ │ ├── Convert │ │ │ │ │ ├── Base.hs │ │ │ │ │ ├── Type.hs │ │ │ │ │ └── Var.hs │ │ │ │ ├── Detect.hs │ │ │ │ └── Detect │ │ │ │ │ ├── Base.hs │ │ │ │ │ ├── Prim.hs │ │ │ │ │ └── Type.hs │ │ │ │ ├── ToGHC.hs │ │ │ │ └── ToGHC │ │ │ │ ├── Prim.hs │ │ │ │ ├── Type.hs │ │ │ │ ├── Var.hs │ │ │ │ └── Wrap.hs │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── repa-plugin.cabal │ │ └── test │ │ │ ├── 01-Simple │ │ │ └── Main.hs │ │ │ ├── 02-Opaque │ │ │ └── Main.hs │ │ │ ├── 03-Prims │ │ │ └── Main.hs │ │ │ ├── 10-Pack │ │ │ └── Main.hs │ │ │ ├── 20-Vector │ │ │ └── Main.hs │ │ │ └── 90-Benchmarks │ │ │ ├── c │ │ │ ├── Makefile │ │ │ └── src │ │ │ │ ├── Main_DotProduct.c │ │ │ │ ├── Main_FilterMax.c │ │ │ │ ├── Main_FilterSum.c │ │ │ │ ├── Main_MapMap.c │ │ │ │ ├── Main_NestedFilter.c │ │ │ │ ├── Main_QuickHull.c │ │ │ │ ├── QuickHull.c │ │ │ │ ├── Timing.c │ │ │ │ ├── Timing.h │ │ │ │ └── Vector.h │ │ │ └── repa │ │ │ ├── DotProduct │ │ │ ├── Main.hs │ │ │ └── Vector.hs │ │ │ ├── FilterMax │ │ │ └── Main.hs │ │ │ ├── FilterSum │ │ │ ├── Main.hs │ │ │ └── Vector.hs │ │ │ ├── MapMap │ │ │ ├── Main.hs │ │ │ └── Vector.hs │ │ │ ├── NestedFilter │ │ │ ├── Main.hs │ │ │ └── Vector.hs │ │ │ ├── Points │ │ │ └── Main.hs │ │ │ ├── QuickHull │ │ │ ├── Main.hs │ │ │ └── Vector.hs │ │ │ └── QuickSort │ │ │ └── Quicksort.hs │ ├── repa-series │ │ ├── Data │ │ │ └── Array │ │ │ │ └── Repa │ │ │ │ ├── Series.hs │ │ │ │ └── Series │ │ │ │ ├── Fallback.hs │ │ │ │ ├── Prim.hs │ │ │ │ ├── Prim │ │ │ │ ├── Double.hs │ │ │ │ ├── Float.hs │ │ │ │ ├── Int.hs │ │ │ │ ├── Loop.hs │ │ │ │ ├── Utils.hs │ │ │ │ └── Word.hs │ │ │ │ ├── Process.hs │ │ │ │ ├── Rate.hs │ │ │ │ ├── Ref.hs │ │ │ │ ├── Sel.hs │ │ │ │ ├── Series.hs │ │ │ │ └── Vector.hs │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── icebox │ │ │ └── Series.hs │ │ └── repa-series.cabal │ ├── repa-stream │ │ ├── Data │ │ │ └── Array │ │ │ │ └── Repa │ │ │ │ ├── Chain.hs │ │ │ │ ├── Chain │ │ │ │ ├── Append.hs │ │ │ │ ├── Base.hs │ │ │ │ ├── Eval.hs │ │ │ │ ├── Indexed.hs │ │ │ │ ├── Indexs.hs │ │ │ │ ├── Map.hs │ │ │ │ └── Replicate.hs │ │ │ │ ├── Distro.hs │ │ │ │ ├── Stream.hs │ │ │ │ └── Stream │ │ │ │ ├── Base.hs │ │ │ │ ├── Combine.hs │ │ │ │ ├── Eval.hs │ │ │ │ ├── Flatten.hs │ │ │ │ ├── Fold.hs │ │ │ │ ├── Indexs.hs │ │ │ │ ├── Map.hs │ │ │ │ ├── Pack.hs │ │ │ │ └── Scan.hs │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── repa-stream.cabal │ │ ├── scratch │ │ │ ├── Solver.hs │ │ │ └── Stream.hs │ │ └── test │ │ │ └── fusion │ │ │ ├── Map.hs │ │ │ └── Replicate.hs │ ├── repa-vector-old │ │ ├── Data │ │ │ └── Vector │ │ │ │ ├── Repa.hs │ │ │ │ └── Repa │ │ │ │ ├── Base.hs │ │ │ │ ├── Operators │ │ │ │ ├── Chains.hs │ │ │ │ ├── Replicate.hs │ │ │ │ └── Zip.hs │ │ │ │ └── Repr │ │ │ │ ├── Chain.hs │ │ │ │ ├── Chunked.hs │ │ │ │ └── Sliced.hs │ │ ├── chains │ │ │ └── Data │ │ │ │ └── Array │ │ │ │ └── Repa │ │ │ │ ├── Repr │ │ │ │ ├── Chain.hs │ │ │ │ └── Stream.hs │ │ │ │ ├── Vector.hs │ │ │ │ └── Vector │ │ │ │ ├── Base.hs │ │ │ │ ├── Operators │ │ │ │ ├── Combine.hs │ │ │ │ ├── Flatten.hs │ │ │ │ ├── Fold.hs │ │ │ │ ├── Indexed.hs │ │ │ │ ├── Indexs.hs │ │ │ │ ├── Map.hs │ │ │ │ ├── Pack.hs │ │ │ │ ├── Scan.hs │ │ │ │ └── Zip.hs │ │ │ │ ├── Segd.hs │ │ │ │ ├── Segd │ │ │ │ └── Split.hs │ │ │ │ └── Sel.hs │ │ ├── compile-test │ │ ├── cuts │ │ │ ├── Unboxed.hs │ │ │ └── Vector.hs │ │ └── fusion │ │ │ ├── ChainChunk.hs │ │ │ └── ChainSeq.hs │ └── repa-vector │ │ ├── Data │ │ └── Array │ │ │ └── Repa │ │ │ ├── Vector.hs │ │ │ └── Vector │ │ │ ├── Base.hs │ │ │ ├── Compute.hs │ │ │ ├── Compute │ │ │ ├── Load.hs │ │ │ └── Target.hs │ │ │ ├── Distro.hs │ │ │ ├── Index.hs │ │ │ ├── Operators │ │ │ ├── Append.hs │ │ │ ├── Bulk.hs │ │ │ ├── Combine.hs │ │ │ ├── Flatten.hs │ │ │ ├── Fold.hs │ │ │ ├── Map.hs │ │ │ ├── Pack.hs │ │ │ ├── Project.hs │ │ │ ├── Replicate.hs │ │ │ ├── Traverse.hs │ │ │ ├── Unzip.hs │ │ │ └── Zip.hs │ │ │ ├── Repr │ │ │ ├── Delayed.hs │ │ │ ├── Flow.hs │ │ │ └── Unboxed.hs │ │ │ ├── Segd.hs │ │ │ └── Shape.hs │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── repa-vector.cabal │ │ └── test │ │ ├── Test.hs │ │ └── props │ │ └── Test.hs ├── deprecated │ └── repa-bytestring │ │ ├── LICENSE │ │ ├── Setup.hs │ │ └── repa-bytestring.cabal └── stashed │ ├── Base.hs │ ├── Boxed.hs │ ├── Checked.hs │ ├── Foreign.hs │ └── Unboxed.hs ├── repa-algorithms ├── Data │ └── Array │ │ └── Repa │ │ └── Algorithms │ │ ├── ColorRamp.hs │ │ ├── Complex.hs │ │ ├── Convolve.hs │ │ ├── DFT.hs │ │ ├── DFT │ │ ├── Center.hs │ │ └── Roots.hs │ │ ├── FFT.hs │ │ ├── Matrix.hs │ │ ├── Pixel.hs │ │ └── Randomish.hs ├── LICENSE ├── Setup.hs └── repa-algorithms.cabal ├── repa-array ├── Data │ └── Repa │ │ ├── Array.hs │ │ ├── Array │ │ ├── Auto.hs │ │ ├── Auto │ │ │ ├── Base.hs │ │ │ ├── Convert.hs │ │ │ ├── Format.hs │ │ │ ├── IO.hs │ │ │ ├── Operator.hs │ │ │ └── XSV.hs │ │ ├── Generic.hs │ │ ├── Generic │ │ │ ├── Convert.hs │ │ │ ├── Index.hs │ │ │ ├── Load.hs │ │ │ ├── Slice.hs │ │ │ ├── Target.hs │ │ │ └── Unpacks.hs │ │ ├── Internals │ │ │ ├── Bulk.hs │ │ │ ├── Check.hs │ │ │ ├── Layout.hs │ │ │ ├── Load.hs │ │ │ ├── Operator │ │ │ │ ├── Compact.hs │ │ │ │ ├── Concat.hs │ │ │ │ ├── Filter.hs │ │ │ │ ├── Fold.hs │ │ │ │ ├── Group.hs │ │ │ │ ├── Insert.hs │ │ │ │ ├── Merge.hs │ │ │ │ ├── Partition.hs │ │ │ │ ├── Process.hs │ │ │ │ ├── Reduce.hs │ │ │ │ └── Replicate.hs │ │ │ ├── Shape.hs │ │ │ └── Target.hs │ │ ├── Material.hs │ │ ├── Material │ │ │ ├── Auto.hs │ │ │ ├── Auto │ │ │ │ ├── Base.hs │ │ │ │ ├── InstArray.hs │ │ │ │ ├── InstBox.hs │ │ │ │ ├── InstChar.hs │ │ │ │ ├── InstDate32.hs │ │ │ │ ├── InstFloat.hs │ │ │ │ ├── InstInt.hs │ │ │ │ ├── InstList.hs │ │ │ │ ├── InstMaybe.hs │ │ │ │ ├── InstProduct.hs │ │ │ │ ├── InstText.hs │ │ │ │ ├── InstTuple.hs │ │ │ │ ├── InstUnit.hs │ │ │ │ ├── InstWord.hs │ │ │ │ └── Operator │ │ │ │ │ ├── Lines.hs │ │ │ │ │ └── Unpackables.hs │ │ │ ├── Boxed.hs │ │ │ ├── Foreign.hs │ │ │ ├── Foreign │ │ │ │ ├── Base.hs │ │ │ │ └── Lines.hs │ │ │ ├── Nested.hs │ │ │ └── Unboxed.hs │ │ ├── Meta.hs │ │ └── Meta │ │ │ ├── Delayed.hs │ │ │ ├── Delayed2.hs │ │ │ ├── Dense.hs │ │ │ ├── Linear.hs │ │ │ ├── RowWise.hs │ │ │ ├── Tuple.hs │ │ │ └── Window.hs │ │ ├── Eval │ │ ├── Chain.hs │ │ └── Stream.hs │ │ ├── Fusion │ │ └── Unpack.hs │ │ ├── Nice.hs │ │ └── Nice │ │ ├── Display.hs │ │ ├── Present.hs │ │ └── Tabulate.hs ├── LICENSE ├── include │ └── repa-array.h └── repa-array.cabal ├── repa-convert ├── Data │ └── Repa │ │ ├── Convert.hs │ │ └── Convert │ │ ├── Format.hs │ │ ├── Format │ │ ├── App.hs │ │ ├── Ascii.hs │ │ ├── Binary.hs │ │ ├── Bytes.hs │ │ ├── Date32.hs │ │ ├── Fields.hs │ │ ├── Maybe.hs │ │ ├── Numeric.hs │ │ ├── Object.hs │ │ ├── Sep.hs │ │ ├── String.hs │ │ ├── Text.hs │ │ └── Unit.hs │ │ ├── Formats.hs │ │ └── Internal │ │ ├── Format.hs │ │ ├── Packable.hs │ │ ├── Packer.hs │ │ └── Unpacker.hs ├── LICENSE ├── include │ └── repa-convert.h └── repa-convert.cabal ├── repa-eval ├── Data │ └── Repa │ │ └── Eval │ │ ├── Elt.hs │ │ ├── Gang.hs │ │ └── Generic │ │ ├── Par.hs │ │ ├── Par │ │ ├── Chunked.hs │ │ ├── Cursored.hs │ │ ├── Interleaved.hs │ │ └── Reduction.hs │ │ ├── Seq.hs │ │ └── Seq │ │ ├── Chunked.hs │ │ ├── Cursored.hs │ │ └── Reduction.hs ├── LICENSE ├── Setup.hs └── repa-eval.cabal ├── repa-examples ├── LICENSE ├── Makefile ├── Setup.hs ├── broken │ ├── Fluid │ │ └── legacy │ │ │ ├── demo.c │ │ │ └── solver.c │ └── MDim │ │ └── MDim.hs ├── data │ ├── cosine-horizontal.bmp.gz │ ├── cosine-rotated.bmp.gz │ ├── cosine-vertical.bmp.gz │ ├── lena.bmp.gz │ └── step20.bmp.gz ├── examples │ ├── Blur │ │ └── src-repa │ │ │ └── Main.hs │ ├── Canny │ │ ├── src-opencv │ │ │ └── Main.cpp │ │ └── src-repa │ │ │ └── Main.hs │ ├── FFT │ │ ├── FFT2d │ │ │ └── src-repa │ │ │ │ └── Main.hs │ │ ├── HighPass2d │ │ │ ├── src-fftw │ │ │ │ ├── FFTW.c │ │ │ │ ├── Jones.c │ │ │ │ └── Main.c │ │ │ ├── src-paper │ │ │ │ ├── FFT.hs │ │ │ │ └── Main.hs │ │ │ ├── src-repa │ │ │ │ └── Main.hs │ │ │ ├── src-split │ │ │ │ └── FFT.hs │ │ │ ├── src-traverse │ │ │ │ └── FFT.hs │ │ │ └── src-vector │ │ │ │ ├── FFT.hs │ │ │ │ └── Main.hs │ │ ├── HighPass3d │ │ │ ├── src-fftw │ │ │ │ └── Main.c │ │ │ └── src-repa │ │ │ │ └── Main.hs │ │ └── Paper │ │ │ └── src-repa │ │ │ ├── Main.hs │ │ │ └── Paper.hs │ ├── Laplace │ │ ├── data │ │ │ ├── pls-100x100.bmp.gz │ │ │ ├── pls-100x100.pxm │ │ │ └── pls-400x400.bmp.gz │ │ ├── src-c │ │ │ └── Main.c │ │ └── src-repa │ │ │ ├── Main.hs │ │ │ ├── SolverGet.hs │ │ │ └── SolverStencil.hs │ ├── MMult │ │ ├── data │ │ │ ├── id-10x10.mat │ │ │ ├── random1-100x100.mat.gz │ │ │ ├── random2-100x100.mat.gz │ │ │ └── up-4x4.mat │ │ ├── src-c │ │ │ └── Main.c │ │ └── src-repa │ │ │ ├── Main.hs │ │ │ └── Solver.hs │ ├── PageRank │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── data │ │ │ ├── pages.txt │ │ │ └── titles.txt │ │ ├── pagerank.cabal │ │ └── src │ │ │ ├── External │ │ │ ├── Count.hs │ │ │ ├── Rank.hs │ │ │ ├── Step.hs │ │ │ └── Titles.hs │ │ │ ├── Internal │ │ │ ├── Load.hs │ │ │ ├── Rank.hs │ │ │ └── Step.hs │ │ │ ├── Main.hs │ │ │ ├── Page.hs │ │ │ └── Progress.hs │ ├── QuickHull │ │ ├── Main.hs │ │ ├── Points.hs │ │ ├── SVG.hs │ │ ├── Solver.hs │ │ ├── SolverChunks.hs │ │ └── old │ │ │ ├── QuickHull.hs │ │ │ └── Solver.hs │ ├── QuickSelect │ │ ├── Solver.hs │ │ └── Test.hs │ ├── SMVM │ │ ├── Main.hs │ │ ├── Solver.hs │ │ └── Test.hs │ ├── Sobel │ │ ├── src-opencv │ │ │ └── Main.cpp │ │ └── src-repa │ │ │ ├── Main.hs │ │ │ ├── Solver.hs │ │ │ └── SolverSeparated.hs │ ├── ThreadLocal │ │ └── Main.hs │ ├── UnitTesting │ │ └── UnitTesting.hs │ └── Volume │ │ └── Main.hs ├── libc │ ├── BMP.c │ ├── BMP.h │ ├── ColorRamp.c │ ├── ColorRamp.h │ ├── Matrix.c │ ├── Matrix.h │ ├── Timing.c │ └── Timing.h └── repa-examples.cabal ├── repa-flow ├── Data │ └── Repa │ │ ├── Flow.hs │ │ └── Flow │ │ ├── Auto.hs │ │ ├── Auto │ │ ├── Base.hs │ │ ├── Debug.hs │ │ ├── Format.hs │ │ ├── IO.hs │ │ ├── Select.hs │ │ ├── SizedIO.hs │ │ └── ZipWith.hs │ │ ├── Chunked.hs │ │ ├── Chunked │ │ ├── Base.hs │ │ ├── Fold.hs │ │ ├── Folds.hs │ │ ├── Generic.hs │ │ ├── Groups.hs │ │ ├── IO.hs │ │ ├── Map.hs │ │ ├── Process.hs │ │ └── Replicate.hs │ │ ├── Generic.hs │ │ ├── Generic │ │ ├── Array │ │ │ ├── Chunk.hs │ │ │ ├── Distribute.hs │ │ │ ├── Shuffle.hs │ │ │ └── Unchunk.hs │ │ ├── Base.hs │ │ ├── Connect.hs │ │ ├── Debug.hs │ │ ├── Eval.hs │ │ ├── IO.hs │ │ ├── IO │ │ │ ├── Base.hs │ │ │ ├── Lines.hs │ │ │ ├── Sieve.hs │ │ │ └── XSV.hs │ │ ├── List.hs │ │ ├── Map.hs │ │ ├── Operator.hs │ │ └── Process.hs │ │ ├── IO │ │ └── Bucket.hs │ │ ├── Simple.hs │ │ ├── Simple │ │ ├── Base.hs │ │ ├── Chunk.hs │ │ ├── IO.hs │ │ ├── List.hs │ │ └── Operator.hs │ │ └── States.hs ├── LICENSE ├── examples │ ├── 00-Start │ │ └── Main.hs │ ├── 01-Copy │ │ └── Main.hs │ ├── 02-Fields │ │ └── Main.hs │ ├── 03-GroupSum │ │ └── Main.hs │ ├── 04-Shuffle │ │ └── Main.hs │ └── 05-Sieve │ │ └── Config.hs ├── include │ └── repa-flow.h ├── repa-flow.cabal └── tutorial │ └── 00-GettingStarted.ipynb ├── repa-io ├── Data │ └── Array │ │ └── Repa │ │ └── IO │ │ ├── BMP.hs │ │ ├── Binary.hs │ │ ├── Internals │ │ └── Text.hs │ │ ├── Matrix.hs │ │ ├── Timing.hs │ │ └── Vector.hs ├── LICENSE ├── Setup.hs └── repa-io.cabal ├── repa-machine ├── Data │ └── Repa │ │ ├── Machine.hs │ │ └── Machine │ │ ├── Base.hs │ │ ├── Eval.hs │ │ ├── Step.hs │ │ └── Transition.hs ├── LICENSE ├── example │ └── Map.hs └── repa-machine.cabal ├── repa-query ├── Data │ └── Repa │ │ ├── Query.hs │ │ └── Query │ │ ├── Build.hs │ │ ├── Build │ │ ├── Repa.hs │ │ └── Repa │ │ │ ├── Exp.hs │ │ │ ├── Graph.hs │ │ │ └── Job.hs │ │ ├── Graph.hs │ │ ├── Graph │ │ ├── Compounds.hs │ │ ├── Eval.hs │ │ ├── Eval │ │ │ ├── Env.hs │ │ │ └── Exp.hs │ │ ├── Exp.hs │ │ ├── Graph.hs │ │ └── JSON.hs │ │ ├── Job.hs │ │ ├── Job │ │ ├── Exec.hs │ │ ├── JSON.hs │ │ └── Spec.hs │ │ ├── Runtime.hs │ │ ├── Runtime │ │ ├── Driver.hs │ │ └── Primitive.hs │ │ ├── Source.hs │ │ ├── Source │ │ ├── Builder.hs │ │ ├── External.hs │ │ ├── Interact.hs │ │ └── Primitive │ │ │ ├── Literal.hs │ │ │ ├── Operator.hs │ │ │ ├── Projection.hs │ │ │ ├── Scalar.hs │ │ │ └── Sources.hs │ │ └── Transform │ │ └── Namify.hs ├── LICENSE ├── include │ └── repa-query.h └── repa-query.cabal ├── repa-scalar ├── Data │ └── Repa │ │ └── Scalar │ │ ├── Box.hs │ │ ├── Date32.hs │ │ ├── Double.hs │ │ ├── Int.hs │ │ ├── Option.hs │ │ ├── Product.hs │ │ └── Singleton │ │ ├── Bool.hs │ │ └── Nat.hs ├── LICENSE └── repa-scalar.cabal ├── repa-store ├── Data │ └── Repa │ │ └── Store │ │ ├── Codec │ │ └── XSV.hs │ │ ├── Flow.hs │ │ ├── Format.hs │ │ ├── Object.hs │ │ ├── Object │ │ ├── Column.hs │ │ ├── Dimension.hs │ │ ├── Family.hs │ │ └── Table.hs │ │ ├── Partitions.hs │ │ ├── Prim │ │ ├── BiMap.hs │ │ └── HashLog.hs │ │ └── Resolve.hs ├── LICENSE ├── include │ └── repa-store.h └── repa-store.cabal ├── repa-stream ├── Data │ └── Repa │ │ ├── Chain.hs │ │ ├── Chain │ │ ├── Base.hs │ │ ├── Folds.hs │ │ ├── Scan.hs │ │ └── Weave.hs │ │ ├── Stream.hs │ │ ├── Stream │ │ ├── Compact.hs │ │ ├── Concat.hs │ │ ├── Dice.hs │ │ ├── Extract.hs │ │ ├── Insert.hs │ │ ├── Merge.hs │ │ ├── Pad.hs │ │ ├── Ratchet.hs │ │ ├── Replicate.hs │ │ └── Segment.hs │ │ └── Vector │ │ ├── Generic.hs │ │ └── Unboxed.hs ├── LICENSE ├── include │ └── repa-stream.h └── repa-stream.cabal ├── repa-tools ├── LICENSE ├── repa-tools.cabal └── tools │ ├── build │ ├── Config.hs │ └── Main.hs │ ├── fields │ ├── Config.hs │ └── Main.hs │ ├── sieve │ ├── Config.hs │ └── Main.hs │ └── tags │ ├── Config.hs │ └── Main.hs ├── repa ├── Data │ └── Array │ │ ├── Repa.hs │ │ └── Repa │ │ ├── Arbitrary.hs │ │ ├── Base.hs │ │ ├── Eval.hs │ │ ├── Eval │ │ ├── Chunked.hs │ │ ├── Cursored.hs │ │ ├── Elt.hs │ │ ├── Gang.hs │ │ ├── Interleaved.hs │ │ ├── Load.hs │ │ ├── Reduction.hs │ │ ├── Selection.hs │ │ └── Target.hs │ │ ├── Index.hs │ │ ├── Operators │ │ ├── IndexSpace.hs │ │ ├── Interleave.hs │ │ ├── Mapping.hs │ │ ├── Reduction.hs │ │ ├── Selection.hs │ │ └── Traversal.hs │ │ ├── Repr │ │ ├── ByteString.hs │ │ ├── Cursored.hs │ │ ├── Delayed.hs │ │ ├── ForeignPtr.hs │ │ ├── HintInterleave.hs │ │ ├── HintSmall.hs │ │ ├── Partitioned.hs │ │ ├── Unboxed.hs │ │ ├── Undefined.hs │ │ └── Vector.hs │ │ ├── Shape.hs │ │ ├── Slice.hs │ │ ├── Specialised │ │ └── Dim2.hs │ │ ├── Stencil.hs │ │ ├── Stencil │ │ ├── Base.hs │ │ ├── Dim2.hs │ │ ├── Partition.hs │ │ └── Template.hs │ │ └── Unsafe.hs ├── LICENSE ├── Setup.hs └── repa.cabal ├── stack-7.10.yaml ├── stack-8.0.yaml ├── stack-8.2.yaml ├── stack-8.4.yaml └── stack-8.6.yaml /.authorspellings: -------------------------------------------------------------------------------- 1 | Ben Lippmeier , Ben.Lippmeier@anu.edu.au 2 | Amos Robinson , amos.robinson@gmail.com 3 | Anders Persson -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | continuous-integration: 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | ghc-version: 13 | - "8.10.7" 14 | - "9.0.2" 15 | - "9.2.8" 16 | - "9.4.8" 17 | - "9.6.6" 18 | - "9.8.2" 19 | - "9.10.1" 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | 24 | - name: Install cabal/ghc 25 | uses: haskell-actions/setup@v2 26 | id: setup-haskell 27 | with: 28 | ghc-version: ${{ matrix.ghc-version }} 29 | cabal-version: '3.10.3.0' 30 | 31 | - name: Generate freeze file 32 | run: | 33 | cabal update 34 | cabal configure --disable-optimization --enable-tests 35 | cabal freeze 36 | 37 | - name: Cache cabal work 38 | uses: actions/cache@v4 39 | with: 40 | path: | 41 | dist-newstyle 42 | ${{ steps.setup-haskell.outputs.cabal-store }} 43 | key: ${{ runner.os }}-${{ hashFiles('cabal.project.freeze', 'cabal.project.local') }}-cabal-install 44 | 45 | - name: Build dependencies 46 | run: | 47 | cabal build all --only-dependencies 48 | 49 | - name: Build packages 50 | run: | 51 | cabal build all 52 | 53 | - name: Run tests 54 | run: | 55 | cabal test all 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .stack-work 2 | /stack.yaml 3 | dist 4 | dist-* 5 | cabal-dev 6 | *.o 7 | *.hi 8 | *.hie 9 | *.chi 10 | *.chs.h 11 | *.dyn_o 12 | *.dyn_hi 13 | .hpc 14 | .hsenv 15 | .cabal-sandbox/ 16 | cabal.sandbox.config 17 | *.prof 18 | *.aux 19 | *.hp 20 | *.eventlog 21 | cabal.project.local 22 | cabal.project.local~ 23 | .HTF/ 24 | .ghc.environment.* -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule ".travis"] 2 | path = .travis 3 | url = https://github.com/tmcdonell/travis-scripts.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | repa 2 | ==== 3 | 4 | Repa provides high performance, regular, multi-dimensional, shape polymorphic parallel arrays. 5 | All numeric data is stored unboxed. Functions written with the Repa combinators are automatically 6 | parallel provided you supply +RTS -Nwhatever on the command line when running the program. 7 | -------------------------------------------------------------------------------- /RELEASE-CHECKLIST.md: -------------------------------------------------------------------------------- 1 | # Releasing new versions of Repa packages 2 | 3 | 1. Update the versions in Cabal files and update the `CHANGELOG.md` files to describe changes associated with these version; 4 | 2. Commit changes; 5 | 3. Tag the commit and push to GitHub: 6 | 7 | ```bash 8 | $ git tag -a "vW.X.Y.Z" && git push origin "vW.X.Y.Z" 9 | ``` 10 | 11 | 4. Create source distributions: 12 | 13 | ```bash 14 | $ cabal sdist all 15 | Wrote tarball sdist to 16 | (...)/dist-newstyle/sdist/-W.X.Y.Z.tar.gz 17 | ``` 18 | 19 | 5. Upload to Hackage: 20 | 21 | ```bash 22 | $ cabal upload --publish (...)/dist-newstyle/sdist/* 23 | ``` 24 | 25 | That's it! -------------------------------------------------------------------------------- /cabal.project: -------------------------------------------------------------------------------- 1 | packages: repa/repa.cabal 2 | repa-algorithms/repa-algorithms.cabal 3 | repa-examples/repa-examples.cabal 4 | repa-io/repa-io.cabal 5 | 6 | repa-scalar/repa-scalar.cabal 7 | repa-eval/repa-eval.cabal 8 | repa-convert/repa-convert.cabal 9 | -- Packages below are ignored until they can be updated 10 | -- to support newer GHCs 11 | 12 | -- repa-stream/repa-stream.cabal 13 | 14 | -- We ignore some packages which depend on repa-array rather than repa 15 | -- repa-array/repa-array.cabal 16 | -- repa-flow/repa-flow.cabal 17 | -- repa-query/repa-query.cabal 18 | -- repa-tools/repa-tools.cabal 19 | -- repa-store/repa-store.cabal 20 | -- repa-machine/repa-machine.cabal 21 | 22 | 23 | minimize-conflict-set: true -------------------------------------------------------------------------------- /icebox/abandoned/repa-flow/Data/Array/Repa/Flow/Par.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Flow.Par 3 | ( Flow (..) 4 | , Distro (..) 5 | 6 | -- * Conversion 7 | , flow 8 | , Unflow (..) 9 | 10 | -- * Construction 11 | , generate 12 | , replicate 13 | , replicates 14 | , replicatesSplit 15 | , enumFromN 16 | , appends 17 | 18 | -- * Mapping 19 | , map 20 | , zip 21 | , zipWith 22 | , zipLeft 23 | , zipLeftWith 24 | 25 | -- * Projection 26 | , gather 27 | 28 | -- * Packing 29 | , packByTag 30 | , packByFlag 31 | , filter 32 | 33 | -- * Reduction 34 | , folds 35 | , sums) 36 | where 37 | import Data.Array.Repa.Flow.Par.Flow 38 | import Data.Array.Repa.Flow.Par.Operator.Map 39 | import Data.Array.Repa.Flow.Par.Operator.Generate 40 | import Data.Array.Repa.Flow.Par.Operator.Append 41 | import Data.Array.Repa.Flow.Par.Operator.Pack 42 | import Data.Array.Repa.Flow.Par.Operator.Project 43 | import Data.Array.Repa.Flow.Par.Operator.Fold 44 | import Prelude hiding (map, zip, zipWith, replicate, filter) 45 | 46 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-flow/Data/Array/Repa/Flow/Par/Operator/Project.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Flow.Par.Operator.Project 3 | (gather) 4 | where 5 | import Data.Array.Repa.Flow.Par.Flow 6 | import qualified Data.Array.Repa.Flow.Seq as Seq 7 | import GHC.Exts 8 | 9 | 10 | -- | Takes a vector and a flow of indices, and produces a flow of elements 11 | -- corresponding to each index. 12 | gather :: (Int# -> a) 13 | -> Flow mode dist Int 14 | -> Flow mode dist a 15 | 16 | gather !get (Flow gang distro start frag) 17 | = Flow gang distro start frag' 18 | where 19 | frag' state n 20 | = Seq.gather_bi get (frag state n) 21 | {-# INLINE frag' #-} 22 | {-# INLINE [2] gather #-} 23 | 24 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-flow/Data/Array/Repa/Flow/Seq/Operator/Project.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Flow.Seq.Operator.Project 3 | (gather_bi) 4 | where 5 | import Data.Array.Repa.Flow.Seq.Source 6 | import qualified Data.Array.Repa.Flow.Seq.Report as R 7 | import GHC.Exts 8 | 9 | 10 | -- | Takes a function to get elements and a source of indices, 11 | -- and produces a source of elements corresponding to each index. 12 | gather_bi :: (Int# -> a) -> Source mode Int -> Source mode a 13 | gather_bi !get (Source istate size report get1 get8) 14 | = Source istate size report' get1' get8' 15 | where 16 | report' state 17 | = do r <- report state 18 | return $ R.Gather r 19 | {-# NOINLINE report' #-} 20 | 21 | get1' !state push1 22 | = get1 state $ \r 23 | -> case r of 24 | Yield1 (I# ix) hint 25 | -> push1 $ Yield1 (get ix) hint 26 | 27 | Done -> push1 Done 28 | {-# INLINE get1' #-} 29 | 30 | get8' state push8 31 | = get8 state $ \r 32 | -> case r of 33 | Yield8 (I# ix0) (I# ix1) (I# ix2) (I# ix3) 34 | (I# ix4) (I# ix5) (I# ix6) (I# ix7) 35 | -> push8 $ Yield8 (get ix0) (get ix1) (get ix2) (get ix3) 36 | (get ix4) (get ix5) (get ix6) (get ix7) 37 | Pull1 38 | -> push8 $ Pull1 39 | {-# INLINE get8' #-} 40 | 41 | {-# INLINE [1] gather_bi #-} 42 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-flow/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2013, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-flow/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-flow/test/fusion/TestPar.hs: -------------------------------------------------------------------------------- 1 | module TestPar 2 | where 3 | import GHC.Exts 4 | import Data.Vector.Unboxed (Vector) 5 | import Data.Array.Repa.Flow.Par as F 6 | import Data.Array.Repa.Flow.Par.Segd as Segd 7 | import qualified Data.Vector.Unboxed as U 8 | 9 | 10 | testFlowUnflow :: U.Vector Int -> U.Vector Int 11 | testFlowUnflow vec 12 | = unflow (flow vec) 13 | 14 | 15 | -- 1234 16 | testMap :: U.Vector Int -> U.Vector Int 17 | testMap vec 18 | = unflow $ F.map (+ 1234) (flow vec) 19 | 20 | -- 2345 21 | testMapMap :: U.Vector Int -> U.Vector Int 22 | testMapMap vec 23 | = unflow $ F.map (+ 1234) $ F.map (* 2345) (flow vec) 24 | 25 | 26 | -- 3456 27 | testMapZip :: U.Vector Int -> U.Vector Int -> U.Vector Int 28 | testMapZip vec1 vec2 29 | = unflow $ F.zipWith (+) (F.map (* 3456) (flow vec1)) (flow vec2) 30 | 31 | 32 | -- 2323 33 | testPackByTag :: U.Vector (Int, Int) -> U.Vector Int 34 | testPackByTag vec1 35 | = unflow $ F.map (+ 2323) 36 | $ F.packByTag (flow vec1) 37 | 38 | 39 | -- 3434 40 | testReplicates :: U.Vector Int -> U.Vector Int -> U.Vector Int 41 | testReplicates !vLens !vElems 42 | = unflow $ F.map (+ 3434) 43 | $ F.replicatesUnboxed (Segd.fromLengths vLens) vElems 44 | 45 | 46 | -- 4567 47 | testFoldReplicate :: Segd -> U.Vector Int -> U.Vector Int 48 | testFoldReplicate segd !vElems 49 | = unflow $ F.sums segd 50 | $ F.map (+ 4545) 51 | $ F.replicatesUnboxed segd vElems 52 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-flow/test/seq/Unboxed.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash #-} 2 | -- | Data.Vector.Unboxed harness for testing. 3 | module Unboxed 4 | ( -- uflow 5 | -- szip 6 | -- example1 7 | example2) 8 | where 9 | import Data.Array.Repa.Bulk.Elt 10 | import Data.Array.Repa.Flow.Seq 11 | import Data.Array.Repa.Flow.Seq as S 12 | import qualified Data.Vector.Unboxed as U 13 | import Data.Vector.Unboxed (Vector, Unbox) 14 | import GHC.Exts 15 | 16 | szip = S.zip 17 | 18 | uflow :: (Unbox a, Elt a) => Vector a -> Flow mode a 19 | uflow vec 20 | = let get ix = U.unsafeIndex vec (I# ix) 21 | !(I# len) = U.length vec 22 | in S.flow get len 23 | {-# INLINE uflow #-} 24 | 25 | {- 26 | example1 :: Vector (Int, Int) 27 | -> IO (Partial Int, Partial Int) 28 | 29 | example1 vec 30 | = do (xs, ys) <- S.unzip $ uflow vec 31 | 32 | let xs' = S.map (+ 1234) xs 33 | let ys' = S.map (* 2345) ys 34 | 35 | !x <- S.foldl (+) 0 xs' 36 | !y <- S.foldl (+) 0 ys' 37 | return (x, y) 38 | -} 39 | 40 | example2 :: Vector (Int, Int) 41 | -> IO (Int, Int) 42 | 43 | example2 vec 44 | = do (xs, ys) <- S.unzip $ uflow vec 45 | 46 | let xs' = S.map (+ 1234) xs 47 | let ys' = S.map (+ 2345) ys 48 | 49 | (x, y) <- build2 buildSumInt xs' 50 | buildSumInt ys' 51 | 52 | return (x, y) 53 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/Data/Array/Repa/Plugin/FatName.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Plugin.FatName 3 | ( GhcName (..) 4 | , FatName (..)) 5 | where 6 | import Data.Array.Repa.Plugin.GHC.Pretty () 7 | 8 | import DDC.Base.Pretty 9 | import qualified DDC.Core.Flow.Prim as D 10 | 11 | import qualified Var as G 12 | import qualified Literal as G 13 | import qualified TyCon as G 14 | import qualified TypeRep as G 15 | 16 | 17 | data GhcName 18 | = GhcNameVar G.Var 19 | | GhcNameTyCon G.TyCon 20 | | GhcNameTyLit G.TyLit 21 | | GhcNameLiteral G.Literal 22 | | GhcNameIntU 23 | | GhcNameWordU 24 | | GhcNameFloatU 25 | | GhcNameDoubleU 26 | deriving (Eq, Ord) 27 | 28 | instance Pretty GhcName where 29 | ppr nn 30 | = case nn of 31 | GhcNameVar v -> text "VAR " <> ppr v 32 | GhcNameTyCon tc -> text "TYCON " <> ppr tc 33 | GhcNameTyLit tylit -> text "TYLIT " <> ppr tylit 34 | GhcNameLiteral lit -> text "LIT " <> ppr lit 35 | GhcNameIntU -> text "Int#" 36 | GhcNameWordU -> text "Word#" 37 | GhcNameFloatU -> text "Float#" 38 | GhcNameDoubleU -> text "Double#" 39 | 40 | 41 | data FatName 42 | = FatName 43 | { fatNameGHC :: GhcName 44 | , fatNameDDC :: D.Name } 45 | deriving (Eq, Ord) 46 | 47 | instance Pretty FatName where 48 | ppr (FatName _ name) = ppr name 49 | 50 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/Data/Array/Repa/Plugin/Pass/Dump.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Plugin.Pass.Dump 3 | (passDump) 4 | where 5 | import Data.Array.Repa.Plugin.GHC.Pretty 6 | import DDC.Base.Pretty 7 | import HscTypes 8 | import CoreMonad 9 | import System.IO.Unsafe 10 | import Control.Monad 11 | 12 | 13 | -- | Dump a module. 14 | passDump :: [CommandLineOption] -> String -> ModGuts -> CoreM ModGuts 15 | passDump options name guts 16 | = unsafePerformIO 17 | $ do 18 | when (elem "dump" options) 19 | $ writeFile ("dump." ++ name ++ ".hs") 20 | $ render RenderIndent (pprModGuts guts) 21 | 22 | return (return guts) 23 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/Data/Array/Repa/Plugin/ToDDC.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Plugin.ToDDC 3 | ( convertModGuts 4 | , detectModule) 5 | where 6 | import Data.Array.Repa.Plugin.ToDDC.Convert 7 | import Data.Array.Repa.Plugin.ToDDC.Detect 8 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2013, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/02-Opaque/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | import Data.Array.Repa.Series as R 3 | import Data.Array.Repa.Series.Series as S 4 | import Data.Array.Repa.Series.Vector as V 5 | import qualified Data.Vector.Primitive as P 6 | 7 | --------------------------------------------------------------------- 8 | -- | Set the primitives used by the lowering transform. 9 | repa_primitives :: R.Primitives 10 | repa_primitives = R.primitives 11 | 12 | 13 | --------------------------------------------------------------------- 14 | -- | The opaque worker function for map 15 | -- Noinline, because we want to make sure lower can handle arbitrary functions 16 | {-# NOINLINE f_opaque #-} 17 | f_opaque :: Int -> Int 18 | f_opaque x = x + 1 19 | 20 | 21 | --------------------------------------------------------------------- 22 | main 23 | = do v <- V.fromPrimitive $ P.enumFromN (1 :: Int) 10 24 | 25 | ------------------------------- 26 | putStrLn "singleMap" 27 | v1 <- V.fromPrimitive $ P.replicate 10 0 28 | R.runProcess v (singleMap v1) 29 | print v1 30 | 31 | ------------------------------- 32 | putStrLn "\nexternMap" 33 | v1 <- V.fromPrimitive $ P.replicate 10 0 34 | R.runProcess v (externMap v1) 35 | print v1 36 | 37 | 38 | 39 | -- Map with the opaque function defined in this module 40 | singleMap :: Vector Int 41 | -> RateNat k -> R.Series k Int -> Process 42 | singleMap v _ s 43 | = R.fill v (R.map f_opaque s) 44 | 45 | 46 | -- Map with an opaque function defined in another module 47 | externMap :: Vector Int 48 | -> RateNat k -> R.Series k Int -> Process 49 | externMap v _ s 50 | = R.fill v (R.map ([20..] !!) s) 51 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/c/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: quickhull dotproduct filtermax filtersum mapmap nestedfilter 3 | 4 | quickhull : src/Main_QuickHull.c src/QuickHull.c src/Timing.c src/Timing.h src/Vector.h 5 | gcc --std=c99 -O3 -o bin/quickhull src/Main_QuickHull.c src/QuickHull.c src/Timing.c 6 | 7 | dotproduct : src/Main_DotProduct.c src/Timing.c src/Timing.h src/Vector.h 8 | gcc --std=c99 -O3 -o bin/dotproduct src/Main_DotProduct.c src/Timing.c 9 | 10 | filtermax : src/Main_FilterMax.c src/Timing.c src/Timing.h src/Vector.h 11 | gcc --std=c99 -O3 -o bin/filtermax src/Main_FilterMax.c src/Timing.c 12 | 13 | filtersum : src/Main_FilterSum.c src/Timing.c src/Timing.h src/Vector.h 14 | gcc --std=c99 -O3 -o bin/filtersum src/Main_FilterSum.c src/Timing.c 15 | 16 | mapmap : src/Main_MapMap.c src/Timing.c src/Timing.h src/Vector.h 17 | gcc --std=c99 -O3 -o bin/mapmap src/Main_MapMap.c src/Timing.c 18 | 19 | nestedfilter: src/Main_NestedFilter.c src/Timing.c src/Timing.h src/Vector.h 20 | gcc --std=c99 -O3 -o bin/nestedfilter src/Main_NestedFilter.c src/Timing.c 21 | 22 | 23 | .PHONY : clean 24 | clean: 25 | @rm -f bin/* 26 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/c/src/Timing.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void 6 | add_timeval( struct timeval *x, const struct timeval *y ) 7 | { 8 | x->tv_sec += y->tv_sec; 9 | x->tv_usec += y->tv_usec; 10 | if( x->tv_usec > 1000000 ) { 11 | ++x->tv_sec; 12 | x->tv_usec -= 1000000; 13 | } 14 | } 15 | 16 | 17 | void 18 | sub_timeval( struct timeval *x, const struct timeval *y ) 19 | { 20 | x->tv_sec -= y->tv_sec; 21 | if( x->tv_usec < y->tv_usec ) { 22 | --x->tv_sec; 23 | x->tv_usec = x->tv_usec + (1000000 - y->tv_usec); 24 | } else 25 | x->tv_usec -= y->tv_usec; 26 | } 27 | 28 | 29 | void 30 | print_timeval( const struct timeval *t ) 31 | { 32 | printf( "%ld", (long int) t->tv_sec * 1000 + (long int) t->tv_usec / 1000 ); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/c/src/Timing.h: -------------------------------------------------------------------------------- 1 | #ifndef _Timing_h_ 2 | #define _Timing_h_ 3 | 4 | #include 5 | #include 6 | 7 | void 8 | add_timeval( struct timeval *x, const struct timeval *y ); 9 | 10 | void 11 | sub_timeval( struct timeval *x, const struct timeval *y ); 12 | 13 | void 14 | print_timeval( const struct timeval *t ); 15 | 16 | 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/c/src/Vector.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _Vector_ 3 | #define _Vector_ 4 | 5 | #include 6 | 7 | typedef struct { 8 | int capacity; 9 | int length; 10 | long* x; 11 | long* y; 12 | } Vector; 13 | 14 | 15 | static inline void vector_append(Vector* vector, long x, long y) 16 | { 17 | assert(vector->length + 1 <= vector->capacity); 18 | 19 | int i = vector->length; 20 | vector->x[i] = x; 21 | vector->y[i] = y; 22 | vector->length++; 23 | } 24 | 25 | 26 | static inline Vector* vector_new(int capacity) 27 | { 28 | Vector* vector = malloc(sizeof(Vector)); 29 | vector->capacity = capacity; 30 | vector->length = 0; 31 | vector->x = malloc(sizeof(long) * capacity); 32 | vector->y = malloc(sizeof(long) * capacity); 33 | return vector; 34 | } 35 | 36 | static inline void vector_rewind(Vector* vector) 37 | { 38 | vector->length = 0; 39 | } 40 | 41 | 42 | static inline void vector_delete(Vector* vector) 43 | { 44 | free(vector->x); 45 | free(vector->y); 46 | free(vector); 47 | } 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/repa/DotProduct/Vector.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, RankNTypes #-} 2 | module Main where 3 | import qualified Data.Vector.Unboxed as V 4 | import Data.Vector.Unboxed (Vector) 5 | import System.Environment 6 | import Data.Array.Repa.IO.Timing 7 | 8 | main 9 | = do args <- getArgs 10 | let sz = case args of 11 | [szStr] -> (Prelude.read szStr :: Int) 12 | _ -> error "Usage: quickhull " 13 | let x1 = V.enumFromN 0 sz 14 | let y1 = V.enumFromN 0 sz 15 | let x2 = V.enumFromN 0 sz 16 | let y2 = V.enumFromN 0 sz 17 | x1 `seq` y1 `seq` x2 `seq` y2 `seq` return () 18 | (d,t) <- time $ let d = dotp x1 y1 x2 y2 19 | in d `seq` return d 20 | putStr $ prettyTime t 21 | print (V.head d, V.length d) 22 | 23 | dotp :: V.Vector Int -> V.Vector Int 24 | -> V.Vector Int -> V.Vector Int 25 | -> V.Vector Int 26 | 27 | dotp x1 y1 x2 y2 28 | = (V.zipWith (+) (V.zipWith (*) x1 x2) (V.zipWith (*) y1 y2)) 29 | 30 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/repa/FilterSum/Vector.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, RankNTypes #-} 2 | module Main (main) where 3 | import qualified Data.Vector.Unboxed as U 4 | import Data.Array.Repa.IO.Timing 5 | 6 | import GHC.Exts 7 | import System.Environment 8 | 9 | 10 | --------------------------------------------------------------------- 11 | main 12 | = do args <- getArgs 13 | let sz = case args of 14 | [szStr] -> (read szStr :: Int) 15 | _ -> error "Usage: simplebench " 16 | let v1 = U.enumFromN (0 :: Int) sz 17 | v1 `seq` return () 18 | ((v,i,a),t) <- time $ let (v,i,a) = lower_filterSum v1 19 | in v `seq` i `seq` a `seq` return (v,i,a) 20 | putStr $ prettyTime t 21 | print (U.length v, i, a) 22 | 23 | 24 | lower_filterSum :: U.Vector Int -> (U.Vector Int, Int, Int) 25 | lower_filterSum xs 26 | = let xs' = U.filter (\x -> x > 50) xs 27 | sum1 = U.foldl (+) 0 xs 28 | sum2 = U.foldl (+) 0 xs' 29 | in (xs', sum1, sum2) 30 | {-# NOINLINE lower_filterSum #-} 31 | 32 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/repa/MapMap/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, RankNTypes #-} 2 | module Main (main, repa_primitives) where 3 | import Data.Array.Repa.Series as R 4 | import Data.Array.Repa.Series.Series as S 5 | import Data.Array.Repa.Series.Vector as V 6 | import qualified Data.Vector.Primitive as P 7 | import Data.Array.Repa.IO.Timing 8 | 9 | import GHC.Exts 10 | import System.Environment 11 | 12 | --------------------------------------------------------------------- 13 | -- | Set the primitives used by the lowering transform. 14 | repa_primitives :: R.Primitives 15 | repa_primitives = R.primitives 16 | 17 | --------------------------------------------------------------------- 18 | main 19 | = do args <- getArgs 20 | let sz = case args of 21 | [szStr] -> (Prelude.read szStr :: Int) 22 | _ -> error "Usage: mapmap " 23 | 24 | i1 <- V.fromPrimitive $ P.enumFromN 0 sz 25 | o1 <- (V.new sz :: IO (V.Vector Float)) 26 | o2 <- (V.new sz :: IO (V.Vector Float)) 27 | i1 `seq` o1 `seq` o2 `seq` return () 28 | 29 | ((), t) <- time $ runProcess i1 (mapmap o1 o2) 30 | o1' <- V.toPrimitive o1 31 | o2' <- V.toPrimitive o2 32 | 33 | putStr (prettyTime t) 34 | print (P.head o1', P.length o1', P.head o2', P.length o2') 35 | 36 | 37 | mapmap :: forall k 38 | . R.Vector Float -> R.Vector Float 39 | -> RateNat k 40 | -> R.Series k Float 41 | -> Process 42 | 43 | mapmap o1 o2 _ xs 44 | = let xs' = R.map (\x -> x * 2) xs 45 | ys = R.map (\x -> x + 50) xs' 46 | zs = R.map (\x -> x - 50) xs' 47 | in 48 | R.fill o1 ys 49 | % R.fill o2 zs 50 | {-# NOINLINE mapmap #-} 51 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/repa/MapMap/Vector.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, RankNTypes, BangPatterns #-} 2 | module Main (main) where 3 | import qualified Data.Vector.Unboxed as U 4 | import Data.Array.Repa.IO.Timing 5 | 6 | import GHC.Exts 7 | import System.Environment 8 | 9 | --------------------------------------------------------------------- 10 | main 11 | = do args <- getArgs 12 | let sz = case args of 13 | [szStr] -> (Prelude.read szStr :: Int) 14 | _ -> error "Usage: simplebench " 15 | let !v1 = U.enumFromN (0 :: Int) sz 16 | v1 `seq` return () 17 | ((ys,zs),t) <- time $ let (ys,zs) = lower_mapmap v1 18 | in ys `seq` zs `seq` return (ys,zs) 19 | putStr (prettyTime t) 20 | print (U.head ys, U.length ys, U.head zs, U.length zs) 21 | 22 | 23 | lower_mapmap :: U.Vector Int -> (U.Vector Int, U.Vector Int) 24 | lower_mapmap !xs 25 | = let !xs' = U.map (\x -> x * 2) xs 26 | !ys = U.map (\x -> x + 50) xs' 27 | !zs = U.map (\x -> x - 50) xs' 28 | in (ys, zs) 29 | {-# NOINLINE lower_mapmap #-} 30 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-plugin/test/90-Benchmarks/repa/NestedFilter/Vector.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, RankNTypes #-} 2 | module Main (main) where 3 | import qualified Data.Vector.Unboxed as U 4 | import Data.Array.Repa.IO.Timing 5 | 6 | import GHC.Exts 7 | import System.Environment 8 | 9 | 10 | --------------------------------------------------------------------- 11 | main 12 | = do args <- getArgs 13 | let sz = case args of 14 | [szStr] -> (read szStr :: Int) 15 | _ -> error "Usage: nestedfilter " 16 | let v1 = U.enumFromN (0 :: Int) sz 17 | v1 `seq` return () 18 | ((v,u),t) <- time $ let (v,u) = nested v1 19 | in v `seq` u `seq` return (v,u) 20 | putStr $ prettyTime t 21 | print (U.length v, U.length u) 22 | 23 | 24 | nested :: U.Vector Int -> (U.Vector Int, U.Vector Int) 25 | nested xs 26 | = let ys = U.filter (\x -> x > 50) xs 27 | zs = U.filter (\x -> x < 100) ys 28 | in (ys, zs) 29 | {-# NOINLINE nested #-} 30 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/Data/Array/Repa/Series/Prim/Utils.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Series.Prim.Utils 3 | ( World, W 4 | , unwrapIO' 5 | , unwrapIO_ 6 | , wrapIO1 7 | , wrapIO_) 8 | where 9 | import GHC.Types 10 | import GHC.Exts 11 | 12 | type World 13 | = State# RealWorld 14 | 15 | type W = World 16 | 17 | 18 | unwrapIO' :: IO a -> State# RealWorld -> (# State# RealWorld, a #) 19 | unwrapIO' (IO f) = f 20 | {-# INLINE [1] unwrapIO' #-} 21 | 22 | 23 | unwrapIO_ :: IO a -> State# RealWorld -> State# RealWorld 24 | unwrapIO_ (IO f) world 25 | = case f world of 26 | (# world', _ #) -> world' 27 | {-# INLINE [1] unwrapIO_ #-} 28 | 29 | 30 | wrapIO1 :: (World -> (# World, a #)) -> IO a 31 | wrapIO1 = IO 32 | {-# INLINE [1] wrapIO1 #-} 33 | 34 | 35 | wrapIO_ :: (World -> World) -> IO () 36 | wrapIO_ f 37 | = IO (\w -> let !w' = f w in (# w', () #)) 38 | {-# INLINE [1] wrapIO_ #-} 39 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/Data/Array/Repa/Series/Rate.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Series.Rate 3 | ( RateNat (..) 4 | , rateOfRateNat 5 | , rateNatOfInt 6 | 7 | , Down2 (..), Down4 (..), Down8(..) 8 | , Tail2 (..), Tail4 (..), Tail8(..)) 9 | where 10 | import GHC.Exts 11 | 12 | -- | Holds the value-level version of a type-level rate variable. 13 | -- 14 | -- All the functions in the repa-series API ensures that the value-level and 15 | -- type-level rates match up. 16 | -- 17 | -- Should be treated abstactly by user code. 18 | -- 19 | data RateNat k 20 | = RateNat Word# 21 | 22 | 23 | -- | Take the rate of a `RateNat`. 24 | rateOfRateNat :: RateNat k -> Word# 25 | rateOfRateNat (RateNat len) 26 | = len 27 | {-# INLINE [1] rateOfRateNat #-} 28 | 29 | 30 | -- | Wrap an Int into a `RateNat`. 31 | rateNatOfInt :: Int -> RateNat k 32 | rateNatOfInt (I# i) 33 | = RateNat (int2Word# i) 34 | {-# INLINE [1] rateNatOfInt #-} 35 | 36 | 37 | -- Represents the quotient of a rate divided by the multiplier. 38 | -- Should be treated abstractly by client code. 39 | data Down2 k 40 | data Down4 k 41 | data Down8 k 42 | 43 | 44 | -- | Represents the remainder of a rate divided by the multiplier. 45 | -- 46 | -- Contains the starting offset in the original vector, 47 | -- and number of elements. 48 | -- 49 | -- Should be treated abstractly by client code. 50 | -- 51 | data Tail2 k 52 | data Tail4 k 53 | data Tail8 k 54 | 55 | 56 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/Data/Array/Repa/Series/Ref.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Series.Ref 3 | ( Ref (..) 4 | , new 5 | , read 6 | , write) 7 | where 8 | import Data.Vector.Primitive.Mutable (IOVector, Prim) 9 | import qualified Data.Vector.Primitive.Mutable as PM 10 | import Prelude hiding (read) 11 | 12 | 13 | -- | Mutable references. 14 | data Ref a 15 | = Ref !(IOVector a) 16 | 17 | 18 | -- | Create a new unboxed reference. 19 | new :: Prim a => a -> IO (Ref a) 20 | new x 21 | = do vec <- PM.unsafeNew 1 22 | PM.unsafeWrite vec 0 x 23 | return (Ref vec) 24 | {-# INLINE [1] new #-} 25 | 26 | 27 | -- | Read from an unboxed reference. 28 | read :: Prim a => Ref a -> IO a 29 | read (Ref vec) 30 | = PM.unsafeRead vec 0 31 | {-# INLINE [1] read #-} 32 | 33 | 34 | -- | Write to an unboxed reference. 35 | write :: Prim a => Ref a -> a -> IO () 36 | write (Ref vec) x 37 | = do PM.unsafeWrite vec 0 x 38 | {-# INLINE [1] write #-} 39 | 40 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/Data/Array/Repa/Series/Sel.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Series.Sel 3 | ( Sel1 (..) 4 | , mkSel1) 5 | where 6 | import Data.Array.Repa.Series.Process 7 | import Data.Array.Repa.Series.Vector as V 8 | import Data.Array.Repa.Series.Series as S 9 | import Data.Vector.Primitive as P 10 | import System.IO.Unsafe 11 | import Data.Word 12 | import GHC.Exts 13 | 14 | 15 | -- | Selectors. 16 | data Sel1 k1 k2 17 | = Sel1 18 | { sel1Length :: Word# 19 | , sel1Flags :: !(P.Vector Bool) } 20 | 21 | 22 | -- | Create a new selector from a series of flags. 23 | mkSel1 :: Series k1 Bool 24 | -> (forall k2. Sel1 k1 k2 -> Process) 25 | -> Process 26 | 27 | mkSel1 (Series _ len _ vec) worker 28 | = worker $ Sel1 29 | { sel1Length = len 30 | , sel1Flags = vec } 31 | {-# NOINLINE mkSel1 #-} 32 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2013, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/icebox/Series.hs: -------------------------------------------------------------------------------- 1 | 2 | 3 | -- | Combine all elements of a series with an associative operator. 4 | fold :: forall k a b. Prim b 5 | => (a -> b -> a) -> a -> Series k b -> Process a 6 | 7 | fold f z !source 8 | = go (int2Word# 0#) z 9 | where go !ix !acc 10 | | geWord# ix (S.length source) 11 | = acc 12 | 13 | | otherwise 14 | = let x = S.index source ix 15 | in go (plusWord# ix (int2Word# 1#)) (f acc x) 16 | {-# INLINE [0] fold #-} 17 | 18 | 19 | -- | Combine all elements of a series with an associative operator. 20 | -- The worker function is given the current index into the series. 21 | foldIndex :: forall k a b. Prim b 22 | => (Word -> a -> b -> a) -> a -> Series k b -> a 23 | 24 | foldIndex f z !source 25 | = go (int2Word# 0#) z 26 | where 27 | len = S.length source 28 | go !ix !acc 29 | | geWord# ix len 30 | = acc 31 | 32 | | otherwise 33 | = let x = S.index source ix 34 | in go (plusWord# ix (int2Word# 1#)) (f (W# ix) acc x) 35 | {-# INLINE [0] foldIndex #-} 36 | 37 | 38 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-series/repa-series.cabal: -------------------------------------------------------------------------------- 1 | Name: repa-series 2 | Version: 1.0.1.0 3 | License: BSD3 4 | License-File: LICENSE 5 | Cabal-Version: >= 1.10 6 | Build-Type: Simple 7 | Author: The DPH Team 8 | Maintainer: Ben Lippmeier 9 | Category: Data Structures 10 | Synopsis: Series Expressions API 11 | Description: 12 | Series expression API for writing programs subjected to the 13 | Data Flow Fusion performed by the repa-plugin. 14 | 15 | Library 16 | Exposed-Modules: 17 | Data.Array.Repa.Series 18 | Data.Array.Repa.Series.Series 19 | Data.Array.Repa.Series.Vector 20 | Data.Array.Repa.Series.Sel 21 | Data.Array.Repa.Series.Fallback 22 | Data.Array.Repa.Series.Ref 23 | Data.Array.Repa.Series.Rate 24 | Data.Array.Repa.Series.Process 25 | Data.Array.Repa.Series.Prim 26 | Data.Array.Repa.Series.Prim.Utils 27 | Data.Array.Repa.Series.Prim.Loop 28 | Data.Array.Repa.Series.Prim.Int 29 | Data.Array.Repa.Series.Prim.Word 30 | Data.Array.Repa.Series.Prim.Float 31 | Data.Array.Repa.Series.Prim.Double 32 | 33 | Build-Depends: 34 | base >= 4.6 && < 4.8, 35 | ghc >= 7.5 && < 7.9, 36 | vector >= 0.9 && < 0.11, 37 | primitive >= 0.4 && < 0.6, 38 | ghc-prim >= 0.3 39 | 40 | Default-Language: 41 | Haskell2010 42 | 43 | Default-Extensions: 44 | TypeSynonymInstances 45 | BangPatterns 46 | RankNTypes 47 | MagicHash 48 | UnboxedTuples 49 | 50 | GHC-Options: 51 | -fllvm 52 | -mavx2 53 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/Data/Array/Repa/Chain/Indexed.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Chain.Indexed 3 | ( indexed 4 | , indexedD) 5 | where 6 | import Data.Array.Repa.Chain.Base 7 | import GHC.Exts 8 | import Prelude 9 | 10 | 11 | -- | Tag each element of an stream with its index in that stream. 12 | -- 13 | -- @ 14 | -- indexed [42,93,13] 15 | -- = [(0,42), (1,93), (2,13)] 16 | -- @ 17 | indexed :: Chain a -> Chain (Int,a) 18 | indexed (Chain n start next) 19 | = Chain n start next' 20 | where next' ix s 21 | = case next ix s of 22 | Yield s' x -> Yield s' (I# ix, x) 23 | Update s' -> Update s' 24 | {-# INLINE [1] indexed #-} 25 | 26 | 27 | -- | Tag each element of a distributed stream with its index in that stream. 28 | -- 29 | indexedD :: DistChain a -> DistChain (Int, a) 30 | indexedD (DistChain distro frag) 31 | = DistChain distro frag' 32 | where frag' i = indexed (frag i) 33 | {-# INLINE [1] indexedD #-} 34 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/Data/Array/Repa/Chain/Indexs.hs: -------------------------------------------------------------------------------- 1 | module Data.Array.Repa.Chain.Indexs 2 | ( indexs 3 | , indexsD) 4 | where 5 | import Data.Array.Repa.Chain.Base 6 | import Data.Array.Repa 7 | 8 | indexs :: (Source r e) 9 | => Chain Int 10 | -> Array r DIM1 e 11 | -> Chain e 12 | indexs (Chain sz state next) vec 13 | = Chain sz state next' 14 | where 15 | next' ix s 16 | = case next ix s of 17 | Update s' -> Update s' 18 | Yield s' i -> Yield s' (vec `unsafeLinearIndex` i) 19 | {-# INLINE next' #-} 20 | {-# INLINE indexs #-} 21 | 22 | 23 | indexsD :: (Source r e) 24 | => DistChain Int -> Array r DIM1 e -> DistChain e 25 | indexsD (DistChain distro frag) vec 26 | = DistChain distro frag' 27 | where frag' i = indexs (frag i) vec 28 | {-# INLINE [1] indexsD #-} 29 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/Data/Array/Repa/Stream/Eval.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Stream.Eval 3 | (evalM, evalMD) 4 | where 5 | import Data.Array.Repa.Stream.Base 6 | import GHC.Exts 7 | 8 | 9 | -- | Evaluate a stream, 10 | -- calling the given function with the index and value of each element. 11 | evalM :: Monad m 12 | => (Int# -> a -> m ()) 13 | -> Stream a 14 | -> m Int 15 | 16 | evalM write (Stream _size s0 next) 17 | = go 0# s0 18 | where go ix !s 19 | = case next s of 20 | Yield !s' x 21 | -> do write ix x 22 | go (ix +# 1#) s' 23 | 24 | Update !s' 25 | -> go ix s' 26 | 27 | Done 28 | -> return (I# ix) 29 | {-# INLINE [1] evalM #-} 30 | 31 | 32 | -- | Evaluate a distributed stream, 33 | -- calling the given function with the fragment index, 34 | -- and element index within each fragment. 35 | evalMD :: Monad m 36 | => (Int# -> Int# -> a -> m ()) 37 | -> DistStream a 38 | -> m () 39 | 40 | evalMD write (DistStream _size frags frag) 41 | = go 0# 42 | where go i 43 | | i >=# frags 44 | = return () 45 | 46 | | otherwise 47 | = do _ <- evalM (write i) (frag i) 48 | go (i +# 1#) 49 | {-# INLINE [1] evalMD #-} 50 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/Data/Array/Repa/Stream/Indexs.hs: -------------------------------------------------------------------------------- 1 | module Data.Array.Repa.Stream.Indexs 2 | ( indexs 3 | , indexsD) 4 | where 5 | import Data.Array.Repa.Stream.Base 6 | import Data.Array.Repa 7 | 8 | indexs :: (Source r e) 9 | => Stream Int 10 | -> Array r DIM1 e 11 | -> Stream e 12 | indexs (Stream sz state next) vec 13 | = Stream sz state next' 14 | where 15 | next' s 16 | = case next s of 17 | Done -> Done 18 | Update s' -> Update s' 19 | Yield s' i -> Yield s' (vec `unsafeLinearIndex` i) 20 | {-# INLINE next' #-} 21 | {-# INLINE indexs #-} 22 | 23 | indexsD :: (Source r e) 24 | => DistStream Int -> Array r DIM1 e -> DistStream e 25 | indexsD (DistStream sz frags frag) vec 26 | = DistStream sz frags frag' 27 | where frag' c' = indexs (frag c') vec 28 | {-# INLINE [1] indexsD #-} 29 | 30 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/Data/Array/Repa/Stream/Pack.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Stream.Pack 3 | (pack, packD) 4 | where 5 | import Data.Array.Repa.Stream.Base 6 | 7 | 8 | -- | Given a stream of flags and values, 9 | -- return a stream of values that had their correspondig flag set to `True`. 10 | pack :: Stream (Bool, a) -> Stream a 11 | pack (Stream size start next) 12 | = Stream size' start next' 13 | where 14 | size' 15 | = case size of 16 | Unknown -> Unknown 17 | Max len -> Max len 18 | Exact len -> Max len 19 | 20 | next' s 21 | = case next s of 22 | Yield s' (flag, x) 23 | | flag -> Yield s' x 24 | | otherwise -> Update s' 25 | 26 | Update s' -> Update s' 27 | Done -> Done 28 | {-# INLINE [1] pack #-} 29 | 30 | 31 | -- | Pack for distributed streams. 32 | packD :: DistStream (Bool, a) -> DistStream a 33 | packD (DistStream size frags frag) 34 | = DistStream size' frags frag' 35 | where 36 | size' 37 | = case size of 38 | Unknown -> Unknown 39 | Max len -> Max len 40 | Exact len -> Max len 41 | 42 | frag' i 43 | = pack (frag i) 44 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/Data/Array/Repa/Stream/Scan.hs: -------------------------------------------------------------------------------- 1 | 2 | 3 | module Data.Array.Repa.Stream.Scan 4 | (mapAccum) 5 | where 6 | import Data.Array.Repa.Stream.Base 7 | 8 | 9 | mapAccum :: (acc -> a -> (acc,b)) 10 | -> acc -> Stream a -> Stream b 11 | 12 | mapAccum f acc0 (Stream size state0 next) 13 | = Stream size (acc0, state0) next' 14 | where next' (acc, s) 15 | = case next s of 16 | Yield s' x -> let (acc', y) = f acc x 17 | in Yield (acc', s') y 18 | 19 | Update s' -> Update (acc, s') 20 | Done -> Done 21 | 22 | {-# INLINE mapAccum #-} 23 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2013, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/scratch/Solver.hs: -------------------------------------------------------------------------------- 1 | 2 | module Solver where 3 | 4 | import qualified Stream as S 5 | import qualified Data.Vector.Unboxed as U 6 | import Control.Concurrent.MVar 7 | 8 | 9 | thing :: U.Vector Int -> U.Vector Int -> IO (U.Vector Int) 10 | thing vecLens vecElems 11 | = do vLeft <- newEmptyMVar 12 | vRight <- newEmptyMVar 13 | 14 | S.unstreamUnboxed 15 | $ S.map (+ 12345) 16 | $ S.foldSegsBubble 17 | (+) 18 | 0 19 | (S.streamUnboxed vecLens) 20 | (S.streamUnboxed vecElems) 21 | (Just vLeft) 22 | (Just vRight) 23 | 24 | {- $ S.foldSegsTrade 25 | (+) 26 | 0 27 | (S.streamUnboxed vecLens) 28 | (S.streamUnboxed vecElems) 29 | (Just vLeft) 30 | (Just vRight) 31 | -} 32 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-stream/test/fusion/Replicate.hs: -------------------------------------------------------------------------------- 1 | {- Fusion tests for Replicate. 2 | ghc -Wall -O2 -fno-liberate-case -c Replicate.hs \ 3 | -ddump-prep -dsuppress-all -dppr-case-as-let -dppr-cols200 > Replicate.prep 4 | -} 5 | {-# LANGUAGE MagicHash, BangPatterns #-} 6 | module Replicate where 7 | import Data.Array.Repa.Chain as C 8 | import Data.Vector.Unboxed (Vector) 9 | import GHC.Exts 10 | 11 | -- replicate ------------------------------------------------------------------ 12 | fuse_replicate :: Int -> Vector Int 13 | fuse_replicate (I# size) 14 | = vunchain $ C.replicate size 1234 15 | 16 | 17 | fuse_replicateD :: Distro -> Vector Int 18 | fuse_replicateD distro 19 | = vunchainD $ C.replicateD distro 1234 20 | 21 | 22 | -- replicateEach -------------------------------------------------------------- 23 | fuse_replicateEach 24 | :: Int -> Vector (Int, Int) -> Vector Int 25 | fuse_replicateEach (I# size) !vec 26 | = vunchain $ C.replicateEach size $ vchain vec 27 | 28 | 29 | fuse_replicateEachD 30 | :: Distro -> Distro -> Vector (Int, Int) -> Vector Int 31 | fuse_replicateEachD dResult dSrc !vec 32 | = vunchainD $ C.replicateEachD dResult $ vchainD dSrc vec 33 | 34 | 35 | fuse_replicateReplicateEach 36 | :: Int -> Int -> Vector Int 37 | fuse_replicateReplicateEach (I# tot) (I# n) 38 | = vunchain 39 | $ C.replicateEach tot 40 | $ C.replicate n (10, 1234) 41 | 42 | 43 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/Data/Vector/Repa.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Vector.Repa 3 | ( -- * Representations 4 | N 5 | , Vector 6 | 7 | -- * Conversion 8 | , chain 9 | , unchainP 10 | , unchainS 11 | 12 | -- * Projections 13 | , vlength 14 | 15 | -- * Constructors 16 | , vreplicate 17 | , vreplicates 18 | 19 | -- * Maps and Zips 20 | , Map(..) 21 | , Zip(..) 22 | , vzip3 23 | , vzip4 24 | , vzip5 25 | , vzip6 26 | , vzipWith 27 | , vzipWith3 28 | , vzipWith4 29 | , vzipWith5 30 | , vzipWith6) 31 | where 32 | import Data.Vector.Repa.Operators.Zip 33 | import Data.Vector.Repa.Operators.Replicate 34 | import Data.Vector.Repa.Repr.Chain 35 | import Data.Vector.Repa.Base 36 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/Data/Vector/Repa/Base.hs: -------------------------------------------------------------------------------- 1 | module Data.Vector.Repa.Base 2 | ( Vector 3 | , Map(..) 4 | , Zip(..) 5 | , vlength) 6 | where 7 | import Data.Array.Repa as R 8 | import Prelude hiding (length) 9 | import qualified Data.Vector.Unboxed as U 10 | import Prelude hiding (zip, map, length, replicate) 11 | 12 | type Vector r e 13 | = Array r DIM1 e 14 | 15 | 16 | -- Map ------------------------------------------------------------------------ 17 | class Map r a where 18 | type TM r 19 | -- | Vector map that will preserve the chain representation of source vector. 20 | vmap :: (a -> b) -> Vector r a -> Vector (TM r) b 21 | 22 | 23 | instance U.Unbox e => Map U e where 24 | type TM U = D 25 | 26 | vmap f arr 27 | = case delay arr of 28 | ADelayed sh g -> ADelayed sh (f . g) 29 | {-# INLINE [4] vmap #-} 30 | 31 | 32 | instance Map D e where 33 | type TM D = D 34 | vmap = R.map 35 | {-# INLINE [4] vmap #-} 36 | 37 | 38 | class Zip r1 r2 a b where 39 | type TZ r1 r2 40 | -- | Vector zip that uses the least general possible representation for the 41 | -- result. 42 | -- 43 | -- For example, zipping two Delayed (@D@) arrays produces a delayed array, 44 | -- but zipping a Delayed (@D@) and a Chained (@N@) array must produce 45 | -- a chained array. 46 | vzip :: Vector r1 a 47 | -> Vector r2 b 48 | -> Vector (TZ r1 r2) (a, b) 49 | 50 | 51 | 52 | ------------------------------------------------------------------------------- 53 | -- | Get the length of a vector. 54 | vlength :: Source r e => Vector r e -> Int 55 | vlength !v 56 | = case extent v of 57 | Z :. len -> len 58 | {-# INLINE [4] vlength #-} 59 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/Data/Vector/Repa/Repr/Sliced.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Vector.Repa.Repr.Sliced 3 | ( S 4 | , Array (..) 5 | , vslice) 6 | where 7 | import Data.Vector.Repa.Base 8 | import Data.Array.Repa as R 9 | import Prelude hiding (length) 10 | import Prelude as P 11 | 12 | 13 | data S r 14 | 15 | instance Source r e => Source (S r) e where 16 | data Array (S r) sh e 17 | = ASliced 18 | sh -- starting position 19 | sh -- extent of slice 20 | (Array r sh e) -- source array 21 | 22 | extent (ASliced _ shape _) 23 | = shape 24 | {-# INLINE extent #-} 25 | 26 | index (ASliced start _ arr) ix 27 | = start `deepSeq` unsafeIndex arr (addDim start ix) 28 | {-# INLINE index #-} 29 | 30 | linearIndex (ASliced start shape arr) ix 31 | = start `deepSeq` shape `deepSeq` 32 | unsafeIndex arr 33 | (addDim start (fromIndex shape ix)) 34 | {-# INLINE linearIndex #-} 35 | 36 | deepSeqArray (ASliced start shape _) x 37 | = start `deepSeq` shape `deepSeq` x 38 | {-# INLINE deepSeqArray #-} 39 | 40 | 41 | -- Map ------------------------------------------------------------------------ 42 | instance Map r e => Map (S r) e where 43 | type TM (S r) = S (TM r) 44 | 45 | vmap f (ASliced start shape arr) 46 | = ASliced start shape (vmap f arr) 47 | {-# INLINE [4] vmap #-} 48 | 49 | 50 | -- | Slice a chunk from a vector. 51 | vslice :: Source r e 52 | => Int -- ^ Starting index. 53 | -> Int -- ^ Length of slice. 54 | -> Vector r e 55 | -> Vector (S r) e 56 | 57 | vslice start len vec 58 | = ASliced (Z :. start) (Z :. len) vec 59 | {-# INLINE [4] vslice #-} 60 | 61 | 62 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/chains/Data/Array/Repa/Vector/Base.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Base 3 | ( Vector 4 | , balanced 5 | , vlength 6 | , vindex) 7 | where 8 | import Data.Array.Repa as R 9 | import qualified Data.Array.Repa.Eval.Gang as G 10 | import qualified Data.Array.Repa.Distro as D 11 | import GHC.Exts 12 | 13 | -- | Vectors are one-dimensional arrays. 14 | type Vector r e 15 | = Array r DIM1 e 16 | 17 | 18 | -- | Get the length of a vector. 19 | vlength :: Source r e => Vector r e -> Int 20 | vlength !v 21 | = case extent v of 22 | Z :. len -> len 23 | {-# INLINE [4] vlength #-} 24 | 25 | 26 | -- | Retrieve a single element from a vector. 27 | vindex :: Source r e => Vector r e -> Int -> e 28 | vindex vec ix 29 | = R.unsafeLinearIndex vec ix 30 | 31 | 32 | -- | Construct a balanced `Distro` for a vector of this length, 33 | -- dividing it evenly among the threads of the global Repa gang. 34 | balanced :: Int -> D.Distro 35 | balanced (I# len) 36 | = let !(I# frags) = G.gangSize G.theGang 37 | in D.balanced len frags 38 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/chains/Data/Array/Repa/Vector/Operators/Combine.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Combine 3 | ( vcombine2 4 | , vcombineSegs2) 5 | where 6 | import Data.Array.Repa.Repr.Stream 7 | import Data.Array.Repa.Vector.Base 8 | import Data.Array.Repa 9 | import qualified Data.Array.Repa.Stream as S 10 | import qualified Data.Vector.Unboxed as U 11 | import Prelude as P 12 | 13 | 14 | -- | TODO: make this parallel. 15 | vcombine2 16 | :: U.Unbox a 17 | => Vector U Bool 18 | -> Vector U a -> Vector U a 19 | -> Vector U a 20 | 21 | vcombine2 (AUnboxed sh tags) (AUnboxed _ vec1) (AUnboxed _ vec2) 22 | = AUnboxed sh 23 | $ S.unstreamUnboxed 24 | $ S.combine2 25 | (S.streamUnboxed tags) 26 | (S.streamUnboxed vec1) 27 | (S.streamUnboxed vec2) 28 | 29 | 30 | vcombineSegs2 31 | :: U.Unbox a 32 | => Vector U Bool 33 | -> Vector U Int -> Vector U a 34 | -> Vector U Int -> Vector U a 35 | -> Vector U a 36 | 37 | vcombineSegs2 38 | (AUnboxed sh flags) 39 | (AUnboxed _ lens1) (AUnboxed _ elems1) 40 | (AUnboxed _ lens2) (AUnboxed _ elems2) 41 | = AUnboxed sh 42 | $ S.unstreamUnboxed 43 | $ S.combineSegs2 44 | (S.streamUnboxed flags) 45 | (S.streamUnboxed lens1) (S.streamUnboxed elems1) 46 | (S.streamUnboxed lens2) (S.streamUnboxed elems2) 47 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/chains/Data/Array/Repa/Vector/Operators/Flatten.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Flatten 3 | (Flatten2 (..)) 4 | where 5 | import Data.Array.Repa.Repr.Stream 6 | import Data.Array.Repa.Repr.Chain 7 | import Data.Array.Repa.Vector.Base 8 | import Data.Array.Repa.Stream.Flatten as S 9 | import Data.Array.Repa as R 10 | import qualified Data.Vector.Unboxed as U 11 | 12 | 13 | -- | Flatten a vector of tuples into a vector of their elements. 14 | -- 15 | -- TODO: use less general result representations for unboxeded, delayed, chained sources. 16 | class Flatten2 r a where 17 | type Flatten2R r 18 | vflatten2 :: Vector r (a, a) -> Vector (Flatten2R r) a 19 | 20 | 21 | instance U.Unbox a => Flatten2 U a where 22 | type Flatten2R U = S 23 | vflatten2 vec 24 | = vflatten2 (vstream vec) 25 | {-# INLINE [1] vflatten2 #-} 26 | 27 | 28 | instance U.Unbox a => Flatten2 D a where 29 | type Flatten2R D = S 30 | vflatten2 vec 31 | = vflatten2 (vstream vec) 32 | {-# INLINE [1] vflatten2 #-} 33 | 34 | 35 | instance U.Unbox a => Flatten2 N a where 36 | type Flatten2R N = S 37 | vflatten2 vec 38 | = vflatten2 (vstream vec) 39 | {-# INLINE [1] vflatten2 #-} 40 | 41 | 42 | instance U.Unbox a => Flatten2 S a where 43 | type Flatten2R S = S 44 | vflatten2 (AStream _ dstream _) 45 | = vcacheStream 46 | $ S.flatten2D dstream 47 | {-# INLINE [1] vflatten2 #-} 48 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/chains/Data/Array/Repa/Vector/Operators/Indexed.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Indexed 3 | (Indexed (..)) 4 | where 5 | import Data.Array.Repa.Repr.Chain 6 | import Data.Array.Repa.Vector.Base 7 | import Data.Array.Repa.Chain.Indexed as C 8 | import Data.Array.Repa as R 9 | import qualified Data.Vector.Unboxed as U 10 | 11 | -- | Tag each element of a vector with its index in that vector. 12 | -- 13 | -- `vindexed` doesn't have a stream-consuming version because we won't 14 | -- know how many elements will be produced by each thread. 15 | -- 16 | -- @ 17 | -- vindexed [42,93,13] 18 | -- = [(0,42), (1,93), (2,13)] 19 | -- @ 20 | -- 21 | class Indexed r a where 22 | type IndexedR r 23 | vindexed :: Vector r a -> Vector (IndexedR r) (Int, a) 24 | 25 | 26 | instance U.Unbox a => Indexed U a where 27 | type IndexedR U = D 28 | vindexed vec 29 | = R.fromFunction (R.extent vec) 30 | $ \ ix@(Z :. n) -> (n, R.unsafeIndex vec ix) 31 | 32 | 33 | instance Indexed D a where 34 | type IndexedR D = D 35 | vindexed vec 36 | = R.fromFunction (R.extent vec) 37 | $ \ ix@(Z :. n) -> (n, R.unsafeIndex vec ix) 38 | 39 | 40 | instance U.Unbox a => Indexed N a where 41 | type IndexedR N = N 42 | vindexed (AChain _ dchain _) 43 | = vcacheChain (C.indexedD dchain) 44 | 45 | 46 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/chains/Data/Array/Repa/Vector/Operators/Indexs.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Indexs 3 | (Indexs (..)) 4 | where 5 | import Data.Array.Repa.Repr.Chain 6 | import Data.Array.Repa.Repr.Stream 7 | import Data.Array.Repa.Vector.Base 8 | import Data.Array.Repa.Chain.Indexs as C 9 | import Data.Array.Repa.Stream.Indexs as S 10 | import Data.Array.Repa as R 11 | import qualified Data.Vector.Unboxed as U 12 | 13 | import Data.Array.Repa.Vector.Operators.Map 14 | 15 | -- | Tag each element of a vector with its index in that vector. 16 | -- 17 | -- `vindexs` doesn't have a stream-consuming version because we won't 18 | -- know how many elements will be produced by each thread. 19 | -- 20 | -- @ 21 | -- vindexs [42,93,13] 22 | -- = [(0,42), (1,93), (2,13)] 23 | -- @ 24 | -- 25 | class (Source r a) => Indexs r a where 26 | type IndexsR r 27 | vindexs :: (Source r2 a) 28 | => Vector r Int -> Vector r2 a -> Vector (IndexsR r) a 29 | 30 | 31 | instance U.Unbox a => Indexs U a where 32 | type IndexsR U = D 33 | vindexs ixs vec 34 | = vmap (R.unsafeLinearIndex vec) ixs 35 | 36 | 37 | instance Indexs D a where 38 | type IndexsR D = D 39 | vindexs ixs vec 40 | = vmap (R.unsafeLinearIndex vec) ixs 41 | 42 | 43 | instance U.Unbox a => Indexs N a where 44 | type IndexsR N = N 45 | vindexs (AChain _ dchain _) vec 46 | = vcacheChain (C.indexsD dchain vec) 47 | 48 | instance U.Unbox a => Indexs S a where 49 | type IndexsR S = S 50 | vindexs (AStream _ dstr _) vec 51 | = vcacheStream (S.indexsD dstr vec) -- TODO: losing size information 52 | 53 | 54 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/chains/Data/Array/Repa/Vector/Operators/Map.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Map 3 | (Map (..)) 4 | where 5 | import Data.Array.Repa.Repr.Chain 6 | import Data.Array.Repa.Repr.Stream 7 | import Data.Array.Repa.Vector.Base 8 | import Data.Array.Repa.Chain.Map as C 9 | import Data.Array.Repa.Stream.Map as S 10 | import Data.Array.Repa as R 11 | import qualified Data.Vector.Unboxed as U 12 | 13 | 14 | -- | Vector map perserves the representation of delayed source vectors. 15 | class Map r a where 16 | type MapR r 17 | vmap :: (a -> b) -> Vector r a -> Vector (MapR r) b 18 | 19 | -- Unboxed 20 | instance U.Unbox e => Map U e where 21 | type MapR U = D 22 | 23 | vmap f arr 24 | = case delay arr of 25 | ADelayed sh g -> ADelayed sh (f . g) 26 | {-# INLINE [4] vmap #-} 27 | 28 | 29 | -- Delayed 30 | instance Map D e where 31 | type MapR D = D 32 | vmap = R.map 33 | {-# INLINE [4] vmap #-} 34 | 35 | 36 | -- Chained 37 | instance Map N a where 38 | type MapR N = N 39 | vmap f (AChain sh dchain arr) 40 | = AChain sh (C.mapD f dchain) (R.map f arr) 41 | {-# INLINE vmap #-} 42 | 43 | 44 | -- Streamed 45 | instance Map S a where 46 | type MapR S = S 47 | vmap f (AStream sh dchain arr) 48 | = AStream sh (S.mapD f dchain) (R.map f arr) 49 | {-# INLINE vmap #-} 50 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/chains/Data/Array/Repa/Vector/Operators/Scan.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Scan 3 | (vmapAccum) 4 | where 5 | import Data.Array.Repa.Repr.Stream 6 | import Data.Array.Repa.Vector.Base 7 | import Data.Array.Repa 8 | import qualified Data.Array.Repa.Stream as S 9 | import qualified Data.Vector.Unboxed as U 10 | 11 | -- MapAccum ------------------------------------------------------------------- 12 | -- | TODO: make this parallel 13 | vmapAccum :: U.Unbox a 14 | => (acc -> a -> (acc, a)) 15 | -> acc 16 | -> Vector U a 17 | -> Vector U a 18 | 19 | vmapAccum f acc0 (AUnboxed sh vec) 20 | = AUnboxed sh 21 | $ S.unstreamUnboxed $ S.mapAccum f acc0 $ S.streamUnboxed vec 22 | 23 | 24 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector-old/compile-test: -------------------------------------------------------------------------------- 1 | ghc Test.hs -package dph-prim-par -package repa-vector -package repa -package QuickCheck -i/home/amos/proj/ghc/libraries/dph/dph-test/framework/ -XTypeSynonymInstances -XTemplateHaskell -XFlexibleContexts 2 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Compute/Load.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Compute.Load 3 | ( Load (..) 4 | , LoadRange (..)) 5 | where 6 | import Data.Array.Repa.Vector.Compute.Target 7 | import Data.Array.Repa.Vector.Shape 8 | import Data.Array.Repa.Vector.Base 9 | import Data.Array.Repa.Vector.Operators.Bulk () 10 | 11 | 12 | -- Load ----------------------------------------------------------------------- 13 | -- | Compute all elements defined by an array and write them to a manifest 14 | -- target representation. 15 | -- 16 | -- In general this class only has instances for source array representations 17 | -- that support random access indexing (ie `Bulk` representations) 18 | -- 19 | class Shape sh => Load r1 sh e where 20 | 21 | -- | Fill an entire array sequentially. 22 | loadS :: Target r2 e => Array r1 sh e -> MVec r2 e -> IO () 23 | 24 | -- | Fill an entire array in parallel. 25 | loadP :: Target r2 e => Array r1 sh e -> MVec r2 e -> IO () 26 | 27 | 28 | -- FillRange ------------------------------------------------------------------ 29 | -- | Compute a range of elements defined by an array and write them to a fillable 30 | -- representation. 31 | -- 32 | -- In general this class only has instances for source array representations 33 | -- that support random access indexing (ie `Bulk` representations) 34 | -- 35 | class Shape sh => LoadRange r1 sh e where 36 | 37 | -- | Fill a range of an array sequentially. 38 | loadRangeS :: Target r2 e => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () 39 | 40 | -- | Fill a range of an array in parallel. 41 | loadRangeP :: Target r2 e => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Distro.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Distro 3 | 4 | 5 | -- TODO: should only be able to apply length when the length 6 | -- is known before computing the vector. 7 | -- Should be dependent on the balance mode. 8 | 9 | -- | Get the length of a vector. 10 | -- length :: Source r e => Vector r e -> Int 11 | -- length !v 12 | -- = case extent v of 13 | -- Z :. len -> len 14 | -- {-# INLINE [4] length #-} 15 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Operators/Bulk.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Bulk 3 | ( Bulk (..) 4 | , length) 5 | where 6 | import Data.Array.Repa.Vector.Base 7 | import Prelude hiding (length) 8 | 9 | 10 | -- | Bulk representations support random-access indexing and 11 | -- their extent is known up-front. 12 | class Bulk r a where 13 | -- | Shape-polymorphic indexing. 14 | index :: Shape sh => Array r sh a -> sh -> a 15 | index arr ix = arr `linearIndex` toIndex (extent arr) ix 16 | 17 | -- | Linear indexing into the underlying row-major representation. 18 | linearIndex :: Shape sh => Array r sh a -> Int -> a 19 | 20 | -- | Yield the extent of an array. 21 | extent :: Array r sh a -> sh 22 | 23 | 24 | -- | Yield the length of a bulk vector. 25 | length :: Bulk r a => Vector r a -> Int 26 | length = size . extent 27 | {-# INLINE [4] length #-} 28 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Operators/Flatten.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Flatten 3 | (flatten2) 4 | where 5 | import Data.Array.Repa.Vector.Base 6 | import Data.Array.Repa.Vector.Operators.Bulk 7 | import Data.Array.Repa.Vector.Repr.Delayed 8 | 9 | 10 | flatten2 11 | :: (Shape sh, Bulk r (a, a)) 12 | => Array r (sh :. Int) (a, a) 13 | -> Array D (sh :. Int) a 14 | 15 | flatten2 arr 16 | = let sh :. len = extent arr 17 | in fromFunction 18 | (sh :. len * 2) 19 | (\(ix :. n) 20 | -> if n `mod` 2 == 0 21 | then fst (index arr (ix :. (n `div` 2))) 22 | else snd (index arr (ix :. (n `div` 2)))) 23 | {-# INLINE flatten2 #-} 24 | 25 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Operators/Map.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Map 3 | (Map(..)) 4 | where 5 | import Data.Array.Repa.Vector.Base 6 | import Data.Array.Repa.Vector.Repr.Delayed 7 | import Data.Array.Repa.Vector.Repr.Unboxed 8 | import Data.Array.Repa.Vector.Repr.Flow 9 | import qualified Data.Array.Repa.Flow.Par as F 10 | import qualified Data.Vector.Unboxed as U 11 | import Prelude hiding (map) 12 | 13 | 14 | class Map r a where 15 | type TM r 16 | -- | Vector map where the representation of the result depends on the 17 | -- representation of the source. 18 | map :: Shape sh 19 | => (a -> b) -> Array r sh a -> Array (TM r) sh b 20 | 21 | 22 | -- Unboxed 23 | instance (Elt a, U.Unbox a) => Map U a where 24 | type TM U = D 25 | 26 | map f arr 27 | = case delay arr of 28 | ADelayed sh g -> ADelayed sh (f . g) 29 | {-# INLINE [4] map #-} 30 | 31 | 32 | -- Delayed 33 | instance Map D a where 34 | type TM D = D 35 | map f arr 36 | = case delay arr of 37 | ADelayed sh g -> ADelayed sh (f . g) 38 | {-# INLINE [4] map #-} 39 | 40 | 41 | -- Flows 42 | instance Map (O mode dist) a where 43 | type TM (O mode dist) 44 | = (O mode dist) 45 | 46 | map f (AFlow sh ff) 47 | = AFlow sh (F.map f ff) 48 | {-# INLINE [4] map #-} 49 | 50 | 51 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Operators/Project.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Project 3 | ( gather 4 | , gather1) 5 | where 6 | import Data.Array.Repa.Vector.Base 7 | import Data.Array.Repa.Vector.Operators.Bulk 8 | import Data.Array.Repa.Vector.Operators.Map as R 9 | import Prelude hiding (map) 10 | 11 | 12 | -- | Gather elements from a shared array. 13 | gather :: (Shape sh, Bulk r1 a, Map r2 sh) 14 | => Array r1 sh a -> Vector r2 sh -> Vector (TM r2) a 15 | gather vec ixs 16 | = R.map (index vec) ixs 17 | {-# INLINE [4] gather #-} 18 | 19 | 20 | -- | Like gather, but specialised to linear indices. 21 | gather1 :: (Bulk r1 a, Map r2 Int) 22 | => Vector r1 a -> Vector r2 Int -> Vector (TM r2) a 23 | gather1 vec ixs 24 | = R.map (linearIndex vec) ixs 25 | {-# INLINE gather1 #-} 26 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Operators/Unzip.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Operators.Unzip 3 | ( Unzip(..) 4 | , unzip3) 5 | where 6 | import Data.Array.Repa.Vector.Base 7 | import Data.Array.Repa.Vector.Operators.Map as R 8 | import Data.Array.Repa.Vector.Repr.Delayed 9 | import Data.Array.Repa.Vector.Repr.Unboxed 10 | import Prelude hiding (unzip, unzip3) 11 | 12 | class Unzip r a b where 13 | type TU r 14 | 15 | -- | Convert an array of pairs into a pair of arrays. 16 | unzip :: Shape sh 17 | => Array r sh (a, b) 18 | -> (Array (TU r) sh a, Array (TU r) sh b) 19 | 20 | 21 | -- Unboxed -------------------------------------------------------------------- 22 | instance ( Elt a, Unbox a 23 | , Elt b, Unbox b) => Unzip U a b where 24 | type TU U = D 25 | 26 | unzip vec 27 | = (R.map fst vec, R.map snd vec) 28 | {-# INLINE [4] unzip #-} 29 | 30 | 31 | unzip3 :: ( Shape sh 32 | , Map r (a, b, c) 33 | , Unzip (TM r) a (b, c) 34 | , Unzip (TU (TM r)) b c) 35 | => Array r sh (a, b, c) 36 | -> ( Array (TU (TM r)) sh a 37 | , Array (TU (TU (TM r))) sh b 38 | , Array (TU (TU (TM r))) sh c) 39 | 40 | unzip3 arr 41 | = let bake (x, y, z) = (x, (y, z)) 42 | arr' = R.map bake arr 43 | (arr1, arr1') = unzip arr' 44 | (arr2, arr3) = unzip arr1' 45 | in (arr1, arr2, arr3) 46 | {-# INLINE unzip3 #-} 47 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Data/Array/Repa/Vector/Segd.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Vector.Segd 3 | ( -- * Segment Descriptors 4 | Segd 5 | , empty 6 | , fromLengths 7 | , lengths 8 | , elements 9 | 10 | -- * Split Segment Descriptors 11 | , SplitSegd (..) 12 | , splitSegd 13 | , unsplitSegd) 14 | 15 | where 16 | import Data.Array.Repa.Vector.Base 17 | import Data.Array.Repa.Vector.Repr.Unboxed 18 | import Data.Array.Repa.Flow.Par.Segd (Segd, SplitSegd, empty) 19 | import qualified Data.Array.Repa.Flow.Par.Segd as Segd 20 | import qualified Data.Vector.Unboxed as U 21 | import GHC.Exts 22 | 23 | 24 | -- | Construct a segment descriptor from a vector of segment lengths. 25 | fromLengths :: Vector U Int -> Segd 26 | fromLengths vec 27 | = Segd.fromLengths (toUnboxed vec) 28 | {-# INLINE [4] fromLengths #-} 29 | 30 | 31 | -- | Take the segment lengths of a segment descriptor. 32 | lengths :: Segd -> Vector U Int 33 | lengths segd 34 | = fromUnboxed (Z :. U.length (Segd.lengths segd)) 35 | $ Segd.lengths segd 36 | {-# INLINE [4] lengths #-} 37 | 38 | 39 | -- | Take the total number of elements covered by a segment descriptor. 40 | elements :: Segd -> Int 41 | elements segd 42 | = I# (Segd.elements segd) 43 | {-# INLINE [4] elements #-} 44 | 45 | 46 | -- | O(log segs). Preprocess a `Segd` by splitting it into chunks, trying 47 | -- to assign the same number of elements to each thread. 48 | splitSegd :: Segd -> SplitSegd 49 | splitSegd segd 50 | = Segd.splitSegd theGang segd 51 | 52 | 53 | -- | O(1). Take the original unsplit version from a SplitSegd. 54 | unsplitSegd :: SplitSegd -> Segd 55 | unsplitSegd segd 56 | = Segd.splitOriginal segd 57 | {-# INLINE [4] unsplitSegd #-} 58 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2013, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /icebox/abandoned/repa-vector/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /icebox/deprecated/repa-bytestring/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2013, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /icebox/deprecated/repa-bytestring/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /icebox/deprecated/repa-bytestring/repa-bytestring.cabal: -------------------------------------------------------------------------------- 1 | Name: repa-bytestring 2 | Version: 3.0.0.1 3 | License: BSD3 4 | License-file: LICENSE 5 | Author: The DPH Team 6 | Maintainer: Ben Lippmeier 7 | Build-Type: Simple 8 | Cabal-Version: >=1.6 9 | Stability: experimental 10 | Category: Data Structures 11 | Homepage: http://repa.ouroborus.net 12 | Bug-reports: repa@ouroborus.net 13 | Description: (deprecated) 14 | Synopsis: (deprecated) 15 | 16 | Library 17 | Build-Depends: 18 | base == 4.*, 19 | repa == 3.0.* 20 | 21 | ghc-options: 22 | -Odph -Wall -fno-warn-missing-signatures 23 | 24 | 25 | -------------------------------------------------------------------------------- /icebox/stashed/Base.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Material.Safe.Base 3 | ( B (..) 4 | , U (..) 5 | , F (..)) 6 | where 7 | 8 | 9 | -- | Representation tag for arrays of Boxed elements. 10 | data B = B 11 | 12 | 13 | -- | Representation tag for arrays of Unboxed elements. 14 | -- 15 | -- The implementation uses @Data.Vector.Unboxed@ which is based on type 16 | -- families and picks an efficient, specialised representation for every 17 | -- element type. In particular, unboxed vectors of pairs are represented 18 | -- as pairs of unboxed vectors. 19 | -- This is the most efficient representation for numerical data. 20 | data U = U 21 | 22 | 23 | -- | Representation tag for Foreign arrays. 24 | data F = F 25 | 26 | -------------------------------------------------------------------------------- /repa-algorithms/Data/Array/Repa/Algorithms/ColorRamp.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE RankNTypes #-} 2 | 3 | -- | Hyprometric color ramps, for making pretty images from scalar data. 4 | module Data.Array.Repa.Algorithms.ColorRamp 5 | (rampColorHotToCold) 6 | where 7 | 8 | 9 | -- | Standard Hot to Cold hypsometric color ramp. 10 | -- Color sequence is red, yellow, green, cyan, blue. 11 | rampColorHotToCold 12 | :: forall a 13 | . (Ord a, Floating a) 14 | => a -- ^ Minimum value of range. 15 | -> a -- ^ Maximum value of range. 16 | -> a -- ^ Data value. 17 | -> (a, a, a) 18 | 19 | {-# INLINE rampColorHotToCold #-} 20 | rampColorHotToCold vmin vmax vNotNorm 21 | = let 22 | v | vNotNorm < vmin = vmin 23 | | vNotNorm > vmax = vmax 24 | | otherwise = vNotNorm 25 | 26 | dv = vmax - vmin 27 | 28 | result | v < vmin + 0.25 * dv 29 | = ( 0 30 | , 4 * (v - vmin) / dv 31 | , 1.0) 32 | 33 | | v < vmin + 0.5 * dv 34 | = ( 0 35 | , 1.0 36 | , 1 + 4 * (vmin + 0.25 * dv - v) / dv) 37 | 38 | | v < vmin + 0.75 * dv 39 | = ( 4 * (v - vmin - 0.5 * dv) / dv 40 | , 1.0 41 | , 0.0) 42 | 43 | | otherwise 44 | = ( 1.0 45 | , 1 + 4 * (vmin + 0.75 * dv - v) / dv 46 | , 0) 47 | 48 | in result 49 | 50 | -------------------------------------------------------------------------------- /repa-algorithms/Data/Array/Repa/Algorithms/DFT/Center.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Applying these transforms to the input of a DFT causes the output 3 | -- to be centered so that the zero frequency is in the middle. 4 | module Data.Array.Repa.Algorithms.DFT.Center 5 | ( center1d 6 | , center2d 7 | , center3d) 8 | where 9 | import Data.Array.Repa as R 10 | import Data.Array.Repa.Algorithms.Complex as R 11 | 12 | -- | Apply the centering transform to a vector. 13 | center1d 14 | :: Source r Complex 15 | => Array r DIM1 Complex -> Array D DIM1 Complex 16 | {-# INLINE center1d #-} 17 | center1d arr 18 | = R.traverse arr id 19 | (\get ix@(_ :. x) -> ((-1) ^ x) * get ix) 20 | 21 | 22 | -- | Apply the centering transform to a matrix. 23 | center2d 24 | :: Source r Complex 25 | => Array r DIM2 Complex -> Array D DIM2 Complex 26 | {-# INLINE center2d #-} 27 | center2d arr 28 | = R.traverse arr id 29 | (\get ix@(_ :. y :. x) -> ((-1) ^ (y + x)) * get ix) 30 | 31 | 32 | -- | Apply the centering transform to a 3d array. 33 | center3d 34 | :: Source r Complex 35 | => Array r DIM3 Complex -> Array D DIM3 Complex 36 | {-# INLINE center3d #-} 37 | center3d arr 38 | = R.traverse arr id 39 | (\get ix@(_ :. z :. y :. x) -> ((-1) ^ (z + y + x)) * get ix) 40 | -------------------------------------------------------------------------------- /repa-algorithms/Data/Array/Repa/Algorithms/DFT/Roots.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeOperators, RankNTypes #-} 2 | 3 | -- | Calculation of roots of unity for the forward and inverse DFT\/FFT. 4 | module Data.Array.Repa.Algorithms.DFT.Roots 5 | ( calcRootsOfUnityP 6 | , calcInverseRootsOfUnityP) 7 | where 8 | import Data.Array.Repa 9 | import Data.Array.Repa.Algorithms.Complex 10 | 11 | 12 | -- | Calculate roots of unity for the forward transform. 13 | calcRootsOfUnityP 14 | :: (Shape sh, Monad m) 15 | => (sh :. Int) -- ^ Length of lowest dimension of result. 16 | -> m (Array U (sh :. Int) Complex) 17 | 18 | calcRootsOfUnityP sh@(_ :. n) 19 | = computeP $ fromFunction sh f 20 | where 21 | f :: Shape sh => (sh :. Int) -> Complex 22 | f (_ :. i) 23 | = ( cos (2 * pi * (fromIntegral i) / len) 24 | , - sin (2 * pi * (fromIntegral i) / len)) 25 | 26 | len = fromIntegral n 27 | 28 | 29 | -- | Calculate roots of unity for the inverse transform. 30 | calcInverseRootsOfUnityP 31 | :: (Shape sh, Monad m) 32 | => (sh :. Int) -- ^ Length of lowest dimension of result. 33 | -> m (Array U (sh :. Int) Complex) 34 | 35 | calcInverseRootsOfUnityP sh@(_ :. n) 36 | = computeP $ fromFunction sh f 37 | where 38 | f :: Shape sh => (sh :. Int) -> Complex 39 | f (_ :. i) 40 | = ( cos (2 * pi * (fromIntegral i) / len) 41 | , sin (2 * pi * (fromIntegral i) / len)) 42 | 43 | len = fromIntegral n 44 | -------------------------------------------------------------------------------- /repa-algorithms/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2014, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-algorithms/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Auto/Base.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Auto.Base 3 | ( Array 4 | , Elem 5 | , Build) 6 | where 7 | import Data.Repa.Array.Material.Auto (A(..)) 8 | import qualified Data.Repa.Array.Generic as G 9 | import qualified Data.Repa.Array.Meta.Window as A 10 | 11 | 12 | -- | Arrays of elements that are automatically layed out into some 13 | -- efficient runtime representation. 14 | -- 15 | -- The implementation uses type families to chose unboxed representations 16 | -- for all elements that can be unboxed. In particular: arrays of unboxed 17 | -- tuples are represented as tuples of unboxed arrays, and nested arrays 18 | -- are represented using a segment descriptor and a single single flat 19 | -- vector containing all the elements. 20 | -- 21 | 22 | type Array a 23 | = G.Array A a 24 | 25 | -- | Class of elements that can be automatically organised into arrays. 26 | type Elem a 27 | = ( G.Bulk A a 28 | , A.Windowable A a) 29 | 30 | -- | Class of elements where arrays of those elements can be constructed 31 | -- in arbitrary order. 32 | type Build a 33 | = ( G.Bulk A a 34 | , G.Target A a) 35 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Generic/Convert.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE IncoherentInstances #-} 2 | module Data.Repa.Array.Generic.Convert 3 | (Convert (..)) 4 | where 5 | import Data.Repa.Array.Internals.Bulk 6 | 7 | -- | Constant time conversion of one array representation to another. 8 | class Convert r1 a1 r2 a2 where 9 | convert :: Array r1 a1 -> Array r2 a2 10 | 11 | instance Convert r a r a where 12 | convert = id 13 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Generic/Index.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Shapes and Indices 3 | module Data.Repa.Array.Generic.Index 4 | ( -- * Shapes 5 | Shape (..) 6 | , inShape 7 | , showShape 8 | 9 | -- ** Polymorphic Shapes 10 | , Z (..) 11 | , (:.) (..) 12 | 13 | -- | Synonyms for common layouts. 14 | , SH0, SH1, SH2, SH3, SH4, SH5 15 | 16 | -- | Helpers that constrain the coordinates to be @Int@s. 17 | , ish0, ish1, ish2, ish3, ish4, ish5 18 | 19 | -- * Layouts 20 | , Layout(..), LayoutI) 21 | where 22 | import Data.Repa.Array.Internals.Shape 23 | import Data.Repa.Array.Internals.Layout 24 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Generic/Load.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Generic.Load 3 | ( Load (..) 4 | , computeS 5 | , computeIntoS) 6 | where 7 | import Data.Repa.Array.Internals.Target as A 8 | import Data.Repa.Array.Internals.Load as A 9 | import Data.Repa.Array.Internals.Bulk as A 10 | import Data.Repa.Array.Generic.Index as A 11 | import System.IO.Unsafe 12 | #include "repa-array.h" 13 | 14 | 15 | -- | Sequential computation of delayed array elements. 16 | -- 17 | -- Elements of the source array are computed sequentially and 18 | -- written to a new array of the specified layout. 19 | -- 20 | computeS :: (Load lSrc lDst a, Index lSrc ~ Index lDst) 21 | => Name lDst -> Array lSrc a -> Array lDst a 22 | computeS !nDst !aSrc 23 | = let !lDst = create nDst (extent $ layout aSrc) 24 | Just aDst = computeIntoS lDst aSrc 25 | in aDst `seq` aDst 26 | {-# INLINE computeS #-} 27 | 28 | 29 | -- | Like `computeS` but use the provided desination layout. 30 | -- 31 | -- The size of the destination layout must match the size of the source 32 | -- array, else `Nothing`. 33 | -- 34 | computeIntoS :: Load lSrc lDst a 35 | => lDst -> Array lSrc a -> Maybe (Array lDst a) 36 | computeIntoS !lDst !aSrc 37 | | (A.size $ A.extent lDst) == A.length aSrc 38 | = unsafePerformIO 39 | $ do !buf <- unsafeNewBuffer lDst 40 | loadS aSrc buf 41 | !arr <- unsafeFreezeBuffer buf 42 | return $ Just arr 43 | 44 | | otherwise 45 | = Nothing 46 | {-# INLINE_ARRAY computeIntoS #-} 47 | 48 | 49 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Generic/Target.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Generic.Target 3 | ( Target (..), TargetI 4 | , empty, singleton 5 | , fromList, fromListInto 6 | , generateMaybeS, mapMaybeS 7 | , generateEitherS, mapEitherS) 8 | where 9 | import Data.Repa.Array.Internals.Target -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Internals/Check.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Internals.Check 3 | ( Check (..) 4 | , Safe (..) 5 | , Unsafe (..)) 6 | where 7 | import Data.Repa.Array.Generic.Index as A 8 | 9 | 10 | class Check m where 11 | method :: m 12 | check :: Shape sh => m -> sh -> sh -> Bool 13 | 14 | 15 | data Safe = Safe 16 | 17 | instance Check Safe where 18 | method = Safe 19 | check _ _ _ = True -- TODO: bounds checks 20 | 21 | 22 | data Unsafe = Unsafe 23 | 24 | instance Check Unsafe where 25 | method = Unsafe 26 | check _ _ _ = True 27 | 28 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Internals/Layout.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Internals.Layout 3 | (Layout (..), LayoutI) 4 | where 5 | import Data.Repa.Array.Internals.Shape 6 | 7 | 8 | -- | A layout provides a total order on the elements of an index space. 9 | -- 10 | -- We can talk about the n-th element of an array, independent of its 11 | -- shape and dimensionality. 12 | -- 13 | class Shape (Index l) => Layout l where 14 | 15 | -- | Short name for a layout which does not include details of 16 | -- the exact extent. 17 | data Name l 18 | 19 | -- | Type used to index into this array layout. 20 | type Index l 21 | 22 | -- | O(1). Proxy for the layout name. 23 | name :: Name l 24 | 25 | -- | O(1). Create a default layout of the given extent. 26 | create :: Name l -> Index l -> l 27 | 28 | -- | O(1). Yield the extent of the layout. 29 | extent :: l -> Index l 30 | 31 | -- | O(1). Convert a polymorphic index to a linear one. 32 | toIndex :: l -> Index l -> Int 33 | 34 | -- | O(1). Convert a linear index to a polymorphic one. 35 | fromIndex :: l -> Int -> Index l 36 | 37 | 38 | type LayoutI l = (Layout l, Index l ~ Int) 39 | 40 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Internals/Load.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Internals.Load 3 | (Load (..)) 4 | where 5 | import Data.Repa.Array.Internals.Target 6 | import Data.Repa.Array.Internals.Bulk 7 | import Data.Repa.Eval.Gang 8 | 9 | 10 | -- | Compute all elements defined by a delayed array and write them to a 11 | -- manifest target representation. 12 | -- 13 | -- The instances of this class require that the source array has a delayed 14 | -- representation. If you want to use a pre-existing manifest array as the 15 | -- source then `delay` it first. 16 | -- 17 | class (Bulk l1 a, Target l2 a) => Load l1 l2 a where 18 | 19 | -- | Fill an entire array sequentially. 20 | loadS :: Array l1 a -> Buffer l2 a -> IO () 21 | 22 | -- | Fill an entire array in parallel. 23 | loadP :: Gang 24 | -> Array l1 a -> Buffer l2 a -> IO () 25 | 26 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Internals/Operator/Compact.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Compacting operations on arrays. 3 | module Data.Repa.Array.Internals.Operator.Compact 4 | ( compact 5 | , compactIn) 6 | where 7 | import Data.Repa.Array.Internals.Layout as A 8 | import Data.Repa.Array.Internals.Target as A 9 | import Data.Repa.Array.Internals.Bulk as A 10 | import Data.Repa.Eval.Stream as A 11 | import Data.Repa.Stream as S 12 | import Prelude hiding (concat) 13 | #include "repa-array.h" 14 | 15 | 16 | -- | Combination of `fold` and `filter`. 17 | -- 18 | -- We walk over the stream front to back, maintaining an accumulator. 19 | -- At each point we can chose to emit an element (or not). 20 | -- 21 | compact :: (BulkI lSrc a, TargetI lDst b) 22 | => Name lDst 23 | -> (s -> a -> (s, Maybe b)) 24 | -> s 25 | -> Array lSrc a 26 | -> Array lDst b 27 | 28 | compact nDst f s0 arr 29 | = A.unstreamToArray nDst 30 | $ S.compactS f s0 31 | $ A.streamOfArray arr 32 | {-# INLINE_ARRAY compact #-} 33 | 34 | 35 | -- | Like `compact` but use the first value of the stream as the 36 | -- initial state, and add the final state to the end of the output. 37 | -- 38 | compactIn 39 | :: (BulkI lSrc a, TargetI lDst a) 40 | => Name lDst 41 | -> (a -> a -> (a, Maybe a)) 42 | -> Array lSrc a 43 | -> Array lDst a 44 | 45 | compactIn nDst f arr 46 | = A.unstreamToArray nDst 47 | $ S.compactInS f 48 | $ A.streamOfArray arr 49 | {-# INLINE_ARRAY compactIn #-} 50 | 51 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Internals/Operator/Filter.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Filtering operators on arrays. 3 | module Data.Repa.Array.Internals.Operator.Filter 4 | ( filter) 5 | where 6 | import Data.Repa.Array.Generic.Index as A 7 | import Data.Repa.Array.Internals.Target as A 8 | import Data.Repa.Array.Internals.Bulk as A 9 | import System.IO.Unsafe 10 | import Prelude as P hiding (filter) 11 | #include "repa-array.h" 12 | 13 | 14 | -- | Keep the elements of an array that match the given predicate. 15 | filter :: (BulkI lSrc a, TargetI lDst a) 16 | => Name lDst -> (a -> Bool) -> Array lSrc a -> Array lDst a 17 | 18 | filter nDst p arr 19 | = unsafePerformIO 20 | $ do 21 | let !len = A.length arr 22 | !buf <- unsafeNewBuffer (create nDst len) 23 | 24 | let loop_filter !ixSrc !ixDst 25 | | ixSrc >= len 26 | = return ixDst 27 | 28 | | otherwise 29 | = do let !x = arr `index` ixSrc 30 | case p x of 31 | False 32 | -> do loop_filter (ixSrc + 1) ixDst 33 | 34 | True 35 | -> do unsafeWriteBuffer buf ixDst x 36 | loop_filter (ixSrc + 1) (ixDst + 1) 37 | 38 | lenDst <- loop_filter 0 0 39 | 40 | buf' <- unsafeSliceBuffer 0 lenDst buf 41 | unsafeFreezeBuffer buf' 42 | {-# INLINE filter #-} 43 | 44 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Internals/Operator/Insert.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Insertion operations on arrays. 3 | module Data.Repa.Array.Internals.Operator.Insert 4 | (insert) 5 | where 6 | import Data.Repa.Array.Generic.Index as A 7 | import Data.Repa.Array.Meta.Tuple as A 8 | import Data.Repa.Array.Internals.Bulk as A 9 | import Data.Repa.Array.Internals.Target as A 10 | import Data.Repa.Eval.Stream as A 11 | import qualified Data.Repa.Stream as S 12 | #include "repa-array.h" 13 | 14 | 15 | -- | Insert elements produced by the given function in to an array. 16 | insert :: (BulkI lSrc a, TargetI lDst a) 17 | => Name lDst -- ^ Name of destination layout. 18 | -> (Int -> Maybe a) -- ^ Produce an element for this index. 19 | -> Array lSrc a -- ^ Array of source elements. 20 | -> Array lDst a 21 | 22 | insert nDst fNew aSrc 23 | = A.unstreamToArray nDst 24 | $ S.insertS fNew 25 | $ A.streamOfArray aSrc 26 | {-# INLINE_ARRAY insert #-} 27 | 28 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Internals/Operator/Replicate.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Replicate operations on arrays. 3 | module Data.Repa.Array.Internals.Operator.Replicate 4 | ( replicates ) 5 | where 6 | import Data.Repa.Array.Internals.Layout as A 7 | import Data.Repa.Array.Internals.Target as A 8 | import Data.Repa.Array.Internals.Bulk as A 9 | import Data.Repa.Eval.Stream as A 10 | import Data.Repa.Stream as S 11 | #include "repa-array.h" 12 | 13 | 14 | -- | Segmented replicate. 15 | replicates 16 | :: (BulkI lSrc (Int, a), TargetI lDst a) 17 | => Name lDst 18 | -> Array lSrc (Int, a) 19 | -> Array lDst a 20 | 21 | replicates nDst arr 22 | = A.unstreamToArray nDst 23 | $ S.replicatesS 24 | $ A.streamOfArray arr 25 | {-# INLINE_ARRAY replicates #-} 26 | 27 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Material/Auto.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Material.Auto 3 | ( A (..) 4 | , Name (..) 5 | , Array (..) 6 | , Buffer (..) 7 | 8 | -- * Date utils 9 | , rangeDate32) 10 | where 11 | import Data.Repa.Array.Material.Auto.Base 12 | import Data.Repa.Array.Material.Auto.InstArray 13 | import Data.Repa.Array.Material.Auto.InstBox 14 | import Data.Repa.Array.Material.Auto.InstChar 15 | import Data.Repa.Array.Material.Auto.InstDate32 16 | import Data.Repa.Array.Material.Auto.InstFloat 17 | import Data.Repa.Array.Material.Auto.InstInt 18 | import Data.Repa.Array.Material.Auto.InstList 19 | import Data.Repa.Array.Material.Auto.InstMaybe 20 | import Data.Repa.Array.Material.Auto.InstProduct 21 | import Data.Repa.Array.Material.Auto.InstTuple 22 | import Data.Repa.Array.Material.Auto.InstText 23 | import Data.Repa.Array.Material.Auto.InstUnit 24 | import Data.Repa.Array.Material.Auto.InstWord 25 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Material/Auto/Base.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE UndecidableInstances, IncoherentInstances #-} 2 | module Data.Repa.Array.Material.Auto.Base 3 | ( A (..) 4 | , Name (..) 5 | , Array (..)) 6 | where 7 | import Data.Repa.Array.Meta.Tuple as A 8 | import Data.Repa.Array.Internals.Layout as A 9 | import Data.Repa.Array.Material.Boxed as A 10 | import Data.Repa.Array.Material.Unboxed as A 11 | import Data.Repa.Array.Material.Foreign as A 12 | import Data.Repa.Array.Material.Nested as A 13 | #include "repa-array.h" 14 | 15 | 16 | -- | Arrays where the elements that are automatically layed out into some 17 | -- efficient runtime representation. 18 | -- 19 | -- The implementation uses type families to chose unboxed representations 20 | -- for all elements that can be unboxed. In particular: arrays of unboxed 21 | -- tuples are represented as tuples of unboxed arrays, and nested arrays 22 | -- are represented using a segment descriptor and a single single flat 23 | -- vector containing all the elements. 24 | -- 25 | data A = Auto { autoLength :: Int } 26 | deriving (Show, Eq) 27 | 28 | 29 | instance Layout A where 30 | data Name A = A 31 | type Index A = Int 32 | name = A 33 | create A len = Auto len 34 | extent (Auto len) = len 35 | toIndex _ ix = ix 36 | fromIndex _ ix = ix 37 | {-# INLINE_ARRAY name #-} 38 | {-# INLINE_ARRAY create #-} 39 | {-# INLINE_ARRAY extent #-} 40 | {-# INLINE_ARRAY toIndex #-} 41 | {-# INLINE_ARRAY fromIndex #-} 42 | 43 | deriving instance Eq (Name A) 44 | deriving instance Show (Name A) 45 | 46 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Material/Auto/Operator/Lines.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Material.Auto.Operator.Lines 3 | (findRowsStartEnd) 4 | where 5 | import Data.Repa.Array.Material.Auto.Base 6 | import Data.Repa.Array.Material.Auto.InstInt () 7 | import Data.Repa.Array.Material.Auto.InstWord 8 | import Data.Repa.Array.Material.Auto.InstTuple 9 | 10 | import qualified Data.Repa.Array.Generic as G 11 | import qualified Data.Repa.Array.Generic.Target as G 12 | import qualified Data.Repa.Array.Generic.Index as G 13 | 14 | import qualified Data.Repa.Stream as S 15 | import qualified Data.Repa.Eval.Stream as S 16 | import qualified Data.Vector.Fusion.Stream.Monadic as S 17 | 18 | import Data.Word 19 | import System.IO.Unsafe 20 | 21 | -- | Given a row ending byte and a buffer containing encoded rows, 22 | -- get buffers of row starting and ending indices. 23 | findRowsStartEnd 24 | :: Word8 25 | -> G.Array A Word8 26 | -> (G.Buffer A Int, G.Buffer A Int) 27 | 28 | findRowsStartEnd wSepLine (AArray_Word8 arrWords) 29 | = unsafePerformIO 30 | $ do 31 | let len = G.extent $ G.layout arrWords 32 | 33 | let (AArray_T2 (T2Array arr1 arr2)) 34 | = S.unstreamToArray A 35 | $ S.findSegmentsS (const True) (== wSepLine) (len - 1) 36 | $ S.indexed 37 | $ S.streamOfArray 38 | $ arrWords 39 | 40 | buf1 <- G.unsafeThawBuffer arr1 41 | buf2 <- G.unsafeThawBuffer arr2 42 | 43 | return (buf1, buf2) 44 | {-# NOINLINE findRowsStartEnd #-} -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Material/Foreign.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Array.Material.Foreign 3 | ( F (..) 4 | , Name (..) 5 | , Array (..) 6 | , Buffer (..) 7 | 8 | -- * Format conversion 9 | , unsafeCast 10 | , fromForeignPtr, toForeignPtr 11 | , fromStorableVector, toStorableVector 12 | , fromByteString, toByteString) 13 | where 14 | import Data.Repa.Array.Material.Foreign.Base 15 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Material/Foreign/Lines.hs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-array/Data/Repa/Array/Material/Foreign/Lines.hs -------------------------------------------------------------------------------- /repa-array/Data/Repa/Array/Meta/Linear.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE UndecidableInstances #-} 2 | module Data.Repa.Array.Meta.Linear 3 | ( L(..) 4 | , Name (..) 5 | , Array (..) 6 | , linear) 7 | where 8 | import Data.Repa.Array.Generic.Index 9 | import Data.Repa.Array.Internals.Bulk 10 | #include "repa-array.h" 11 | 12 | 13 | -- | A linear layout with the elements indexed by integers. 14 | -- 15 | -- * Indexing is not bounds checked. Indexing outside the extent 16 | -- yields the corresponding index. 17 | -- 18 | data L = Linear 19 | { linearLength :: Int } 20 | 21 | deriving instance Eq L 22 | deriving instance Show L 23 | 24 | 25 | -- | Linear layout. 26 | instance Layout L where 27 | data Name L = L 28 | type Index L = Int 29 | name = L 30 | create L len = Linear len 31 | extent (Linear len) = len 32 | toIndex _ ix = ix 33 | fromIndex _ ix = ix 34 | {-# INLINE_ARRAY name #-} 35 | {-# INLINE_ARRAY create #-} 36 | {-# INLINE_ARRAY extent #-} 37 | {-# INLINE_ARRAY toIndex #-} 38 | {-# INLINE_ARRAY fromIndex #-} 39 | 40 | deriving instance Eq (Name L) 41 | deriving instance Show (Name L) 42 | 43 | 44 | -- | Linear arrays. 45 | instance Bulk L Int where 46 | data Array L Int = LArray Int 47 | layout (LArray len) = Linear len 48 | index (LArray _) ix = ix 49 | {-# INLINE_ARRAY layout #-} 50 | {-# INLINE_ARRAY index #-} 51 | 52 | 53 | -- | Construct a linear array that produces the corresponding index 54 | -- for every element. 55 | -- 56 | -- @> toList $ linear 10 57 | -- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]@ 58 | -- 59 | linear :: Int -> Array L Int 60 | linear len = LArray len 61 | {-# INLINE linear #-} 62 | 63 | -------------------------------------------------------------------------------- /repa-array/Data/Repa/Fusion/Unpack.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Fusion.Unpack 3 | (Unpack (..)) 4 | where 5 | 6 | 7 | -- | Unpack the pieces of a structure into a tuple. 8 | -- 9 | -- This is used in a low-level fusion optimisation to ensure that 10 | -- intermediate values are unboxed. 11 | -- 12 | class Unpack a t | a -> t where 13 | unpack :: a -> t 14 | repack :: a -> t -> a 15 | 16 | -------------------------------------------------------------------------------- /repa-array/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-array/include/repa-array.h: -------------------------------------------------------------------------------- 1 | 2 | #define PHASE_FLOW [3] 3 | #define PHASE_ARRAY [2] 4 | #define PHASE_STREAM [1] 5 | #define PHASE_INNER [0] 6 | 7 | #define INLINE_FLOW INLINE PHASE_FLOW 8 | #define INLINE_ARRAY INLINE PHASE_ARRAY 9 | #define INLINE_STREAM INLINE PHASE_STREAM 10 | #define INLINE_INNER INLINE PHASE_INNER 11 | -------------------------------------------------------------------------------- /repa-convert/Data/Repa/Convert/Format.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | This module provides the `Format` class definition, 3 | -- without exporting the pre-defined formats. 4 | module Data.Repa.Convert.Format 5 | ( -- * Packing single fields 6 | Format (..) 7 | 8 | -- * Packable 9 | , Packable (..) 10 | , Packer (..) 11 | , unsafeRunPacker 12 | 13 | -- ** Unpackable 14 | , Unpackable (..) 15 | , Unpacker (..) 16 | , unsafeRunUnpacker) 17 | where 18 | import Data.Repa.Convert.Internal.Format 19 | import Data.Repa.Convert.Internal.Packable 20 | import Data.Repa.Convert.Internal.Packer 21 | import Data.Repa.Convert.Internal.Unpacker 22 | -------------------------------------------------------------------------------- /repa-convert/Data/Repa/Convert/Format/Fields.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-orphans #-} 2 | module Data.Repa.Convert.Format.Fields where 3 | import Data.Repa.Convert.Internal.Format 4 | import Data.Repa.Convert.Internal.Packable 5 | import Data.Repa.Scalar.Product 6 | #include "repa-convert.h" 7 | 8 | 9 | --------------------------------------------------------------------------------------------------- 10 | instance Format () where 11 | type Value () = () 12 | fieldCount _ = 0 13 | minSize _ = 0 14 | fixedSize _ = return 0 15 | packedSize _ _ = return 0 16 | {-# INLINE minSize #-} 17 | {-# INLINE fieldCount #-} 18 | {-# INLINE fixedSize #-} 19 | {-# INLINE packedSize #-} 20 | 21 | 22 | instance Packable () where 23 | packer _f _v dst _fails k 24 | = k dst 25 | {-# INLINE packer #-} 26 | 27 | 28 | instance Unpackable () where 29 | 30 | unpacker _f start _end _stop _fail eat 31 | = eat start () 32 | {-# INLINE unpacker #-} 33 | 34 | 35 | --------------------------------------------------------------------------------------------------- 36 | -- | Formatting fields. 37 | instance (Format a, Format b) 38 | => Format (a :*: b) where 39 | 40 | type Value (a :*: b) 41 | = Value a :*: Value b 42 | 43 | fieldCount (fa :*: fb) 44 | = fieldCount fa + fieldCount fb 45 | {-# NOINLINE fieldCount #-} 46 | 47 | minSize (fa :*: fb) 48 | = minSize fa + minSize fb 49 | {-# NOINLINE minSize #-} 50 | 51 | fixedSize (fa :*: fb) 52 | = do sa <- fixedSize fa 53 | sb <- fixedSize fb 54 | return $ sa + sb 55 | {-# NOINLINE fixedSize #-} 56 | 57 | packedSize (fa :*: fb) (xa :*: xb) 58 | = do sa <- packedSize fa xa 59 | sb <- packedSize fb xb 60 | return $ sa + sb 61 | {-# NOINLINE packedSize #-} 62 | 63 | -------------------------------------------------------------------------------- /repa-convert/Data/Repa/Convert/Format/Unit.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Unitary formats. 3 | module Data.Repa.Convert.Format.Unit 4 | ( UnitAsc (..)) 5 | where 6 | import Data.Repa.Convert.Internal.Format 7 | import Data.Repa.Convert.Internal.Packable 8 | import Data.Repa.Convert.Format.String 9 | import GHC.Exts 10 | import Data.Word 11 | import Prelude hiding (fail) 12 | #include "repa-convert.h" 13 | 14 | 15 | ------------------------------------------------------------------------------------------- UnitAsc 16 | -- | A particular ASCII string. 17 | data UnitAsc = UnitAsc String deriving (Eq, Show) 18 | instance Format UnitAsc where 19 | type Value UnitAsc = () 20 | fieldCount _ = 1 21 | minSize (UnitAsc s) = length s 22 | fixedSize (UnitAsc s) = Just $ length s 23 | packedSize (UnitAsc s) () = Just $ length s 24 | {-# INLINE fieldCount #-} 25 | {-# INLINE minSize #-} 26 | {-# INLINE fixedSize #-} 27 | {-# INLINE packedSize #-} 28 | 29 | 30 | instance Packable UnitAsc where 31 | packer (UnitAsc s) () start k 32 | = packer (FixChars (length s)) s start k 33 | {-# INLINE packer #-} 34 | 35 | 36 | instance Unpackable UnitAsc where 37 | unpacker (UnitAsc str) start end stop fail eat 38 | = do (Ptr ptr, str') <- unpackCharList (pw8 start) (pw8 end) stop 39 | if str == str' 40 | then eat ptr () 41 | else fail 42 | {-# NOINLINE unpacker #-} 43 | 44 | 45 | 46 | pw8 :: Addr# -> Ptr Word8 47 | pw8 addr = Ptr addr 48 | {-# INLINE pw8 #-} 49 | -------------------------------------------------------------------------------- /repa-convert/Data/Repa/Convert/Internal/Format.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Convert.Internal.Format 3 | (Format (..)) 4 | where 5 | 6 | 7 | -- | Relates a storage format to the Haskell type of the value 8 | -- that is stored in that format. 9 | class Format f where 10 | 11 | -- | Get the type of a value with this format. 12 | type Value f 13 | 14 | 15 | -- | Yield the number of separate fields in this format. 16 | fieldCount :: f -> Int 17 | 18 | 19 | -- | Yield the minumum number of bytes that a value of this 20 | -- format will take up. 21 | -- 22 | -- Packing a value into this format 23 | -- is guaranteed to use at least this many bytes. 24 | -- This is exact for fixed-size formats. 25 | minSize :: f -> Int 26 | 27 | 28 | -- | For fixed size formats, yield their size (length) in bytes. 29 | -- 30 | -- Yields `Nothing` if this is not a fixed size format. 31 | -- 32 | fixedSize :: f -> Maybe Int 33 | 34 | 35 | -- | Yield the maximum packed size of the value in this format. 36 | -- 37 | -- If `fixedSize` returns a size then `packedSize` returns the same size. 38 | -- 39 | -- For variable length formats, `packedSize` is an over-approximation. 40 | -- We allow the actual packed value to use less space, as it may not be 41 | -- possible to determine how much space it needs without actually packing it. 42 | -- 43 | -- Yields `Nothing` when a collection of values is to be packed into a 44 | -- fixed length format, but the size of the collection does not match 45 | -- the format. 46 | -- 47 | packedSize :: f -> Value f -> Maybe Int 48 | -------------------------------------------------------------------------------- /repa-convert/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-convert/include/repa-convert.h: -------------------------------------------------------------------------------- 1 | 2 | #define PHASE_REVEAL [4] 3 | #define PHASE_FLOW [3] 4 | #define PHASE_ARRAY [2] 5 | #define PHASE_STREAM [1] 6 | #define PHASE_INNER [0] 7 | 8 | #define INLINE_REVEAL INLINE PHASE_REVEAL 9 | #define INLINE_FLOW INLINE PHASE_FLOW 10 | #define INLINE_ARRAY INLINE PHASE_ARRAY 11 | #define INLINE_STREAM INLINE PHASE_STREAM 12 | #define INLINE_INNER INLINE PHASE_INNER 13 | -------------------------------------------------------------------------------- /repa-eval/Data/Repa/Eval/Generic/Par.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Generic parallel array computation operators. 3 | module Data.Repa.Eval.Generic.Par 4 | ( -- * Filling 5 | fillChunked 6 | , fillChunkedIO 7 | , fillBlock2 8 | , fillInterleaved 9 | , fillCursoredBlock2 10 | 11 | -- * Reduction 12 | , foldAll 13 | , foldInner) 14 | where 15 | import Data.Repa.Eval.Generic.Par.Chunked 16 | import Data.Repa.Eval.Generic.Par.Cursored 17 | import Data.Repa.Eval.Generic.Par.Interleaved 18 | import Data.Repa.Eval.Generic.Par.Reduction 19 | -------------------------------------------------------------------------------- /repa-eval/Data/Repa/Eval/Generic/Seq.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Generic sequential array computation operators. 3 | module Data.Repa.Eval.Generic.Seq 4 | ( -- * Filling 5 | fillLinear 6 | , fillBlock2 7 | , fillCursoredBlock2 8 | 9 | -- * Reduction 10 | , foldAll 11 | , foldRange 12 | , foldInner) 13 | where 14 | import Data.Repa.Eval.Generic.Seq.Chunked 15 | import Data.Repa.Eval.Generic.Seq.Cursored 16 | import Data.Repa.Eval.Generic.Seq.Reduction 17 | -------------------------------------------------------------------------------- /repa-eval/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-eval/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /repa-eval/repa-eval.cabal: -------------------------------------------------------------------------------- 1 | Name: repa-eval 2 | Version: 4.2.4.0 3 | License: BSD3 4 | License-file: LICENSE 5 | Author: The Repa Development Team 6 | Maintainer: Ben Lippmeier 7 | Build-Type: Simple 8 | Cabal-Version: >=1.10 9 | Stability: experimental 10 | Category: Data Structures 11 | Homepage: http://repa.ouroborus.net 12 | Bug-reports: repa@ouroborus.net 13 | Description: Low-level parallel operators on bulk random-accessble arrays. 14 | Synopsis: Low-level parallel operators on bulk random-accessble arrays. 15 | 16 | source-repository head 17 | type: git 18 | location: https://github.com/haskell-repa/repa.git 19 | 20 | Library 21 | Build-Depends: 22 | base >= 4.9 && <4.22 23 | Exposed-modules: 24 | Data.Repa.Eval.Elt 25 | Data.Repa.Eval.Gang 26 | Data.Repa.Eval.Generic.Seq 27 | Data.Repa.Eval.Generic.Par 28 | 29 | Default-Language: Haskell2010 30 | 31 | Other-modules: 32 | Data.Repa.Eval.Generic.Seq.Chunked 33 | Data.Repa.Eval.Generic.Seq.Cursored 34 | Data.Repa.Eval.Generic.Seq.Reduction 35 | 36 | Data.Repa.Eval.Generic.Par.Chunked 37 | Data.Repa.Eval.Generic.Par.Cursored 38 | Data.Repa.Eval.Generic.Par.Reduction 39 | Data.Repa.Eval.Generic.Par.Interleaved 40 | 41 | ghc-options: 42 | -Wall -fno-warn-missing-signatures 43 | -O2 44 | 45 | default-extensions: 46 | NoMonomorphismRestriction 47 | BangPatterns 48 | MagicHash 49 | UnboxedTuples 50 | ScopedTypeVariables 51 | PatternGuards 52 | FlexibleInstances 53 | TypeOperators 54 | FlexibleContexts 55 | DefaultSignatures 56 | 57 | -------------------------------------------------------------------------------- /repa-examples/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2014, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-examples/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /repa-examples/data/cosine-horizontal.bmp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/data/cosine-horizontal.bmp.gz -------------------------------------------------------------------------------- /repa-examples/data/cosine-rotated.bmp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/data/cosine-rotated.bmp.gz -------------------------------------------------------------------------------- /repa-examples/data/cosine-vertical.bmp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/data/cosine-vertical.bmp.gz -------------------------------------------------------------------------------- /repa-examples/data/lena.bmp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/data/lena.bmp.gz -------------------------------------------------------------------------------- /repa-examples/data/step20.bmp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/data/step20.bmp.gz -------------------------------------------------------------------------------- /repa-examples/examples/FFT/HighPass2d/src-fftw/FFTW.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | // Perform high-pass filtering on a 2d image. 7 | // The DC value is set to zero, but the other frequencies are kept. 8 | void highpass2d_fftw(int width, int height, u_int8_t* image) 9 | { 10 | // The size of the whole image. 11 | int size = height * width; 12 | 13 | // Allocate input and output buffers 14 | fftw_complex* buf1 = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * size); 15 | fftw_complex* buf2 = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * size); 16 | 17 | // Copy in image data as real values for the transform. 18 | for(int i = 0; i < size; i++) { 19 | buf1[i][0] = (double)image[i]; 20 | buf1[i][1] = 0; 21 | } 22 | 23 | // Transform to frequency space. 24 | fftw_plan pFwd = fftw_plan_dft_2d(width, height, buf1, buf2, FFTW_FORWARD, FFTW_ESTIMATE); 25 | fftw_execute(pFwd); 26 | fftw_destroy_plan(pFwd); 27 | 28 | // Zap the DC value 29 | buf2[0][0] = 0; 30 | buf2[0][1] = 0; 31 | 32 | // Transform back to image space. 33 | fftw_plan pBack = fftw_plan_dft_2d(width, height, buf2, buf1, FFTW_BACKWARD, FFTW_ESTIMATE); 34 | fftw_execute(pBack); 35 | fftw_destroy_plan(pBack); 36 | 37 | // Have to scale the output values to get back to the original. 38 | for(int i = 0; i < size; i++) { 39 | buf1[i][0] = buf1[i][0] / size; 40 | buf1[i][1] = buf1[i][1] / size; 41 | } 42 | 43 | // Copy the magnitude of the result back into the image. 44 | for(int i = 0; i < size; i++) { 45 | double re = buf1[i][0]; 46 | double im = buf1[i][1]; 47 | double mag = sqrt (re*re + im*im); 48 | image[i] = (u_int8_t)mag; 49 | } 50 | 51 | // Cleanup. 52 | fftw_free(buf1); 53 | fftw_free(buf2); 54 | } 55 | -------------------------------------------------------------------------------- /repa-examples/examples/FFT/HighPass2d/src-fftw/Main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "BMP.h" 7 | 8 | 9 | extern void highpass2d_fftw(int width, int height, u_int8_t* image); 10 | extern void highpass2d_jones(int width, int height, u_int8_t* image); 11 | 12 | int main(int argc, char** argv) 13 | { 14 | if(argc != 4) { 15 | printf("usage: highpass \n"); 16 | printf(" algorithms: -fftw -jones\n"); 17 | 18 | exit(1); 19 | } 20 | 21 | char* algName = argv[1]; 22 | char* fileNameIn = argv[2]; 23 | char* fileNameOut = argv[3]; 24 | 25 | // Decide what algorithm to use. 26 | void (*highpass2d)(int, int, u_int8_t*) = 0; 27 | if (strcmp(algName, "-fftw") == 0) 28 | highpass2d = highpass2d_fftw; 29 | else if (strcmp(algName, "-jones") == 0) 30 | highpass2d = highpass2d_jones; 31 | else { 32 | printf("unknown algorithm %s\n", algName); 33 | exit(1); 34 | } 35 | 36 | // Read the image. 37 | ImageRGB* image = readBMP24(fileNameIn); 38 | 39 | // Transform it. 40 | highpass2d(image->width, image->height, image->red); 41 | highpass2d(image->width, image->height, image->green); 42 | highpass2d(image->width, image->height, image->blue); 43 | 44 | // Write it back to file. 45 | writeBMP24(fileNameOut, image); 46 | } 47 | -------------------------------------------------------------------------------- /repa-examples/examples/FFT/HighPass2d/src-traverse/FFT.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Compute the DFT of a vector. 3 | fft1d :: Array DIM1 Complex 4 | -> Array DIM1 Complex 5 | 6 | fft1d vec 7 | = let (Z :. len) = extent vec 8 | in fft1d' len 0 1 vec 9 | 10 | 11 | fft1d' :: Int -- ^ Length. 12 | -> Int -- ^ Offset. 13 | -> Int -- ^ Stride. 14 | -> Array DIM1 Complex 15 | -> Array DIM1 Complex 16 | 17 | fft1d' n' offset' stride' vec@Manifest{} 18 | = go n' offset' stride' 19 | where go !n !offset !stride 20 | | n == 1 21 | = fromFunction (Z :. 1) (\_ -> vec !: (Z :. offset)) 22 | 23 | | otherwise 24 | = let n2 = n `div` 2 25 | evenT = force $ go n2 offset (stride * 2) 26 | oddT = force $ go n2 (offset + stride) (stride * 2) 27 | 28 | left = traverse2 evenT oddT 29 | (\sh _ -> sh) 30 | (\getEven getOdd k@(_ :. k') -> getEven k + twiddle k' n * getOdd k) 31 | 32 | right = traverse2 evenT oddT 33 | (\sh _ -> sh) 34 | (\getEven getOdd k@(_ :. k') -> getEven k - twiddle k' n * getOdd k) 35 | 36 | in left +:+ right 37 | 38 | 39 | twiddle :: Int -- ^ Index. 40 | -> Int -- ^ Length of vector. 41 | -> Complex 42 | 43 | {-# INLINE twiddle #-} 44 | twiddle !k' !n' 45 | = cos (2 * pi * k / n) :*: (- sin (2 * pi * k / n)) 46 | where k = fromIntegral k' 47 | n = fromIntegral n' 48 | -------------------------------------------------------------------------------- /repa-examples/examples/FFT/Paper/src-repa/Paper.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeOperators #-} 2 | 3 | module Paper where 4 | 5 | import Data.Array.Repa.Algorithms.Complex 6 | import Data.Array.Repa as A 7 | 8 | -- | Take the odd or even halves of an array. 9 | evenHalf, oddHalf 10 | :: Shape sh 11 | => Array (sh :. Int) Complex 12 | -> Array (sh :. Int) Complex 13 | 14 | evenHalf = halve (\(ix :. i) -> ix :. 2*i) 15 | oddHalf = halve (\(ix :. i) -> ix :. 2*i+1) 16 | 17 | halve :: Shape sh 18 | => (sh :. Int -> sh :. Int) 19 | -> Array (sh :. Int) Complex 20 | -> Array (sh :. Int) Complex 21 | 22 | halve sel arr 23 | = backpermute (sh :. n `div` 2) sel arr 24 | where sh :. n = extent arr 25 | 26 | 27 | fft2d :: Array DIM2 Complex 28 | -> Array DIM2 Complex 29 | -> Array DIM2 Complex 30 | 31 | fft2d rofu 32 | = fftTrans . fftTrans 33 | where fftTrans = transpose . fft1d rofu 34 | 35 | 36 | -- | Rank generalised worker. 37 | fft1d :: Shape sh 38 | => Array (sh :. Int) Complex 39 | -> Array (sh :. Int) Complex 40 | -> Array (sh :. Int) Complex 41 | 42 | fft1d rofu v 43 | | n > 2 = (left +^ right) +:+ (left -^ right) 44 | | n == 2 = traverse v id swivel 45 | where 46 | (_ :. n) = extent v 47 | swivel f (ix :. 0) = f (ix :. 0) + f (ix :. 1) 48 | swivel f (ix :. 1) = f (ix :. 0) - f (ix :. 1) 49 | 50 | rofu' = evenHalf rofu 51 | left = force . fft1d rofu' . evenHalf $ v 52 | right = force . (*^ rofu) . fft1d rofu' . oddHalf $ v 53 | 54 | -------------------------------------------------------------------------------- /repa-examples/examples/Laplace/data/pls-100x100.bmp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/examples/Laplace/data/pls-100x100.bmp.gz -------------------------------------------------------------------------------- /repa-examples/examples/Laplace/data/pls-100x100.pxm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/examples/Laplace/data/pls-100x100.pxm -------------------------------------------------------------------------------- /repa-examples/examples/Laplace/data/pls-400x400.bmp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/examples/Laplace/data/pls-400x400.bmp.gz -------------------------------------------------------------------------------- /repa-examples/examples/Laplace/src-repa/SolverStencil.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE BangPatterns, TemplateHaskell, QuasiQuotes, FlexibleContexts #-} 2 | module SolverStencil 3 | (solveLaplace) 4 | where 5 | import Data.Array.Repa as A 6 | import Data.Array.Repa.Stencil as A 7 | import Data.Array.Repa.Stencil.Dim2 as A 8 | import qualified Data.Array.Repa.Shape as S 9 | import Language.Haskell.TH 10 | import Language.Haskell.TH.Quote 11 | 12 | 13 | -- | Solver for the Laplace equation. 14 | solveLaplace 15 | :: Monad m 16 | => Int -- ^ Number of iterations to use. 17 | -> Array U DIM2 Double -- ^ Boundary value mask. 18 | -> Array U DIM2 Double -- ^ Boundary values. 19 | -> Array U DIM2 Double -- ^ Initial state. 20 | -> m (Array U DIM2 Double) 21 | 22 | solveLaplace !steps !arrBoundMask !arrBoundValue !arrInit 23 | = go steps arrInit 24 | where go 0 !arr = return arr 25 | go n !arr 26 | = do arr' <- relaxLaplace arr 27 | go (n - 1) arr' 28 | 29 | relaxLaplace arr 30 | = computeP 31 | $ A.szipWith (+) arrBoundValue 32 | $ A.szipWith (*) arrBoundMask 33 | $ A.smap (/ 4) 34 | $ mapStencil2 (BoundConst 0) 35 | [stencil2| 0 1 0 36 | 1 0 1 37 | 0 1 0 |] arr 38 | 39 | {-# NOINLINE solveLaplace #-} 40 | -------------------------------------------------------------------------------- /repa-examples/examples/MMult/data/id-10x10.mat: -------------------------------------------------------------------------------- 1 | MATRIX 2 | 10 10 3 | 1 0 0 0 0 0 0 0 0 0 4 | 0 1 0 0 0 0 0 0 0 0 5 | 0 0 1 0 0 0 0 0 0 0 6 | 0 0 0 1 0 0 0 0 0 0 7 | 0 0 0 0 1 0 0 0 0 0 8 | 0 0 0 0 0 1 0 0 0 0 9 | 0 0 0 0 0 0 1 0 0 0 10 | 0 0 0 0 0 0 0 1 0 0 11 | 0 0 0 0 0 0 0 0 1 0 12 | 0 0 0 0 0 0 0 0 0 1 13 | -------------------------------------------------------------------------------- /repa-examples/examples/MMult/data/random1-100x100.mat.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/examples/MMult/data/random1-100x100.mat.gz -------------------------------------------------------------------------------- /repa-examples/examples/MMult/data/random2-100x100.mat.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haskell-repa/repa/aedc349c2a3976fe236cb2b9d27fec1e44248b65/repa-examples/examples/MMult/data/random2-100x100.mat.gz -------------------------------------------------------------------------------- /repa-examples/examples/MMult/data/up-4x4.mat: -------------------------------------------------------------------------------- 1 | MATRIX 2 | 4 4 3 | 1 2 3 4 4 | 5 6 7 8 5 | 9 10 11 12 6 | 13 14 15 16 7 | -------------------------------------------------------------------------------- /repa-examples/examples/MMult/src-repa/Solver.hs: -------------------------------------------------------------------------------- 1 | 2 | module Solver (mmultP) where 3 | import Data.Array.Repa as R 4 | import Data.Array.Repa.Unsafe as R 5 | 6 | 7 | -- | Matrix matrix multiply. 8 | mmultP :: Monad m 9 | => Array U DIM2 Double 10 | -> Array U DIM2 Double 11 | -> m (Array U DIM2 Double) 12 | 13 | mmultP arr brr 14 | = do trr <- transpose2P brr 15 | let (Z :. h1 :. _) = extent arr 16 | let (Z :. _ :. w2) = extent brr 17 | computeP 18 | $ fromFunction (Z :. h1 :. w2) 19 | $ \ix -> R.sumAllS 20 | $ R.zipWith (*) 21 | (unsafeSlice arr (Any :. (row ix) :. All)) 22 | (unsafeSlice trr (Any :. (col ix) :. All)) 23 | {-# NOINLINE mmultP #-} 24 | 25 | 26 | -- | Transpose a 2D matrix. 27 | transpose2P 28 | :: Monad m 29 | => Array U DIM2 Double 30 | -> m (Array U DIM2 Double) 31 | 32 | transpose2P arr 33 | = computeUnboxedP 34 | $ unsafeBackpermute new_extent swap arr 35 | where swap (Z :. i :. j) = Z :. j :. i 36 | new_extent = swap (extent arr) 37 | {-# INLINE transpose2P #-} 38 | 39 | 40 | -- | Take the row number of a rank-2 index. 41 | row :: DIM2 -> Int 42 | row (Z :. r :. _) = r 43 | {-# INLINE row #-} 44 | 45 | 46 | -- | Take the column number of a rank-2 index. 47 | col :: DIM2 -> Int 48 | col (Z :. _ :. c) = c 49 | {-# INLINE col #-} 50 | 51 | 52 | -------------------------------------------------------------------------------- /repa-examples/examples/PageRank/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, University of New South Wales. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the University of New South Wales nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /repa-examples/examples/PageRank/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /repa-examples/examples/PageRank/data/pages.txt: -------------------------------------------------------------------------------- 1 | 1: 1 2 2 | 2: 5 3 | 4: 5 4 | 5: 7 5 | 6: 3 5 4 6 | 8: 2 10 9 7 | 9: 5 7 1 8 | 10: 9 9 | -------------------------------------------------------------------------------- /repa-examples/examples/PageRank/data/titles.txt: -------------------------------------------------------------------------------- 1 | Red 2 | Orange 3 | Yellow 4 | Green 5 | Blue 6 | Indigo 7 | Violet 8 | Black 9 | White 10 | Grey 11 | -------------------------------------------------------------------------------- /repa-examples/examples/PageRank/pagerank.cabal: -------------------------------------------------------------------------------- 1 | Name: pagerank 2 | Version: 1.0 3 | License: BSD3 4 | License-file: LICENSE 5 | Author: Ben Lippmeier 6 | Maintainer: Ben Lippmeier 7 | Build-Type: Simple 8 | Cabal-Version: >=1.6 9 | Stability: experimental 10 | Category: Data Structures 11 | 12 | Flag llvm 13 | Description: Compile via LLVM. This produces much better object code, 14 | but you need to have the LLVM compiler installed. 15 | 16 | Default: False 17 | 18 | Executable pagerank 19 | Build-depends: 20 | base, 21 | directory >= 1.1, 22 | bytestring >= 0.9.2, 23 | containers >= 0.4.2, 24 | repa == 3.4.*, 25 | vector >= 0.9, 26 | vector-algorithms >= 0.5.4 27 | 28 | Main-is: 29 | Main.hs 30 | 31 | other-modules: 32 | Page Progress 33 | External.Rank External.Step External.Count External.Titles 34 | Internal.Rank Internal.Step Internal.Load 35 | 36 | hs-source-dirs: src 37 | 38 | ghc-options: 39 | -rtsopts 40 | -threaded 41 | -Odph 42 | -fno-liberate-case 43 | -funfolding-use-threshold100 44 | -funfolding-keeness-factor100 45 | 46 | if flag(llvm) 47 | ghc-options: 48 | -fllvm -optlo-O3 49 | 50 | extensions: 51 | PatternGuards 52 | BangPatterns 53 | GADTs 54 | 55 | -- vim: nospell 56 | 57 | -------------------------------------------------------------------------------- /repa-examples/examples/PageRank/src/External/Count.hs: -------------------------------------------------------------------------------- 1 | 2 | module External.Count where 3 | import Progress 4 | import qualified Data.ByteString.Lazy.Char8 as BL 5 | 6 | 7 | -- | Get the maximum page number in the file, 8 | -- and count the total number of lines. 9 | countPages :: FilePath -> IO (Int, Int) 10 | countPages !filePath 11 | = do putStrLn $ "* Counting pages in file." 12 | bs <- BL.readFile filePath 13 | (lineCount, maxPageId) <- eat 0 0 (BL.lines bs) 14 | printPosition True " lines read : " 10000 lineCount 15 | putStrLn $ " max page id: " ++ padR 10 (show maxPageId) 16 | return (lineCount, maxPageId) 17 | 18 | where eat !lineCount !maxPageId [] 19 | = return (lineCount, maxPageId) 20 | 21 | eat !lineCount !maxPageId (l:ls) 22 | = case BL.readInt l of 23 | Nothing 24 | -> error $ "countPages: parse error on line " ++ show lineCount 25 | 26 | Just (pid', _) 27 | -> do let !maxPageId' = max pid' maxPageId 28 | printPosition False " lines read : " 10000 lineCount 29 | eat (lineCount + 1) maxPageId' ls 30 | 31 | -------------------------------------------------------------------------------- /repa-examples/examples/PageRank/src/Progress.hs: -------------------------------------------------------------------------------- 1 | 2 | module Progress 3 | ( printPosition 4 | , printProgress 5 | , padR 6 | , padL) 7 | where 8 | import System.IO 9 | import Control.Monad 10 | 11 | 12 | -- | Print position in a stream, without a maximum value. 13 | printPosition :: Bool -> String -> Int -> Int -> IO () 14 | printPosition isLast header block pos 15 | | pos == 0 16 | = do putStr $ header ++ padR 10 (show pos) 17 | hFlush stdout 18 | 19 | | pos `mod` block == 0 || isLast 20 | = do putStr $ replicate (length header + 10) '\b' 21 | putStr $ header ++ padR 10 (show pos) 22 | when isLast 23 | $ putStr "\n" 24 | hFlush stdout 25 | 26 | | otherwise 27 | = return () 28 | 29 | 30 | -- | Print progress in a stream towards a maximum value. 31 | printProgress :: String -> Int -> Int -> Int -> IO () 32 | printProgress header block pos len 33 | | pos == 0 34 | = do putStr $ header ++ padR 10 (show $ pos) ++ "/" ++ padR 10 (show len) 35 | hFlush stdout 36 | 37 | | pos `mod` block == 0 || pos == len 38 | = do let n = length header + 21 39 | putStr $ replicate n '\b' 40 | putStr $ header ++ padR 10 (show $ pos) ++ "/" ++ padR 10 (show len) 41 | when (pos == len) 42 | $ putStr "\n" 43 | hFlush stdout 44 | 45 | | otherwise 46 | = return () 47 | 48 | 49 | -- | Pretty print in a right-justified column. 50 | padR :: Int -> String -> String 51 | padR n str 52 | = replicate (n - length str) ' ' ++ str 53 | 54 | 55 | -- | Pretty print in a left-justified column. 56 | padL :: Int -> String -> String 57 | padL n str 58 | = str ++ replicate (n - length str) ' ' 59 | -------------------------------------------------------------------------------- /repa-examples/examples/QuickHull/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE BangPatterns #-} 2 | import SolverChunks 3 | import SVG 4 | import Points 5 | import Data.Array.Repa.Vector as R 6 | import qualified Data.Vector.Unboxed as U 7 | import Data.Array.Repa.IO.Timing 8 | 9 | main 10 | = do 11 | let pointCount = 100000 12 | let uPoints = genPointsDisc pointCount (400, 400) 350 13 | let vPoints = R.fromUnboxed (Z :. pointCount) uPoints 14 | let mFileSVG = Nothing -- Just "out.svg" 15 | 16 | -- Force points to create the input vector. 17 | U.force uPoints `seq` return () 18 | 19 | -- Compute the convex hull. 20 | (vHull, tElapsed) 21 | <- time 22 | $ let vHull = quickHull vPoints 23 | in vHull `seq` return vHull 24 | 25 | -- Print how long it took. 26 | putStr $ prettyTime tElapsed 27 | 28 | let !uHull = R.toUnboxed vHull 29 | 30 | -- If we were asked for an SVG then write it out to file. 31 | maybe (return ()) 32 | (\fileSVG -> 33 | writeFile fileSVG 34 | $ makeSVG (roundPoints $ U.toList uPoints) 35 | (roundPoints $ U.toList uHull)) 36 | mFileSVG 37 | 38 | {- 39 | points1 40 | = fromListUnboxed (Z :. 10) 41 | $ [ (-4, 1), (-2, 1), (-1, 4), ( 1, 1), (2, 3) 42 | , ( 3, 2), (-4, -1), (-1, -2), (-2, -3), (1, -4)] 43 | -} 44 | -------------------------------------------------------------------------------- /repa-examples/examples/QuickHull/SVG.hs: -------------------------------------------------------------------------------- 1 | 2 | 3 | module SVG where 4 | 5 | -- Making a SVG diagram of the points and hull 6 | makeSVG :: [(Int, Int)] -> [(Int, Int)] -> String 7 | makeSVG points hull 8 | = unlines 9 | $ [ "" ] 10 | ++ [svgPolygon hull] 11 | ++ map svgPoint points 12 | ++ map svgPointHull hull 13 | ++ [""] 14 | 15 | svgPolygon :: [(Int, Int)] -> String 16 | svgPolygon points 17 | = "" 21 | 22 | svgPoint :: (Int, Int) -> String 23 | svgPoint (x, y) 24 | = "" 27 | 28 | svgPointHull :: (Int, Int) -> String 29 | svgPointHull (x, y) 30 | = "" 33 | 34 | roundPoints :: [(Double, Double)] -> [(Int, Int)] 35 | roundPoints ps = [(round x, round y) | (x, y) <- ps] 36 | -------------------------------------------------------------------------------- /repa-examples/examples/QuickSelect/Solver.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE BangPatterns, MagicHash #-} 2 | module Solver 3 | (quick_select) 4 | where 5 | import Data.Array.Repa as R 6 | import Data.Array.Repa.Repr.Unboxed as R 7 | import Data.Array.Repa.Vector as R 8 | import Prelude as P 9 | import Data.Array.Repa.Vector.Segd (Segd(..)) 10 | import qualified Data.Array.Repa.Vector.Segd as Segd 11 | import GHC.Exts 12 | import qualified Data.Array.Repa.Vector.Operators.Fold as R 13 | import Data.Array.Repa.Repr.Stream 14 | import qualified Data.Array.Repa.Vector.Operators.Indexs as I 15 | 16 | {-# NOINLINE quick_select #-} 17 | quick_select 18 | -- I suspect using (Ord a => Vector U a) would produce worse core 19 | :: Vector U Int 20 | -> Int# 21 | -> Int 22 | quick_select !s !k 23 | = let !p = vindex s $ vlength s `div` 2 24 | !l = vcomputeUnboxedP $ vfilter (p) s 30 | !(I# len) = vlength s - vlength g 31 | in 32 | if k >=# len 33 | then quick_select g (k -# len) 34 | else p 35 | 36 | -------------------------------------------------------------------------------- /repa-examples/examples/QuickSelect/Test.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeOperators, FlexibleContexts, FlexibleInstances, TypeSynonymInstances #-} 2 | {-# LANGUAGE ParallelListComp, MagicHash, BangPatterns, ScopedTypeVariables #-} 3 | 4 | -- import Test.Framework 5 | -- import Test.Framework.Providers.QuickCheck2 6 | import Test.QuickCheck 7 | import Data.Array.Repa 8 | import Data.Array.Repa.Vector 9 | import Data.Array.Repa.Vector.Segd (Segd(..)) 10 | import System.IO.Unsafe 11 | import qualified Data.Vector.Unboxed as U 12 | import qualified Data.Array.Repa.Vector.Segd as Segd 13 | import Prelude as P 14 | import Data.List 15 | import GHC.Exts 16 | import Control.Applicative ((<$>)) 17 | 18 | import Solver 19 | --import System.IO.Unsafe 20 | import Debug.Trace 21 | 22 | 23 | -- Framework ------------------------------------------------------------------ 24 | main = quickCheck prop_qs 25 | 26 | prop_qs :: Int -> [Int] -> Int -> Bool 27 | prop_qs x1 xs1 k 28 | = let xs = (x1:xs1) -- non-empty 29 | k' = k `mod` length xs 30 | xs' = fromList' xs 31 | 32 | expect = (sort xs) !! k' 33 | result = quick_select xs' (unbox k') 34 | in result == expect 35 | 36 | unbox :: Int -> Int# 37 | unbox (I# i) = i 38 | 39 | fromList' :: U.Unbox a => [a] -> Vector U a 40 | fromList' l = fromListUnboxed (Z :. length l) l 41 | 42 | -------------------------------------------------------------------------------- /repa-examples/examples/SMVM/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE BangPatterns, MagicHash #-} 2 | 3 | import Solver 4 | import Data.Array.Repa.Vector as R 5 | import qualified Data.Array.Repa.Vector.Segd as Segd 6 | 7 | main 8 | = do let !matrix = fromListUnboxed (Z :. 7) 9 | $ [ (0, 1.0), (1, 0.2) 10 | , (0, 0.2), (1, 1.0), (2, 0.4) 11 | , (1, 0.4), (2, 1.0) ] 12 | 13 | let !segd = Segd.fromLengths 14 | (fromListUnboxed (Z :. 3) [ 2, 3, 2 ]) 15 | 16 | let !vector = fromListUnboxed (Z :. 3) 17 | [ 1.0, 1.0, 1.0 ] 18 | 19 | let !vec' = smvm segd matrix vector 20 | 21 | print $ vec' 22 | 23 | -------------------------------------------------------------------------------- /repa-examples/examples/SMVM/Solver.hs: -------------------------------------------------------------------------------- 1 | 2 | module Solver (smvm) where 3 | import Data.Array.Repa.Vector.Segd 4 | import Data.Array.Repa.Vector.Repr.Unboxed 5 | import Data.Array.Repa.Vector as R 6 | import Prelude as P 7 | 8 | smvm :: Segd 9 | -> Vector U (Int, Double) 10 | -> Vector U Double 11 | -> Vector U Double 12 | 13 | smvm !segd !matrix !vector 14 | = let (!ixs, !vals) = R.unzip matrix 15 | in R.unflowP 16 | $ R.sums segd 17 | $ R.zipWith (*) vals 18 | $ R.gather1 vector ixs 19 | {-# NOINLINE smvm #-} 20 | 21 | -------------------------------------------------------------------------------- /repa-examples/examples/Sobel/src-repa/Solver.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE PackageImports, BangPatterns, QuasiQuotes, PatternGuards #-} 2 | {-# OPTIONS -Wall -fno-warn-missing-signatures -fno-warn-incomplete-patterns #-} 3 | 4 | module Solver 5 | ( Image 6 | , gradientX 7 | , gradientY ) 8 | where 9 | import Data.Array.Repa as R 10 | import Data.Array.Repa.Stencil as R 11 | import Data.Array.Repa.Stencil.Dim2 as R 12 | 13 | type Image = Array U DIM2 Float 14 | 15 | gradientX :: Monad m => Image -> m Image 16 | gradientX img 17 | = computeP 18 | $ forStencil2 (BoundConst 0) img 19 | [stencil2| -1 0 1 20 | -2 0 2 21 | -1 0 1 |] 22 | {-# NOINLINE gradientX #-} 23 | 24 | 25 | gradientY :: Monad m => Image -> m Image 26 | gradientY img 27 | = computeP 28 | $ forStencil2 (BoundConst 0) img 29 | [stencil2| 1 2 1 30 | 0 0 0 31 | -1 -2 -1 |] 32 | {-# NOINLINE gradientY #-} 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /repa-examples/examples/Sobel/src-repa/SolverSeparated.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE PackageImports, BangPatterns, QuasiQuotes, PatternGuards #-} 2 | {-# OPTIONS -Wall -fno-warn-missing-signatures -fno-warn-incomplete-patterns #-} 3 | 4 | module SolverSeparated 5 | ( Image 6 | , gradientX_sep 7 | , gradientY_sep ) 8 | where 9 | import Data.Array.Repa as Repa 10 | import Data.Array.Repa.Stencil 11 | 12 | type Image = Array DIM2 Float 13 | 14 | gradientX_sep :: Image -> Image 15 | gradientX_sep = gradientX1 . gradientX2 16 | 17 | gradientX1 :: Image -> Image 18 | {-# NOINLINE gradientX1 #-} 19 | gradientX1 img 20 | = force2 21 | $ forStencil2 BoundClamp img 22 | [stencil2| 1 0 -1 |] 23 | 24 | gradientX2 :: Image -> Image 25 | {-# NOINLINE gradientX2 #-} 26 | gradientX2 img 27 | = force2 28 | $ forStencil2 BoundClamp img 29 | [stencil2| 1 30 | 2 31 | 1 |] 32 | 33 | 34 | gradientY_sep :: Image -> Image 35 | gradientY_sep = gradientY1 . gradientY2 36 | 37 | gradientY1 :: Image -> Image 38 | {-# NOINLINE gradientY1 #-} 39 | gradientY1 img 40 | = force2 41 | $ forStencil2 BoundClamp img 42 | [stencil2| 1 2 1 |] 43 | 44 | gradientY2 :: Image -> Image 45 | {-# NOINLINE gradientY2 #-} 46 | gradientY2 img 47 | = force2 48 | $ forStencil2 BoundClamp img 49 | [stencil2| 1 50 | 0 51 | -1 |] 52 | -------------------------------------------------------------------------------- /repa-examples/examples/ThreadLocal/Main.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Example of how to use one of Repa's low level array filling functions 3 | -- with a thread local state (or other IO action). 4 | -- 5 | import Data.Array.Repa.Eval 6 | import Data.Vector.Unboxed as V 7 | import Data.Vector.Unboxed.Mutable as VM 8 | import Data.IORef 9 | 10 | main 11 | = do vec <- doIt 100 12 | print vec 13 | 14 | -- | Generate a vector of the given length. 15 | {-# NOINLINE doIt #-} 16 | doIt :: Int -> IO (Vector (Int, Int)) 17 | doIt len 18 | = do mvec <- VM.new len 19 | 20 | fillChunkedIOP 21 | len 22 | (VM.unsafeWrite mvec) 23 | mkGetElem 24 | 25 | V.unsafeFreeze mvec 26 | 27 | 28 | -- | Make a function to compute each element of the array. 29 | -- In the first IO action you can do some per-thread initialisation. 30 | {-# INLINE mkGetElem #-} 31 | mkGetElem :: Int -> IO (Int -> IO (Int, Int)) 32 | mkGetElem threadId 33 | = newIORef (threadId * 1000) >>= \ref 34 | -> let 35 | -- The per-thread element function can use the per-thread 36 | -- value stored in the IORef in its closure. 37 | 38 | -- Write this as a separate binding with an INLINE pragma to 39 | -- ensure it is inlined into the unfolding of 'fillChunkedIOP'. 40 | {-# INLINE getElem #-} 41 | getElem :: Int -> IO (Int, Int) 42 | getElem ix 43 | = do z' <- readIORef ref 44 | writeIORef ref (z' + 1) 45 | return (z', ix) 46 | 47 | in return getElem 48 | -------------------------------------------------------------------------------- /repa-examples/examples/UnitTesting/UnitTesting.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell, ScopedTypeVariables, FlexibleContexts #-} 2 | module Main where 3 | import Data.Array.Repa 4 | import Data.Array.Repa.Arbitrary(forAll2UShaped, forAll2VShaped) 5 | import Test.QuickCheck 6 | import Test.QuickCheck.All 7 | import Control.Monad (liftM2) 8 | 9 | -- | Example of how write unit tests for Repa arrays of a given number of dimensions 10 | arrayAdditionU sh 11 | = forAll2UShaped sh test 12 | where test (a, b) = a +^ b == fromFunction (extent a) (\i -> ((a!i) + (b!i) :: Double)) 13 | 14 | arrayAdditionV sh 15 | = forAll2VShaped sh test 16 | where test (a, b) = a +^ b == fromFunction (extent a) (\i -> ((a!i) + (b!i) :: Double)) 17 | 18 | prop_addU1D :: DIM1 -> Property 19 | prop_addU1D = arrayAdditionU 20 | 21 | prop_addU2D :: DIM2 -> Property 22 | prop_addU2D = arrayAdditionU 23 | 24 | prop_addU3D :: DIM3 -> Property 25 | prop_addU3D = arrayAdditionU 26 | 27 | prop_addU4D :: DIM4 -> Property 28 | prop_addU4D = arrayAdditionU 29 | 30 | prop_addU5D :: DIM5 -> Property 31 | prop_addU5D = arrayAdditionU 32 | 33 | prop_addV1D :: DIM1 -> Property 34 | prop_addV1D = arrayAdditionV 35 | 36 | prop_addV2D :: DIM2 -> Property 37 | prop_addV2D = arrayAdditionV 38 | 39 | prop_addV3D :: DIM3 -> Property 40 | prop_addV3D = arrayAdditionV 41 | 42 | prop_addV4D :: DIM4 -> Property 43 | prop_addV4D = arrayAdditionV 44 | 45 | prop_addV5D :: DIM5 -> Property 46 | prop_addV5D = arrayAdditionV 47 | 48 | return [] -- see docs for quickCheckAll 49 | main = $quickCheckAll 50 | 51 | -------------------------------------------------------------------------------- /repa-examples/libc/BMP.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | typedef struct ImageRGB_ { 6 | int width; 7 | int height; 8 | u_int8_t* red; 9 | u_int8_t* green; 10 | u_int8_t* blue; 11 | } ImageRGB; 12 | 13 | ImageRGB* readBMP24 (char* fileName); 14 | void writeBMP24(char* fileName, ImageRGB* image); 15 | 16 | -------------------------------------------------------------------------------- /repa-examples/libc/ColorRamp.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | // Color Ramps ------------------------------------------------------------------------------------ 4 | // Standard Hot -> Cold hypsometric color ramp. 5 | // Sequence is red, yellow, green, cyan, blue. 6 | // All values are clamped to [vmin .. vmax] 7 | void rampColorHotToCold 8 | (double v 9 | , double vmin 10 | , double vmax 11 | , double* r // color component outputs 12 | , double* g 13 | , double* b) 14 | { 15 | if (v < vmin) v = vmin; 16 | if (v > vmax) v = vmax; 17 | double dv = vmax - vmin; 18 | 19 | if (v < (vmin + 0.25 * dv)) { 20 | *r = 0; 21 | *g = 4 * (v - vmin) / dv; 22 | *b = 1; 23 | } 24 | else if (v < (vmin + 0.5 * dv)) { 25 | *r = 0; 26 | *g = 1; 27 | *b = 1 + 4 * (vmin + 0.25 * dv - v) / dv; 28 | } 29 | else if (v < (vmin + 0.75 * dv)) { 30 | *r = 4 * (v - vmin - 0.5 * dv) / dv; 31 | *g = 1; 32 | *b = 0; 33 | } 34 | else { 35 | *r = 1; 36 | *g = 1 + 4 * (vmin + 0.75 * dv - v) / dv; 37 | *b = 0; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /repa-examples/libc/ColorRamp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ColorRamp_h_ 3 | #define _ColorRamp_h_ 4 | 5 | 6 | void rampColorHotToCold 7 | (double v 8 | , double vmin 9 | , double vmax 10 | , double* r // color component outputs 11 | , double* g 12 | , double* b); 13 | 14 | 15 | #endif -------------------------------------------------------------------------------- /repa-examples/libc/Matrix.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _Matrix_h_ 3 | #define _Matrix_h_ 4 | 5 | // A matrix represented as an array of rows. 6 | typedef struct { 7 | int width; 8 | int height; 9 | double** data; 10 | } Matrix; 11 | 12 | 13 | Matrix* createMatrix 14 | ( int width 15 | , int height 16 | , double (*mkElem)(int width, int height, int x, int y)); 17 | 18 | void freeMatrix 19 | (Matrix* mat); 20 | 21 | Matrix* newRandomMatrix 22 | ( int width 23 | , int height); 24 | 25 | Matrix* newZeroMatrix 26 | ( int width 27 | , int height); 28 | 29 | int matricesHaveSameShape 30 | ( Matrix* mat1 31 | , Matrix* mat2); 32 | 33 | double sumMatrix 34 | (Matrix* mat); 35 | 36 | void writeMatrixAsPPM 37 | ( char* fileName 38 | , Matrix* mat ); 39 | 40 | void writeMatrixAsTextFile 41 | ( char* fileName 42 | , Matrix* mat); 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /repa-examples/libc/Timing.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _Timing_h_ 3 | #define _Timing_h_ 4 | 5 | #include 6 | #include 7 | 8 | // -- timeval ----------------------------------------------------------------- 9 | void timeval_add( struct timeval *x, const struct timeval *y); 10 | void timeval_sub( struct timeval *x, const struct timeval *y); 11 | void timeval_print( const struct timeval *t ); 12 | 13 | 14 | // -- benchtime --------------------------------------------------------------- 15 | struct benchtime; 16 | 17 | struct benchtime* bench_begin(); 18 | void bench_end (struct benchtime *bt); 19 | void bench_print (struct benchtime *bt); 20 | void bench_done (struct benchtime *bt); 21 | 22 | 23 | #endif 24 | 25 | 26 | -------------------------------------------------------------------------------- /repa-flow/Data/Repa/Flow/Chunked/Replicate.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Flow.Chunked.Replicate 3 | ( replicates_i ) 4 | where 5 | import Data.Repa.Flow.Chunked.Base 6 | import qualified Data.Repa.Flow.Generic as G 7 | import qualified Data.Repa.Array.Generic as A 8 | 9 | 10 | replicates_i 11 | :: ( Flow i m lSrc (Int, a) 12 | , A.TargetI lDst a) 13 | => A.Name lDst 14 | -> Sources i m lSrc (Int, a) 15 | -> m (Sources i m lDst a) 16 | 17 | replicates_i nDst ss 18 | = G.smap_i (\_ arr -> A.replicates nDst arr) ss 19 | {-# INLINE replicates_i #-} 20 | -------------------------------------------------------------------------------- /repa-flow/Data/Repa/Flow/Generic/IO.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Flow.Generic.IO 3 | ( -- * Buckets 4 | module Data.Repa.Flow.IO.Bucket 5 | 6 | -- * Sourcing 7 | , sourceBytes 8 | , sourceChars 9 | , sourceChunks 10 | , sourceRecords 11 | , sourceLinesFormat 12 | 13 | , sourceLinesFormatFromLazyByteString 14 | 15 | -- * Sinking 16 | , sinkBytes 17 | , sinkChars 18 | , sinkLines 19 | 20 | -- * Sieving 21 | , sieve_o 22 | 23 | -- * Tables 24 | , sourceCSV 25 | , sourceTSV) 26 | where 27 | import Data.Repa.Flow.IO.Bucket 28 | import Data.Repa.Flow.Generic.IO.Base as F 29 | import Data.Repa.Flow.Generic.IO.XSV as F 30 | import Data.Repa.Flow.Generic.IO.Lines as F 31 | -------------------------------------------------------------------------------- /repa-flow/Data/Repa/Flow/Simple/List.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Flow.Simple.List 3 | ( fromList 4 | , toList 5 | , takeList) 6 | where 7 | import Data.Repa.Flow.Simple.Base 8 | import Data.Repa.Flow.States (States) 9 | import qualified Data.Repa.Flow.Generic as G 10 | #include "repa-flow.h" 11 | 12 | 13 | -- | Given an arity and a list of elements, yield a source that produces 14 | -- all the elements. 15 | fromList :: States () m 16 | => [a] -> m (Source m a) 17 | fromList xx = G.fromList () xx 18 | {-# INLINE fromList #-} 19 | 20 | 21 | -- | Drain a source into a list. 22 | toList :: States () m 23 | => Source m a -> m [a] 24 | toList s = G.toList1 () s 25 | {-# INLINE toList #-} 26 | 27 | 28 | -- | Drain the given number of elements from a single source into a list. 29 | takeList :: States () m 30 | => Int -> Source m a -> m [a] 31 | takeList len s = G.takeList1 len () s 32 | {-# INLINE takeList #-} 33 | -------------------------------------------------------------------------------- /repa-flow/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-flow/examples/00-Start/Main.hs: -------------------------------------------------------------------------------- 1 | 2 | module Main where 3 | import Data.Repa.Flow as F 4 | import Data.Repa.Array as A 5 | import Data.Char 6 | 7 | main 8 | = do ws <- fromFiles 9 | [ "/usr/share/dict/words" 10 | , "/usr/share/dict/cracklib-small"] 11 | sourceLines 12 | 13 | up <- map_i (A.map toUpper) ws 14 | out <- toFiles ["out1.txt", "out2.txt"] $ sinkLines 15 | drainS up out 16 | -------------------------------------------------------------------------------- /repa-flow/examples/01-Copy/Main.hs: -------------------------------------------------------------------------------- 1 | 2 | import Data.Repa.Flow as F 3 | import System.Environment 4 | import Prelude as P 5 | 6 | main :: IO () 7 | main 8 | = do args <- getArgs 9 | case args of 10 | [fileIn, fileOut] 11 | -> pcopy fileIn fileOut 12 | 13 | _ -> putStrLn $ P.unlines 14 | [ "Usage: flow-copy " ] 15 | 16 | 17 | -- | Copy a file from one place to another, one line at a time. 18 | pcopy :: FilePath -> FilePath -> IO () 19 | pcopy fileIn fileOut 20 | = do 21 | -- Source from the input file. 22 | ifile <- fromFiles [fileIn] sourceBytes 23 | 24 | -- Sink to the output file. 25 | ofile <- toFiles [fileOut] sinkBytes 26 | 27 | -- Drain the source into the sink. 28 | drainS ifile ofile 29 | -------------------------------------------------------------------------------- /repa-flow/include/repa-flow.h: -------------------------------------------------------------------------------- 1 | 2 | #define PHASE_FLOW [3] 3 | #define PHASE_ARRAY [2] 4 | #define PHASE_STREAM [1] 5 | #define PHASE_INNER [0] 6 | 7 | #define INLINE_FLOW INLINE PHASE_FLOW 8 | #define INLINE_ARRAY INLINE PHASE_ARRAY 9 | #define INLINE_STREAM INLINE PHASE_STREAM 10 | #define INLINE_INNER INLINE PHASE_INNER 11 | -------------------------------------------------------------------------------- /repa-io/Data/Array/Repa/IO/Internals/Text.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_HADDOCK hide #-} 2 | module Data.Array.Repa.IO.Internals.Text 3 | ( hWriteValues 4 | , readValues) 5 | where 6 | import System.IO 7 | import Data.Char 8 | 9 | -- Stuff shared with Matrix module ------------------------------------------------------------- 10 | -- | Write out values to a file. 11 | hWriteValues 12 | :: Show a 13 | => Handle 14 | -> [a] -- ^ Data values. 15 | -> IO () 16 | 17 | hWriteValues handle xx 18 | = go xx 19 | where go [] = return () 20 | go (x:xs) 21 | = do hPutStr handle $ show x 22 | hPutStr handle $ "\n" 23 | go xs 24 | 25 | 26 | -- | Read a string containing ints separated by whitespace. 27 | readValues :: (Num a, Read a) => String -> [a] 28 | readValues cs = readValues' [] cs 29 | where readValues' _ [] = [] 30 | readValues' acc (c : rest) 31 | | isSpace c 32 | = if null acc 33 | then readValues' [] rest 34 | else read (reverse acc) : readValues' [] rest 35 | 36 | | isDigit c || c == '.' || c == 'e' || c == '-' 37 | = readValues' (c : acc) rest 38 | 39 | | otherwise 40 | = error $ "unexpected char in Matrix file " ++ show (ord c) 41 | 42 | -------------------------------------------------------------------------------- /repa-io/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2013, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-io/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /repa-io/repa-io.cabal: -------------------------------------------------------------------------------- 1 | Name: repa-io 2 | Version: 3.4.2.0 3 | License: BSD3 4 | License-file: LICENSE 5 | Author: The DPH Team 6 | Maintainer: Ben Lippmeier 7 | Build-Type: Simple 8 | Cabal-Version: >=1.10 9 | Stability: experimental 10 | Category: Data Structures 11 | Homepage: http://repa.ouroborus.net 12 | Bug-reports: http://groups.google.com/d/forum/haskell-repa 13 | Description: 14 | Read and write Repa arrays in various formats. 15 | 16 | Synopsis: 17 | Read and write Repa arrays in various formats. 18 | 19 | source-repository head 20 | type: git 21 | location: https://github.com/haskell-repa/repa.git 22 | 23 | Library 24 | Build-Depends: 25 | base >= 4.8 && < 4.21 26 | , binary >= 0.7 && < 0.9 27 | , bmp >= 1.2 && <1.3 28 | , bytestring >= 0.10 && < 0.13 29 | , old-time == 1.1.* 30 | , repa >= 3.4 && <3.5 31 | , vector >= 0.11 && < 0.14 32 | 33 | ghc-options: 34 | -O2 35 | -Wall 36 | -fno-warn-missing-signatures 37 | 38 | default-language: 39 | Haskell2010 40 | 41 | Exposed-modules: 42 | Data.Array.Repa.IO.Binary 43 | Data.Array.Repa.IO.BMP 44 | Data.Array.Repa.IO.Matrix 45 | Data.Array.Repa.IO.Timing 46 | Data.Array.Repa.IO.Vector 47 | 48 | Other-modules: 49 | Data.Array.Repa.IO.Internals.Text 50 | 51 | -- vim: nospell 52 | -------------------------------------------------------------------------------- /repa-machine/Data/Repa/Machine.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Machine 3 | ( Machine (..) 4 | , Transition (..) 5 | , Exp, Val, Lit 6 | , step 7 | , eval 8 | , ErrorStep (..)) 9 | where 10 | import Data.Repa.Machine.Base 11 | import Data.Repa.Machine.Step 12 | import Data.Repa.Machine.Eval 13 | -------------------------------------------------------------------------------- /repa-machine/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-machine/example/Map.hs: -------------------------------------------------------------------------------- 1 | 2 | 3 | import Data.Repa.Merge.Machine 4 | import Data.Repa.Merge.Transition 5 | import Control.Monad.ST 6 | import Data.STRef 7 | import Data.Map (Map) 8 | import Data.Repa.Query.Eval.Env (Env) 9 | import qualified Data.Repa.Query.Eval.Env as Env 10 | import qualified Data.Repa.Query.Exp as Exp 11 | import qualified Data.Map as Map 12 | 13 | import Debug.Trace 14 | 15 | mmap :: Machine String (Map String) 16 | mmap 17 | = Machine "pull" 18 | False 19 | (Map.fromList tt) 20 | (Env.fromList [("x", Nothing)]) 21 | (Env.fromList [("y", Nothing)]) 22 | where 23 | tt = [ ("pull", TrPull "x" "out" "eject") 24 | , ("out", TrOut "y" xx "release") 25 | , ("release", TrRelease "x" "pull") 26 | , ("eject", TrEject "y" "halt") 27 | , ("halt", TrHalt) ] 28 | 29 | xx = Exp.XOp () Exp.SopMul [Exp.XVar () "x", Exp.xInt () 2] 30 | 31 | 32 | main 33 | = putStrLn "foo" 34 | 35 | 36 | lInts :: [Integer] -> [Lit] 37 | lInts is = map Exp.LInt is 38 | -------------------------------------------------------------------------------- /repa-machine/repa-machine.cabal: -------------------------------------------------------------------------------- 1 | Name: repa-machine 2 | Version: 4.1.0.1 3 | License: BSD3 4 | License-file: LICENSE 5 | Author: The Repa Development Team 6 | Maintainer: Ben Lippmeier 7 | Build-Type: Simple 8 | Cabal-Version: >=1.6 9 | Stability: experimental 10 | Category: Data Structures 11 | Homepage: http://repa.ouroborus.net 12 | Bug-reports: repa@ouroborus.net 13 | Description: Machine fusion. 14 | Synopsis: Machine fusion. 15 | 16 | source-repository head 17 | type: git 18 | location: https://github.com/haskell-repa/repa.git 19 | 20 | Library 21 | build-Depends: 22 | base == 4.8.*, 23 | mtl == 2.2.1, 24 | text == 1.2.*, 25 | aeson == 0.8.*, 26 | bytestring >= 0.10.6 && < 0.11, 27 | unordered-containers >= 0.2.5 && < 0.3, 28 | containers >= 0.5.6 && < 0.6, 29 | repa-query >= 4.1.0 && < 4.2 30 | 31 | 32 | exposed-modules: 33 | Data.Repa.Machine 34 | Data.Repa.Machine.Transition 35 | 36 | other-modules: 37 | Data.Repa.Machine.Base 38 | Data.Repa.Machine.Step 39 | Data.Repa.Machine.Eval 40 | 41 | ghc-options: 42 | -threaded 43 | -Wall -fno-warn-missing-signatures 44 | -O2 45 | 46 | extensions: 47 | OverloadedStrings 48 | BangPatterns 49 | PatternGuards 50 | FlexibleContexts 51 | FlexibleInstances 52 | TypeFamilies 53 | MultiParamTypeClasses 54 | RankNTypes 55 | GADTs 56 | ScopedTypeVariables 57 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Query 3 | ( -- * Jobs 4 | Job (..) 5 | , OutputFormat (..) 6 | 7 | -- * Query 8 | , Query (..) 9 | , QueryS 10 | 11 | -- * Graphs 12 | , Graph (..) 13 | , Node (..) 14 | , Source (..) 15 | , FlowOp (..) 16 | 17 | -- * Expressions 18 | , Exp (..) 19 | , Val (..) 20 | , Lit (..) 21 | , ScalarOp (..)) 22 | where 23 | import Data.Repa.Query.Job 24 | import Data.Repa.Query.Graph 25 | 26 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query/Build/Repa.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Query.Build.Repa 3 | ( decOfJob 4 | , expOfJob) 5 | where 6 | import Data.Repa.Query.Build.Repa.Job 7 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query/Graph.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Query.Graph 3 | ( -- * Graphs 4 | Graph (..) 5 | , Node (..) 6 | 7 | -- * Flow sources 8 | , Source (..) 9 | 10 | -- * Flow operators 11 | , FlowOp (..) 12 | 13 | -- * Scalar expressions 14 | , Exp (..) 15 | , Val (..) 16 | , Lit (..) 17 | , ScalarOp (..)) 18 | where 19 | import Data.Repa.Query.Graph.Graph 20 | 21 | 22 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query/Graph/Eval.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Query.Graph.Eval 3 | ( -- * Environments 4 | Env (..) 5 | , ExpEnv 6 | , ValEnv 7 | 8 | -- * Evaluators 9 | , evalExp 10 | , evalScalarOp) 11 | where 12 | import Data.Repa.Query.Graph.Eval.Env 13 | import Data.Repa.Query.Graph.Eval.Exp 14 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query/Graph/Eval/Env.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Generic environment type used when directly evaluating queries. 3 | module Data.Repa.Query.Graph.Eval.Env 4 | (Env (..)) 5 | where 6 | import Data.Map (Map) 7 | import qualified Data.Map as Map 8 | 9 | 10 | -- Generic environment type. 11 | class Env env a where 12 | type Bind env 13 | type Bound env 14 | 15 | -- | Look up a value. 16 | lookup :: Bound env -> env a -> Maybe a 17 | 18 | -- | Update a value. 19 | update :: Bound env -> a -> env a -> env a 20 | 21 | -- | Insert a new value. 22 | insert :: Bind env -> a -> env a -> env a 23 | 24 | -- | Get the binder corresponding to this bound occurrence from the 25 | bindOfBound :: Bound env -> env a -> Maybe (Bind env) 26 | 27 | -- | Yield an environment from a list of binders and values. 28 | fromList :: [(Bind env, a)] -> env a 29 | 30 | -- | Yield a list of binders and values from an environment. 31 | toList :: env a -> [(Bind env, a)] 32 | 33 | 34 | instance Ord n => Env (Map n) a where 35 | type Bind (Map n) = n 36 | type Bound (Map n) = n 37 | lookup = Map.lookup 38 | update = Map.insert 39 | insert = Map.insert 40 | bindOfBound u _ = Just u 41 | fromList = Map.fromList 42 | toList = Map.toList 43 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query/Job.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Query.Job 3 | ( -- * Jobs 4 | Job (..) 5 | 6 | -- * Query 7 | , Query (..) 8 | , QueryS 9 | , OutputFormat (..) 10 | 11 | -- * Extract 12 | , ExtractTarget (..) 13 | 14 | -- * Job Execution 15 | , runWith 16 | , RunError (..) 17 | 18 | -- * Job Explanations 19 | , explainWith 20 | , ExplainFormat (..) 21 | , ExplainError (..)) 22 | where 23 | import Data.Repa.Query.Job.Exec 24 | import Data.Repa.Query.Job.Spec 25 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query/Runtime.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Query.Runtime 3 | ( execQuery) 4 | where 5 | import Data.Repa.Query.Runtime.Driver 6 | 7 | -------------------------------------------------------------------------------- /repa-query/Data/Repa/Query/Source/Interact.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Driver commands for running queries interactively in GHCi. 3 | module Data.Repa.Query.Source.Interact 4 | ( module Data.Repa.Query.Source 5 | , module Data.Repa.Query.Job) 6 | where 7 | import Data.Repa.Query.Source 8 | import Data.Repa.Query.Job 9 | -------------------------------------------------------------------------------- /repa-query/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-query/include/repa-query.h: -------------------------------------------------------------------------------- 1 | 2 | #define PHASE_FLOW [3] 3 | #define PHASE_ARRAY [2] 4 | #define PHASE_STREAM [1] 5 | #define PHASE_INNER [0] 6 | 7 | #define INLINE_FLOW INLINE PHASE_FLOW 8 | #define INLINE_ARRAY INLINE PHASE_ARRAY 9 | #define INLINE_STREAM INLINE PHASE_STREAM 10 | #define INLINE_INNER INLINE PHASE_INNER 11 | -------------------------------------------------------------------------------- /repa-scalar/Data/Repa/Scalar/Singleton/Bool.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-} 2 | 3 | -- | Singleton typed booleans. 4 | module Data.Repa.Scalar.Singleton.Bool 5 | ( B (..) 6 | , Boolean (..)) 7 | where 8 | 9 | data B = Y | N 10 | 11 | deriving instance Show B 12 | 13 | data Boolean (b :: B) where 14 | Yes :: Boolean Y 15 | No :: Boolean N 16 | 17 | deriving instance Show (Boolean b) 18 | 19 | 20 | -------------------------------------------------------------------------------- /repa-scalar/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-store/Data/Repa/Store/Object/Column.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | A column is a single sequence of elements. 3 | module Data.Repa.Store.Object.Column 4 | (Column (..)) 5 | where 6 | import Control.Monad 7 | import Data.Text (Text) 8 | import Data.Aeson as A 9 | import qualified Data.Repa.Store.Format as F 10 | import qualified Data.HashMap.Strict as H 11 | 12 | 13 | -- | Describes a single column in a table. 14 | data Column 15 | = Column 16 | { -- | Name of column. 17 | columnName :: Text 18 | 19 | -- | On-disk data format of column. 20 | , columnFormat :: F.FieldBox 21 | 22 | -- | Human readable description of column. 23 | , columnDescription :: Text 24 | 25 | -- | Local directory that holds the column, if known. 26 | -- (not serialized) 27 | , columnDirectory :: Maybe FilePath } 28 | deriving Show 29 | 30 | 31 | instance ToJSON Column where 32 | toJSON (Column name field desc _mDirectory) 33 | = object [ "_type" .= text "column" 34 | , "name" .= toJSON name 35 | , "format" .= toJSON field 36 | , "desc" .= toJSON desc ] 37 | 38 | 39 | instance FromJSON Column where 40 | parseJSON (Object hh) 41 | | Just (String "column") <- H.lookup "_type" hh 42 | , Just (String name) <- H.lookup "name" hh 43 | , Just jField <- H.lookup "format" hh 44 | , Just (String desc) <- H.lookup "desc" hh 45 | = do 46 | field <- parseJSON jField 47 | return $ Column name field desc Nothing 48 | 49 | parseJSON _ = mzero 50 | 51 | 52 | text :: Text -> Text 53 | text x = x 54 | -------------------------------------------------------------------------------- /repa-store/Data/Repa/Store/Partitions.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Store.Partitions 3 | (listPartitions) 4 | where 5 | import System.FilePath 6 | import Control.Monad 7 | import Data.Maybe 8 | import qualified Data.List as L 9 | import qualified System.Directory as System 10 | 11 | 12 | -- | Given a table directory and its meta-data, 13 | -- get a list of all table partitions. 14 | -- 15 | listPartitions :: FilePath -> IO (Maybe [FilePath]) 16 | listPartitions path 17 | = check 18 | where 19 | check 20 | = do hasTableDir <- System.doesDirectoryExist path 21 | if not hasTableDir 22 | then return $ Nothing 23 | else list 24 | 25 | list 26 | = do files <- liftM (filter (\x -> not $ elem x [".", ".."])) 27 | $ System.getDirectoryContents path 28 | 29 | mfs <- liftM catMaybes 30 | $ mapM slurp 31 | $ map (path ) files 32 | 33 | return $ Just $ L.sort (liftM concat mfs) 34 | 35 | 36 | slurp :: FilePath -> IO (Maybe [FilePath]) 37 | slurp file 38 | = case takeExtension file of 39 | ".tsv" -> return $ Just [file] 40 | ".txt" -> return $ Just [file] 41 | _ -> return Nothing 42 | -------------------------------------------------------------------------------- /repa-store/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-store/include/repa-store.h: -------------------------------------------------------------------------------- 1 | 2 | #define PHASE_FLOW [3] 3 | #define PHASE_ARRAY [2] 4 | #define PHASE_STREAM [1] 5 | #define PHASE_INNER [0] 6 | 7 | #define INLINE_FLOW INLINE PHASE_FLOW 8 | #define INLINE_ARRAY INLINE PHASE_ARRAY 9 | #define INLINE_STREAM INLINE PHASE_STREAM 10 | #define INLINE_INNER INLINE PHASE_INNER 11 | -------------------------------------------------------------------------------- /repa-stream/Data/Repa/Chain.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | * See the "Data.Repa.Vector.Unboxed" module for examples of how these 3 | -- functions can be used. 4 | module Data.Repa.Chain 5 | ( -- * Chain Fusion 6 | Chain (..) 7 | , Step (..) 8 | , liftChain 9 | , resumeChain 10 | 11 | -- * Weaves 12 | , weaveC, Weave, Turn (..), Move(..), move 13 | 14 | -- * Folding 15 | , foldsC, Folds(..) 16 | 17 | -- * Unfolding 18 | , unfoldsC 19 | , StepUnfold (..) 20 | 21 | -- * Scanning 22 | , scanMaybeC 23 | 24 | -- * Grouping 25 | , groupsByC) 26 | where 27 | import Data.Repa.Chain.Base 28 | import Data.Repa.Chain.Scan 29 | import Data.Repa.Chain.Weave 30 | import Data.Repa.Chain.Folds 31 | -------------------------------------------------------------------------------- /repa-stream/Data/Repa/Chain/Base.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Chain.Base 3 | ( Step (..) 4 | , Chain (..) 5 | , liftChain 6 | , resumeChain) 7 | where 8 | import qualified Data.Vector.Fusion.Stream.Size as S 9 | import Control.Monad.Identity 10 | #include "repa-stream.h" 11 | 12 | 13 | -- | A chain is an abstract, stateful producer of elements. It is similar 14 | -- a stream as used in stream fusion, except that internal state is visible 15 | -- in its type. This allows the computation to be paused and resumed at a 16 | -- later point. 17 | data Chain m s a 18 | = Chain 19 | { -- | Expected size of the output. 20 | mchainSize :: S.Size 21 | 22 | -- | Starting state. 23 | , mchainState :: s 24 | 25 | -- | Step the chain computation. 26 | , mchainStep :: s -> m (Step s a) } 27 | 28 | 29 | -- | Result of a chain computation step. 30 | data Step s a 31 | 32 | -- | Yield an output value and a new seed. 33 | = Yield !a !s 34 | 35 | -- | Provide just a new seed. 36 | | Skip !s 37 | 38 | -- | Signal that the computation has finished. 39 | | Done !s 40 | deriving Show 41 | 42 | 43 | -- | Lift a pure chain to a monadic chain. 44 | liftChain :: Monad m => Chain Identity s a -> Chain m s a 45 | liftChain (Chain sz s step) 46 | = Chain sz s (return . runIdentity . step) 47 | {-# INLINE_STREAM liftChain #-} 48 | 49 | 50 | -- | Resume a chain computation from a previous state. 51 | resumeChain :: s -> Chain m s a -> Chain m s a 52 | resumeChain s' (Chain sz _s step) 53 | = Chain sz s' step 54 | {-# INLINE_STREAM resumeChain #-} 55 | 56 | -------------------------------------------------------------------------------- /repa-stream/Data/Repa/Stream.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | * See the "Data.Repa.Vector.Unboxed" module for examples of how these 3 | -- functions can be used. 4 | module Data.Repa.Stream 5 | ( -- * Compacting 6 | compactS 7 | , compactInS 8 | 9 | -- * Concatenating 10 | , catMaybesS 11 | 12 | -- * Dicing 13 | , diceSepS 14 | 15 | -- * Extracting 16 | , extractS 17 | 18 | -- * Inserting 19 | , insertS 20 | 21 | -- * Merging 22 | , mergeS 23 | 24 | -- * Padding 25 | , padForwardS 26 | 27 | -- * Ratcheting 28 | , unsafeRatchetS 29 | 30 | -- * Replicating 31 | , replicatesS 32 | 33 | -- * Segmenting 34 | , findSegmentsS 35 | , startLengthsOfSegsS) 36 | where 37 | import Data.Repa.Stream.Concat 38 | import Data.Repa.Stream.Compact 39 | import Data.Repa.Stream.Dice 40 | import Data.Repa.Stream.Extract 41 | import Data.Repa.Stream.Insert 42 | import Data.Repa.Stream.Merge 43 | import Data.Repa.Stream.Pad 44 | import Data.Repa.Stream.Ratchet 45 | import Data.Repa.Stream.Replicate 46 | import Data.Repa.Stream.Segment 47 | 48 | -------------------------------------------------------------------------------- /repa-stream/Data/Repa/Stream/Concat.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Stream.Concat 3 | (catMaybesS) 4 | where 5 | import Data.Vector.Fusion.Stream.Monadic (Stream(..), Step(..)) 6 | import qualified Data.Vector.Fusion.Stream.Size as S 7 | #include "repa-stream.h" 8 | 9 | 10 | -- | Return the `Just` elements from a stream, dropping the `Nothing`s. 11 | catMaybesS 12 | :: Monad m 13 | => Stream m (Maybe a) 14 | -> Stream m a 15 | 16 | catMaybesS (Stream istep si0 sz) 17 | = Stream ostep si0 (S.toMax sz) 18 | where 19 | ostep si 20 | = istep si >>= \m 21 | -> case m of 22 | Yield Nothing si' -> return $ Skip si' 23 | Yield (Just x) si' -> return $ Yield x si' 24 | Skip si' -> return $ Skip si' 25 | Done -> return $ Done 26 | {-# INLINE_INNER ostep #-} 27 | {-# INLINE_STREAM catMaybesS #-} 28 | 29 | -------------------------------------------------------------------------------- /repa-stream/Data/Repa/Stream/Extract.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Stream.Extract 3 | (extractS) 4 | where 5 | import Data.Vector.Fusion.Stream.Monadic (Stream(..), Step(..)) 6 | import qualified Data.Vector.Fusion.Stream.Size as S 7 | #include "repa-stream.h" 8 | 9 | 10 | -- | Extract segments from some source array and concatenate them. 11 | extractS 12 | :: Monad m 13 | => (Int -> a) -- ^ Function to get elements from the source. 14 | -> Stream m (Int, Int) -- ^ Segment start positions and lengths. 15 | -> Stream m a -- ^ Result elements. 16 | 17 | extractS get (Stream istep si0 _) 18 | = Stream ostep (si0, Nothing) S.Unknown 19 | where 20 | -- Start a new segment. 21 | ostep (si, Nothing) 22 | = istep si >>= \m 23 | -> case m of 24 | Yield (iStart, iLen) si' 25 | -> return $ Skip (si', Just (iStart, iStart + iLen)) 26 | Skip si' -> return $ Skip (si', Nothing) 27 | Done -> return $ Done 28 | 29 | -- Emit data from a segment. 30 | ostep (si, Just (iPos, iTop)) 31 | | iPos >= iTop = return $ Skip (si, Nothing) 32 | | otherwise = return $ Yield (get iPos) 33 | (si, Just (iPos + 1, iTop)) 34 | {-# INLINE_INNER ostep #-} 35 | {-# INLINE_STREAM extractS #-} 36 | -------------------------------------------------------------------------------- /repa-stream/Data/Repa/Stream/Insert.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Stream.Insert 3 | (insertS) 4 | where 5 | import Data.Vector.Fusion.Stream.Monadic (Stream(..), Step(..)) 6 | import qualified Data.Vector.Fusion.Stream.Size as S 7 | #include "repa-stream.h" 8 | 9 | 10 | -- | Insert elements produced by the given function in to a stream. 11 | insertS :: Monad m 12 | => (Int -> Maybe a) -- ^ Produce a new element for this index. 13 | -> Stream m a -- ^ Source stream. 14 | -> Stream m a 15 | 16 | insertS fNew (Stream istep si0 _) 17 | = Stream ostep (si0, 0, True, False) S.Unknown 18 | where 19 | ostep (si, ix, tryNew, srcDone) 20 | | tryNew 21 | = case fNew ix of 22 | Just x -> return $ Yield x (si, ix + 1, True, srcDone) 23 | Nothing 24 | | srcDone -> return Done 25 | | otherwise -> ostep_next si ix 26 | 27 | | otherwise 28 | = ostep_next si ix 29 | {-# INLINE_INNER ostep #-} 30 | 31 | ostep_next !si !ix 32 | = istep si >>= \m 33 | -> case m of 34 | Yield x si' -> return $ Yield x (si', ix + 1, True, False) 35 | Skip si' -> return $ Skip (si', ix, False, False) 36 | Done -> return $ Skip (si, ix, True, True) 37 | {-# INLINE_INNER ostep_next #-} 38 | {-# INLINE_STREAM insertS #-} 39 | -------------------------------------------------------------------------------- /repa-stream/Data/Repa/Stream/Replicate.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Repa.Stream.Replicate 3 | (replicatesS) 4 | where 5 | import Data.Vector.Fusion.Stream.Monadic (Stream(..), Step(..)) 6 | import qualified Data.Vector.Fusion.Stream.Size as S 7 | #include "repa-stream.h" 8 | 9 | 10 | -- | Segmented replicate. 11 | -- 12 | -- Given a stream of counts and values, produce a result stream where 13 | -- each value is replciated the associated number of times. 14 | -- 15 | replicatesS 16 | :: Monad m 17 | => Stream m (Int, a) 18 | -> Stream m a 19 | 20 | replicatesS (Stream istepA sA0 _) 21 | = Stream ostep (sA0, 0, Nothing) S.Unknown 22 | where 23 | -- Pull the next element from the source stream. 24 | ostep (sA, 0, mv) 25 | = istepA sA >>= \rA 26 | -> case rA of 27 | Done -> return Done 28 | Skip sA' -> return $ Skip (sA', 0, mv) 29 | Yield (len, val) sA' -> return $ Skip (sA', len, Just val) 30 | 31 | -- Should never be entered, as we'll always have a value 32 | -- when the count is non-zero. 33 | ostep (_, _, Nothing) 34 | = return Done 35 | 36 | ostep (sA, len, mv@(Just val)) 37 | = return $ Yield val (sA, len - 1, mv) 38 | {-# INLINE_INNER ostep #-} 39 | {-# INLINE_STREAM replicatesS #-} 40 | 41 | -------------------------------------------------------------------------------- /repa-stream/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa-stream/include/repa-stream.h: -------------------------------------------------------------------------------- 1 | 2 | #define PHASE_FLOW [3] 3 | #define PHASE_ARRAY [2] 4 | #define PHASE_STREAM [1] 5 | #define PHASE_INNER [0] 6 | 7 | #define INLINE_FLOW INLINE PHASE_FLOW 8 | #define INLINE_ARRAY INLINE PHASE_ARRAY 9 | #define INLINE_STREAM INLINE PHASE_STREAM 10 | #define INLINE_INNER INLINE PHASE_INNER 11 | -------------------------------------------------------------------------------- /repa-tools/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, The Repa Development Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa/Data/Array/Repa/Eval/Load.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Eval.Load 3 | ( Load (..) 4 | , LoadRange (..)) 5 | where 6 | import Data.Array.Repa.Eval.Target 7 | import Data.Array.Repa.Shape 8 | import Data.Array.Repa.Base 9 | 10 | -- Load ----------------------------------------------------------------------- 11 | -- | Compute all elements defined by an array and write them to a manifest 12 | -- target representation. 13 | -- 14 | -- Note that instances require that the source array to have a delayed 15 | -- representation such as `D` or `C`. If you want to use a pre-existing 16 | -- manifest array as the source then `delay` it first. 17 | class (Source r1 e, Shape sh) => Load r1 sh e where 18 | -- | Fill an entire array sequentially. 19 | loadS :: Target r2 e => Array r1 sh e -> MVec r2 e -> IO () 20 | 21 | -- | Fill an entire array in parallel. 22 | loadP :: Target r2 e => Array r1 sh e -> MVec r2 e -> IO () 23 | 24 | 25 | -- FillRange ------------------------------------------------------------------ 26 | -- | Compute a range of elements defined by an array and write them to a fillable 27 | -- representation. 28 | class (Source r1 e, Shape sh) => LoadRange r1 sh e where 29 | -- | Fill a range of an array sequentially. 30 | loadRangeS :: Target r2 e => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () 31 | 32 | -- | Fill a range of an array in parallel. 33 | loadRangeP :: Target r2 e => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /repa/Data/Array/Repa/Eval/Target.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Eval.Target 3 | ( Target (..) 4 | , fromList) 5 | where 6 | import Data.Array.Repa.Base 7 | import Data.Array.Repa.Shape 8 | import Control.Monad 9 | import System.IO.Unsafe 10 | 11 | 12 | -- Target --------------------------------------------------------------------- 13 | -- | Class of manifest array representations that can be constructed in parallel. 14 | class Target r e where 15 | 16 | -- | Mutable version of the representation. 17 | data MVec r e 18 | 19 | -- | Allocate a new mutable array of the given size. 20 | newMVec :: Int -> IO (MVec r e) 21 | 22 | -- | Write an element into the mutable array. 23 | unsafeWriteMVec :: MVec r e -> Int -> e -> IO () 24 | 25 | -- | Freeze the mutable array into an immutable Repa array. 26 | unsafeFreezeMVec :: sh -> MVec r e -> IO (Array r sh e) 27 | 28 | -- | Ensure the strucure of a mutable array is fully evaluated. 29 | deepSeqMVec :: MVec r e -> a -> a 30 | 31 | -- | Ensure the array is still live at this point. 32 | -- Needed when the mutable array is a ForeignPtr with a finalizer. 33 | touchMVec :: MVec r e -> IO () 34 | 35 | 36 | -- | O(n). Construct a manifest array from a list. 37 | fromList :: (Shape sh, Target r e) 38 | => sh -> [e] -> Array r sh e 39 | fromList sh xx 40 | = unsafePerformIO 41 | $ do let len = length xx 42 | if len /= size sh 43 | then error "Data.Array.Repa.Eval.Fill.fromList: provide array shape does not match list length" 44 | else do 45 | mvec <- newMVec len 46 | zipWithM_ (unsafeWriteMVec mvec) [0..] xx 47 | unsafeFreezeMVec sh mvec 48 | 49 | 50 | -------------------------------------------------------------------------------- /repa/Data/Array/Repa/Operators/Selection.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE BangPatterns #-} 2 | module Data.Array.Repa.Operators.Selection 3 | (selectP) 4 | where 5 | import Data.Array.Repa.Index 6 | import Data.Array.Repa.Base 7 | import Data.Array.Repa.Eval.Selection 8 | import Data.Array.Repa.Repr.Unboxed as U 9 | import qualified Data.Vector.Unboxed as V 10 | import System.IO.Unsafe 11 | 12 | 13 | -- | Produce an array by applying a predicate to a range of integers. 14 | -- If the predicate matches, then use the second function to generate 15 | -- the element. 16 | -- 17 | -- * This is a low-level function helpful for writing filtering 18 | -- operations on arrays. 19 | -- 20 | -- * Use the integer as the index into the array you're filtering. 21 | -- 22 | selectP :: (Unbox a, Monad m) 23 | => (Int -> Bool) -- ^ If the Int matches this predicate, 24 | -> (Int -> a) -- ^ ... then pass it to this fn to produce a value 25 | -> Int -- ^ Range between 0 and this maximum. 26 | -> m (Array U DIM1 a) -- ^ Array containing produced values. 27 | 28 | selectP match produce len 29 | = return 30 | $ unsafePerformIO 31 | $ do (sh, vec) <- selectIO 32 | return $ sh `seq` vec `seq` 33 | fromUnboxed sh vec 34 | 35 | where {-# INLINE selectIO #-} 36 | selectIO 37 | = do vecs <- selectChunkedP match produce len 38 | vecs' <- mapM V.unsafeFreeze vecs 39 | 40 | -- TODO: avoid copy somehow. 41 | let result = V.concat vecs' 42 | 43 | return (Z :. V.length result, result) 44 | {-# INLINE [1] selectP #-} 45 | -------------------------------------------------------------------------------- /repa/Data/Array/Repa/Repr/ByteString.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Repr.ByteString 3 | ( B, Array (..) 4 | , fromByteString, toByteString) 5 | where 6 | import Data.Array.Repa.Shape 7 | import Data.Array.Repa.Base 8 | import Data.Array.Repa.Repr.Delayed 9 | import Data.Word 10 | import qualified Data.ByteString as B 11 | import qualified Data.ByteString.Unsafe as BU 12 | import Data.ByteString (ByteString) 13 | 14 | 15 | -- | Strict ByteStrings arrays are represented as ForeignPtr buffers of Word8 16 | data B 17 | 18 | -- | Read elements from a `ByteString`. 19 | instance Source B Word8 where 20 | data Array B sh Word8 21 | = AByteString !sh !ByteString 22 | 23 | linearIndex (AByteString _ bs) ix 24 | = bs `B.index` ix 25 | {-# INLINE linearIndex #-} 26 | 27 | unsafeLinearIndex (AByteString _ bs) ix 28 | = bs `BU.unsafeIndex` ix 29 | {-# INLINE unsafeLinearIndex #-} 30 | 31 | extent (AByteString sh _) 32 | = sh 33 | {-# INLINE extent #-} 34 | 35 | deepSeqArray (AByteString sh bs) x 36 | = sh `deepSeq` bs `seq` x 37 | {-# INLINE deepSeqArray #-} 38 | 39 | 40 | deriving instance Show sh 41 | => Show (Array B sh Word8) 42 | 43 | deriving instance Read sh 44 | => Read (Array B sh Word8) 45 | 46 | 47 | -- Conversions ---------------------------------------------------------------- 48 | -- | O(1). Wrap a `ByteString` as an array. 49 | fromByteString 50 | :: sh -> ByteString -> Array B sh Word8 51 | fromByteString sh bs 52 | = AByteString sh bs 53 | {-# INLINE fromByteString #-} 54 | 55 | 56 | -- | O(1). Unpack a `ByteString` from an array. 57 | toByteString :: Array B sh Word8 -> ByteString 58 | toByteString (AByteString _ bs) = bs 59 | {-# INLINE toByteString #-} 60 | -------------------------------------------------------------------------------- /repa/Data/Array/Repa/Repr/Undefined.hs: -------------------------------------------------------------------------------- 1 | 2 | module Data.Array.Repa.Repr.Undefined 3 | ( X, Array (..)) 4 | where 5 | import Data.Array.Repa.Base 6 | import Data.Array.Repa.Shape 7 | import Data.Array.Repa.Eval 8 | 9 | 10 | -- | An array with undefined elements. 11 | -- 12 | -- * This is normally used as the last representation in a partitioned array, 13 | -- as the previous partitions are expected to provide full coverage. 14 | data X 15 | 16 | 17 | -- | Undefined array elements. Inspecting them yields `error`. 18 | -- 19 | instance Source X e where 20 | data Array X sh e 21 | = AUndefined !sh 22 | 23 | deepSeqArray _ x 24 | = x 25 | {-# INLINE deepSeqArray #-} 26 | 27 | extent (AUndefined sh) 28 | = sh 29 | {-# INLINE extent #-} 30 | 31 | index (AUndefined _) _ 32 | = error $ "Repa: array element is undefined." 33 | {-# INLINE index #-} 34 | 35 | linearIndex (AUndefined _) ix 36 | = error $ "Repa: array element at " ++ show ix ++ " is undefined." 37 | {-# INLINE linearIndex #-} 38 | 39 | 40 | deriving instance Show sh 41 | => Show (Array X sh e) 42 | 43 | deriving instance Read sh 44 | => Read (Array X sh e) 45 | 46 | 47 | instance Shape sh => Load X sh e where 48 | loadS _ _ = return () 49 | loadP _ _ = return () 50 | 51 | 52 | -------------------------------------------------------------------------------- /repa/Data/Array/Repa/Stencil.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS -Wnot #-} 2 | 3 | -- | Efficient computation of stencil based convolutions. 4 | -- 5 | module Data.Array.Repa.Stencil 6 | ( Stencil (..) 7 | , Boundary (..) 8 | 9 | -- * Stencil creation. 10 | , makeStencil) 11 | where 12 | import Data.Array.Repa 13 | import Data.Array.Repa.Base 14 | import Data.Array.Repa.Stencil.Base 15 | import Data.Array.Repa.Specialised.Dim2 16 | 17 | -------------------------------------------------------------------------------- /repa/Data/Array/Repa/Unsafe.hs: -------------------------------------------------------------------------------- 1 | 2 | -- | Functions without sanity or bounds checks. 3 | module Data.Array.Repa.Unsafe 4 | ( unsafeBackpermute 5 | , unsafeBackpermuteDft 6 | , unsafeSlice 7 | , unsafeExtend 8 | , unsafeTraverse 9 | , unsafeTraverse2 10 | , unsafeTraverse3 11 | , unsafeTraverse4) 12 | where 13 | import Data.Array.Repa.Operators.IndexSpace 14 | import Data.Array.Repa.Operators.Traversal 15 | -------------------------------------------------------------------------------- /repa/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2014, The Data Parallel Haskell Team 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | - The names of the copyright holders may not be used to endorse or promote 14 | products derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /repa/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /stack-7.10.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html 2 | # vim: nospell 3 | 4 | resolver: lts-6.35 5 | 6 | packages: 7 | - repa 8 | - repa-io 9 | - repa-algorithms 10 | - repa-examples 11 | 12 | # Packages to be pulled from upstream that are not in the resolver 13 | # extra-deps: [] 14 | 15 | # Override default flag values for local packages and extra-deps 16 | # flags: {} 17 | 18 | # Extra package databases containing global packages 19 | # extra-package-dbs: [] 20 | 21 | # Control whether we use the GHC we find on the path 22 | # system-ghc: true 23 | 24 | # Require a specific version of stack, using version ranges 25 | # require-stack-version: -any # Default 26 | # require-stack-version: >= 1.0.0 27 | 28 | # Override the architecture used by stack, especially useful on Windows 29 | # arch: i386 30 | # arch: x86_64 31 | 32 | # Extra directories used by stack for building 33 | # extra-include-dirs: [/path/to/dir] 34 | # extra-lib-dirs: [/path/to/dir] 35 | 36 | # Allow a newer minor version of GHC than the snapshot specifies 37 | # compiler-check: newer-minor 38 | -------------------------------------------------------------------------------- /stack-8.0.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html 2 | # vim: nospell 3 | 4 | resolver: lts-9.21 5 | 6 | packages: 7 | - repa 8 | - repa-io 9 | - repa-algorithms 10 | - repa-examples 11 | 12 | # Packages to be pulled from upstream that are not in the resolver 13 | # extra-deps: [] 14 | 15 | # Override default flag values for local packages and extra-deps 16 | # flags: {} 17 | 18 | # Extra package databases containing global packages 19 | # extra-package-dbs: [] 20 | 21 | # Control whether we use the GHC we find on the path 22 | # system-ghc: true 23 | 24 | # Require a specific version of stack, using version ranges 25 | # require-stack-version: -any # Default 26 | # require-stack-version: >= 1.0.0 27 | 28 | # Override the architecture used by stack, especially useful on Windows 29 | # arch: i386 30 | # arch: x86_64 31 | 32 | # Extra directories used by stack for building 33 | # extra-include-dirs: [/path/to/dir] 34 | # extra-lib-dirs: [/path/to/dir] 35 | 36 | # Allow a newer minor version of GHC than the snapshot specifies 37 | # compiler-check: newer-minor 38 | -------------------------------------------------------------------------------- /stack-8.2.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html 2 | # vim: nospell 3 | 4 | resolver: lts-11.22 5 | 6 | packages: 7 | - repa 8 | - repa-io 9 | - repa-algorithms 10 | - repa-examples 11 | 12 | # Packages to be pulled from upstream that are not in the resolver 13 | # extra-deps: [] 14 | 15 | # Override default flag values for local packages and extra-deps 16 | # flags: {} 17 | 18 | # Extra global and per-package GHC options 19 | # ghc-options: {} 20 | 21 | # Extra package databases containing global packages 22 | # extra-package-dbs: [] 23 | 24 | # Control whether we use the GHC we find on the path 25 | # system-ghc: true 26 | 27 | # Require a specific version of stack, using version ranges 28 | # require-stack-version: -any # Default 29 | # require-stack-version: >= 1.0.0 30 | 31 | # Override the architecture used by stack, especially useful on Windows 32 | # arch: i386 33 | # arch: x86_64 34 | 35 | # Extra directories used by stack for building 36 | # extra-include-dirs: [/path/to/dir] 37 | # extra-lib-dirs: [/path/to/dir] 38 | 39 | # Allow a newer minor version of GHC than the snapshot specifies 40 | # compiler-check: newer-minor 41 | -------------------------------------------------------------------------------- /stack-8.4.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html 2 | # vim: nospell 3 | 4 | resolver: lts-12.26 5 | 6 | packages: 7 | - repa 8 | - repa-io 9 | - repa-algorithms 10 | - repa-examples 11 | 12 | # Packages to be pulled from upstream that are not in the resolver 13 | # extra-deps: [] 14 | 15 | # Override default flag values for local packages and extra-deps 16 | # flags: {} 17 | 18 | # Extra global and per-package GHC options 19 | # ghc-options: {} 20 | 21 | # Extra package databases containing global packages 22 | # extra-package-dbs: [] 23 | 24 | # Control whether we use the GHC we find on the path 25 | # system-ghc: true 26 | 27 | # Require a specific version of stack, using version ranges 28 | # require-stack-version: -any # Default 29 | # require-stack-version: >= 1.0.0 30 | 31 | # Override the architecture used by stack, especially useful on Windows 32 | # arch: i386 33 | # arch: x86_64 34 | 35 | # Extra directories used by stack for building 36 | # extra-include-dirs: [/path/to/dir] 37 | # extra-lib-dirs: [/path/to/dir] 38 | 39 | # Allow a newer minor version of GHC than the snapshot specifies 40 | # compiler-check: newer-minor 41 | -------------------------------------------------------------------------------- /stack-8.6.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md 2 | # vim: nospell 3 | 4 | resolver: lts-13.20 5 | 6 | packages: 7 | - repa 8 | - repa-io 9 | - repa-algorithms 10 | - repa-examples 11 | 12 | # extra-deps: [] 13 | 14 | # Override default flag values for local packages and extra-deps 15 | # flags: {} 16 | 17 | # Extra global and per-package GHC options 18 | # ghc-options: {} 19 | 20 | # Extra package databases containing global packages 21 | # extra-package-dbs: [] 22 | 23 | # Control whether we use the GHC we find on the path 24 | # system-ghc: true 25 | 26 | # Require a specific version of stack, using version ranges 27 | # require-stack-version: -any # Default 28 | # require-stack-version: >= 0.1.4.0 29 | 30 | # Override the architecture used by stack, especially useful on Windows 31 | # arch: i386 32 | # arch: x86_64 33 | 34 | # Extra directories used by stack for building 35 | # extra-include-dirs: [/path/to/dir] 36 | # extra-lib-dirs: [/path/to/dir] 37 | 38 | --------------------------------------------------------------------------------