fast-combinatorics 0.1.0.2 → 0.1.0.3
raw patch · 7 files changed
+129/−21 lines, 7 filesdep ~basedep ~composition-preludebuild-type:Customsetup-changed
Dependency ranges changed: base, composition-prelude
Files
- ATS2-Postiats-include-0.3.8/ccomp/runtime/pats_ccomp_config.h +49/−0
- README.md +3/−5
- Setup.hs +36/−2
- bench/Bench.hs +5/−5
- cbits/fast-combinatorics.c +1/−1
- fast-combinatorics.cabal +26/−8
- src/Numeric/Combinatorics.hs +9/−0
+ ATS2-Postiats-include-0.3.8/ccomp/runtime/pats_ccomp_config.h view
@@ -0,0 +1,49 @@+/* ******************************************************************* */+/* */+/* Applied Type System */+/* */+/* ******************************************************************* */++/*+** ATS/Postiats - Unleashing the Potential of Types!+** Copyright (C) 2011-20?? Hongwei Xi, ATS Trustful Software, Inc.+** All rights reserved+**+** ATS is free software; you can redistribute it and/or modify it under+** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the+** Free Software Foundation; either version 3, or (at your option) any+** later version.+** +** ATS is distributed in the hope that it will be useful, but WITHOUT ANY+** WARRANTY; without even the implied warranty of MERCHANTABILITY or+** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License+** for more details.+** +** You should have received a copy of the GNU General Public License+** along with ATS; see the file COPYING. If not, please write to the+** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA+** 02110-1301, USA.+*/++/* ****** ****** */++/*+(* Author: Hongwei Xi *)+(* Authoremail: hwxi AT cs DOT bu DOT edu *)+(* Start time: January, 2013 *)+*/++/* ****** ****** */++#ifndef PATS_CCOMP_CONFIG_H+#define PATS_CCOMP_CONFIG_H++/* ****** ****** */++// HX: it is yet empty++/* ****** ****** */++#endif /* PATS_CCOMP_CONFIG_H */++/* end of [pats_ccomp_config.h] */
README.md view
@@ -2,10 +2,8 @@ [](https://travis-ci.org/vmchale/fast-combinatorics) -This is a library for fast combinatorics using ATS. You may need to download the -relevant ATS libraries-[here](http://www.ats-lang.org/Downloads.html#Install_of_ATS2_include) if-linking fails.+This is a library for fast combinatorics using ATS. As such, make sure+a C compiler is installed. Build reports from Windows users are always welcome. Currently it is in-progress, being somewhat constrained by the fact that I have yet to figure out how to share arbitrary-precision types between ATS and Haskell.@@ -14,7 +12,7 @@ The Haskell library comes with the C bundled, however you may wish to build from source if you are hacking on the library. To that end, you can install-[stack](http://haskellstack.org/), [patscc](http://www.ats-lang.org/Downloads.html) , and+[stack](http://haskellstack.org/), [patscc](http://www.ats-lang.org/Downloads.html), and [pats-filter](https://github.com/Hibou57/PostiATS-Utilities) and build with ```bash
Setup.hs view
@@ -1,2 +1,36 @@-import Distribution.Simple-main = defaultMain+{-# LANGUAGE CPP #-}+{-# LANGUAGE OverloadedStrings #-}+++#if __GLASGOW_HASKELL__ <= 784+import Control.Applicative+#endif+import qualified Codec.Archive.Tar as Tar+import Codec.Compression.GZip (decompress)+import Distribution.Simple+import Distribution.Simple.Setup+import Distribution.Types.HookedBuildInfo+import Distribution.Types.PackageDescription+import Network.HTTP.Client hiding (decompress)+import Network.HTTP.Client.TLS (tlsManagerSettings)+import System.Directory++main = defaultMainWithHooks myHooks+ where myHooks = simpleUserHooks { preBuild = buildScript+ , postClean = cleanATS }++cleanATS :: Args -> CleanFlags -> PackageDescription -> () -> IO ()+cleanATS _ _ _ _ = removeDirectoryRecursive "ATS2-Postiats-include-0.3.8"++buildScript :: Args -> BuildFlags -> IO HookedBuildInfo+buildScript _ _ = do++ putStrLn "Fetching libraries..."+ manager <- newManager tlsManagerSettings+ initialRequest <- parseRequest "https://downloads.sourceforge.net/project/ats2-lang/ats2-lang/ats2-postiats-0.3.8/ATS2-Postiats-include-0.3.8.tgz"+ response <- responseBody <$> httpLbs (initialRequest { method = "GET" }) manager++ putStrLn "Unpacking libraries..."+ Tar.unpack "." . Tar.read . decompress $ response++ pure emptyHookedBuildInfo
bench/Bench.hs view
@@ -1,23 +1,23 @@ module Main where import Criterion.Main-import Numeric.Combinatorics-import qualified Math.Combinatorics.Binomial as Ext+import qualified Math.Combinatorics.Binomial as Ext import qualified Math.Combinatorics.Factorial as Ext+import Numeric.Combinatorics hsIsPrime :: Int -> Bool hsIsPrime x = null [ y | y <- [2..m], x `mod` y == 0]- where m = floor (sqrt (fromIntegral x))+ where m = floor (sqrt (fromIntegral x :: Float)) main :: IO () main = defaultMain [ bgroup "factorial" [ bench "factorial" $ nf factorial 12- , bench "Ext.factorial" $ nf factorial 12+ , bench "Ext.factorial" $ nf (Ext.factorial :: Int -> Int) 12 ] , bgroup "choose" [ bench "choose" $ nf (13 `choose`) 4- , bench "Ext.choose" $ nf (13 `choose`) 4+ , bench "Ext.choose" $ nf (Ext.choose 13 :: Int -> Int) 4 ] , bgroup "isPrime" [ bench "isPrime" $ nf isPrime 2017
cbits/fast-combinatorics.c view
@@ -1,7 +1,7 @@ /* ** ** The C code is generated by [ATS/Postiats-0-3-8]-** The starting compilation time is: 2017-12-30: 12h:55m+** The starting compilation time is: 2017-12-30: 17h:55m ** */
fast-combinatorics.cabal view
@@ -1,5 +1,5 @@ name: fast-combinatorics-version: 0.1.0.2+version: 0.1.0.3 synopsis: Fast combinatorics. description: Fast combinatorics code with a high level of safety guaranteed by writing it in ATS. homepage: https://github.com//fast-combinatorics#readme@@ -9,10 +9,11 @@ maintainer: vamchale@gmail.com copyright: Copyright: (c) 2017 Vanessa McHale category: Numerics-build-type: Simple+build-type: Custom extra-source-files: cbits/fast-combinatorics.c+ , ATS2-Postiats-include-0.3.8/ccomp/runtime/pats_ccomp_config.h extra-doc-files: README.md-cabal-version: >=1.18+cabal-version: >= 1.18 Flag development { Description: Enable `-Werror`@@ -20,16 +21,29 @@ default: False } +custom-setup+ setup-depends: base+ , Cabal >= 2.0+ , http-client+ , http-client-tls+ , tar+ , zlib+ , directory+ library c-sources: cbits/fast-combinatorics.c+ include-dirs: ATS2-Postiats-include-0.3.8/ccomp/runtime/+ , ATS2-Postiats-include-0.3.8/ hs-source-dirs: src exposed-modules: Numeric.Combinatorics- build-depends: base >= 4.7 && < 5- , composition-prelude+ build-depends: base >= 4.6 && < 5+ , composition-prelude >= 0.1.1.3 default-language: Haskell2010 if flag(development) ghc-options: -Werror- ghc-options: -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat -optc-mtune=native -optc-flto -optc-O3+ if impl(ghc >= 8.0)+ ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat + ghc-options: -Wall -optc-mtune=native -optc-flto -optc-O3 test-suite fast-combinatorics-test type: exitcode-stdio-1.0@@ -42,7 +56,9 @@ , arithmoi if flag(development) ghc-options: -Werror- ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat+ if impl(ghc >= 8.0)+ ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall default-language: Haskell2010 benchmark fast-combinatorics-bench@@ -55,7 +71,9 @@ , combinatorics if flag(development) ghc-options: -Werror- ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat -optc-mtune=native -optc-flto -optc-O3+ if impl(ghc >= 8.0)+ ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat + ghc-options: -Wall -optc-mtune=native -optc-flto -optc-O3 default-language: Haskell2010 source-repository head
src/Numeric/Combinatorics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE ForeignFunctionInterface #-} module Numeric.Combinatorics@@ -14,9 +15,17 @@ foreign import ccall unsafe factorial_ats :: CInt -> CInt foreign import ccall unsafe choose_ats :: CInt -> CInt -> CInt foreign import ccall unsafe double_factorial :: CInt -> CInt+#if __GLASGOW_HASKELL__ >= 820 foreign import ccall unsafe is_prime_ats :: CInt -> CBool+#else+foreign import ccall unsafe is_prime_ats :: CInt -> CUChar+#endif +#if __GLASGOW_HASKELL__ >= 820 convertBool :: CBool -> Bool+#else+convertBool :: CUChar -> Bool+#endif convertBool = go . fromIntegral where go :: Word8 -> Bool