Skip to content

Commit 43aefa4

Browse files
dmjiochessai
authored andcommitted
Add .travis.yml
- use haskell-ci - download arrayfire installer and unpack to /opt/arrayfire/ - remove Ord tests from test suite - use shouldBeEps for comparing Array Double
1 parent c4e4aca commit 43aefa4

File tree

5 files changed

+188
-23
lines changed

5 files changed

+188
-23
lines changed

Diff for: .travis.yml

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# This Travis job script has been generated by a script via
2+
#
3+
# haskell-ci 'travis' 'arrayfire.cabal'
4+
#
5+
# For more information, see https://github.com/haskell-CI/haskell-ci
6+
#
7+
# version: 0.3.20190814
8+
#
9+
language: c
10+
dist: xenial
11+
sudo: required
12+
git:
13+
# whether to recursively clone submodules
14+
submodules: false
15+
cache:
16+
directories:
17+
- $HOME/.cabal/packages
18+
- $HOME/.cabal/store
19+
before_cache:
20+
- rm -fv $CABALHOME/packages/hackage.haskell.org/build-reports.log
21+
# remove files that are regenerated by 'cabal update'
22+
- rm -fv $CABALHOME/packages/hackage.haskell.org/00-index.*
23+
- rm -fv $CABALHOME/packages/hackage.haskell.org/*.json
24+
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.cache
25+
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar
26+
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar.idx
27+
- rm -rfv $CABALHOME/packages/head.hackage
28+
matrix:
29+
include:
30+
- compiler: ghc-8.8.1
31+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.8.1","cabal-install-3.0"]}}
32+
- compiler: ghc-8.6.5
33+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.6.5","cabal-install-2.4"]}}
34+
- compiler: ghc-8.4.4
35+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.4","cabal-install-2.4"]}}
36+
before_install:
37+
- HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')
38+
- WITHCOMPILER="-w $HC"
39+
- HCPKG="$HC-pkg"
40+
- unset CC
41+
- CABAL=/opt/ghc/bin/cabal
42+
- CABALHOME=$HOME/.cabal
43+
- export PATH="$CABALHOME/bin:$PATH"
44+
- export LD_LIBRARY_PATH="/opt/arrayfire/lib64:$LD_LIBRARY_PATH"
45+
- TOP=$(pwd)
46+
- "HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')"
47+
- echo $HCNUMVER
48+
- CABAL="$CABAL -vnormal+nowrap+markoutput"
49+
- set -o pipefail
50+
- |
51+
echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }' >> .colorful.awk
52+
echo 'BEGIN { state = "output"; }' >> .colorful.awk
53+
echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }' >> .colorful.awk
54+
echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }' >> .colorful.awk
55+
echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk
56+
echo ' if (state == "cabal") {' >> .colorful.awk
57+
echo ' print blue($0)' >> .colorful.awk
58+
echo ' } else {' >> .colorful.awk
59+
echo ' print $0' >> .colorful.awk
60+
echo ' }' >> .colorful.awk
61+
echo '}' >> .colorful.awk
62+
- cat .colorful.awk
63+
- |
64+
color_cabal_output () {
65+
awk -f $TOP/.colorful.awk
66+
}
67+
- echo text | color_cabal_output
68+
install:
69+
- echo "Downloading ArrayFire-3.6.4"
70+
- curl -O http://arrayfire.s3.amazonaws.com/3.6.4/ArrayFire-v3.6.4_Linux_x86_64.sh
71+
- chmod +x ArrayFire-v3.6.4_Linux_x86_64.sh
72+
- ./ArrayFire-v3.6.4_Linux_x86_64.sh --include-subdir --prefix=/opt
73+
- ls -lah /opt/arrayfire/
74+
- ${CABAL} --version
75+
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
76+
- TEST=--enable-tests
77+
- BENCH=--enable-benchmarks
78+
- HEADHACKAGE=false
79+
- rm -f $CABALHOME/config
80+
- |
81+
echo "verbose: normal +nowrap +markoutput" >> $CABALHOME/config
82+
echo "remote-build-reporting: anonymous" >> $CABALHOME/config
83+
echo "write-ghc-environment-files: always" >> $CABALHOME/config
84+
echo "remote-repo-cache: $CABALHOME/packages" >> $CABALHOME/config
85+
echo "logs-dir: $CABALHOME/logs" >> $CABALHOME/config
86+
echo "world-file: $CABALHOME/world" >> $CABALHOME/config
87+
echo "extra-prog-path: $CABALHOME/bin" >> $CABALHOME/config
88+
echo "symlink-bindir: $CABALHOME/bin" >> $CABALHOME/config
89+
echo "installdir: $CABALHOME/bin" >> $CABALHOME/config
90+
echo "build-summary: $CABALHOME/logs/build.log" >> $CABALHOME/config
91+
echo "store-dir: $CABALHOME/store" >> $CABALHOME/config
92+
echo "install-dirs user" >> $CABALHOME/config
93+
echo " prefix: $CABALHOME" >> $CABALHOME/config
94+
echo "repository hackage.haskell.org" >> $CABALHOME/config
95+
echo " url: http://hackage.haskell.org/" >> $CABALHOME/config
96+
- cat $CABALHOME/config
97+
- rm -fv cabal.project cabal.project.local cabal.project.freeze
98+
- travis_retry ${CABAL} v2-update -v
99+
# Generate cabal.project
100+
- rm -rf cabal.project cabal.project.local cabal.project.freeze
101+
- touch cabal.project
102+
- |
103+
echo "packages: ." >> cabal.project
104+
- |
105+
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(arrayfire)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
106+
- cat cabal.project || true
107+
- cat cabal.project.local || true
108+
- ${CABAL} install $WITHCOMPILER hspec-discover | color_cabal_output # needed on $PATH for tests
109+
- if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi
110+
- ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} | color_cabal_output
111+
- "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
112+
- rm cabal.project.freeze
113+
- ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} --dep -j2 all | color_cabal_output
114+
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks --dep -j2 all | color_cabal_output
115+
script:
116+
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
117+
# Packaging...
118+
- ${CABAL} v2-sdist all | color_cabal_output
119+
# Unpacking...
120+
- mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/
121+
- cd ${DISTDIR} || false
122+
- find . -maxdepth 1 -type f -name '*.tar.gz' -exec tar -xvf '{}' \;
123+
- find . -maxdepth 1 -type f -name '*.tar.gz' -exec rm '{}' \;
124+
- PKGDIR_arrayfire="$(find . -maxdepth 1 -type d -regex '.*/arrayfire-[0-9.]*')"
125+
# Generate cabal.project
126+
- rm -rf cabal.project cabal.project.local cabal.project.freeze
127+
- touch cabal.project
128+
- |
129+
echo "packages: ${PKGDIR_arrayfire}" >> cabal.project
130+
- |
131+
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(arrayfire)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
132+
- cat cabal.project || true
133+
- cat cabal.project.local || true
134+
# Building...
135+
# this builds all libraries and executables (without tests/benchmarks)
136+
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output
137+
# Building with tests and benchmarks...
138+
# build & run tests, build benchmarks
139+
- ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
140+
# Testing...
141+
- ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
142+
# cabal check...
143+
- (cd ${PKGDIR_arrayfire} && ${CABAL} -vnormal check)
144+
# haddock...
145+
- ${CABAL} v2-haddock $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
146+
# Building without installed constraints for packages in global-db...
147+
- rm -f cabal.project.local
148+
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output
149+
150+
# REGENDATA ["travis","arrayfire.cabal"]
151+
# EOF

Diff for: Setup.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Main where
22

3-
import Distribution.Extra.Doctest (defaultMainWithDoctests)
3+
import Distribution.Simple
44

55
main :: IO ()
6-
main = defaultMainWithDoctests "doctests"
6+
main = defaultMain

Diff for: arrayfire.cabal

+3-9
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,20 @@ author: David Johnson
88
maintainer: [email protected]
99
copyright: David Johnson (c) 2018-2020
1010
category: Math
11-
build-type: Custom
11+
build-type: Simple
1212
extra-source-files: CHANGELOG.md
1313
cabal-version: >=1.10
1414
description: High-level Haskell bindings to the ArrayFire General-purpose GPU library
1515
.
1616
<<https://user-images.githubusercontent.com/875324/59819388-9ff83f00-92f5-11e9-9ac0-51eef200c716.png>>
1717
.
18+
tested-with: GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1
1819

1920
flag disable-default-paths
2021
description: When enabled, don't add default hardcoded include/link dirs by default. Needed for hermetic builds like in nix.
2122
default: False
2223
manual: True
2324

24-
custom-setup
25-
setup-depends:
26-
base <5,
27-
Cabal,
28-
cabal-doctest >=1 && <1.1
29-
3025
library
3126
exposed-modules:
3227
ArrayFire
@@ -94,9 +89,8 @@ library
9489
include-dirs:
9590
/opt/arrayfire/include
9691
extra-lib-dirs:
92+
/opt/arrayfire/lib64
9793
/opt/arrayfire/lib
98-
ld-options:
99-
-Wl,-rpath /opt/arrayfire/lib
10094

10195
executable main
10296
hs-source-dirs:

Diff for: shell.nix

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ in
1616
'cabal v1-configure --enable-tests && \
1717
cabal v1-build test && dist/build/test/test'
1818
}
19+
function test () {
20+
cabal v1-configure --enable-tests && \
21+
cabal v1-build test && dist/build/test/test
22+
}
1923
function doctest-runner () {
2024
${pkgs.ag}/bin/ag -l | \
2125
${pkgs.entr}/bin/entr sh -c \

Diff for: test/ArrayFire/ArithSpec.hs

+28-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Prelude hiding (sqrt, div, and, or, not, isNaN)
66
import Test.Hspec
77
import Foreign.C
88

9+
import qualified ArrayFire as A
10+
import qualified System.Exit as E
11+
912
spec :: Spec
1013
spec =
1114
describe "Arith tests" $ do
@@ -20,25 +23,21 @@ spec =
2023
it "Should subtract two scalar arrays" $ do
2124
scalar @Int 4 - 2 `shouldBe` 2
2225
it "Should multiply two scalar arrays" $ do
23-
scalar @Double 4 `mul` 2 `shouldBe` 8
26+
scalar @Double 4 `mul` 2 `shouldBeEps` 8
2427
it "Should divide two scalar arrays" $ do
25-
div @Double 8 2 `shouldBe` 4
28+
div @Double 8 2 `shouldBeEps` 4
2629
it "Should add two matrices" $ do
2730
matrix @Int (2,2) [[1,1],[1,1]] + matrix @Int (2,2) [[1,1],[1,1]]
2831
`shouldBe`
2932
matrix @Int (2,2) [[2,2],[2,2]]
3033
it "Should take cubed root" $ do
31-
3 `shouldBe` cbrt @Double 27
34+
3 `shouldBeEps` cbrt @Double 27
3235
it "Should take square root" $ do
33-
2 `shouldBe` sqrt @Double 4
34-
it "Should lt Array" $ do
35-
2 < (3 :: Array Double) `shouldBe` True
36-
it "Should lte Array" $ do
37-
2 <= (3 :: Array Double) `shouldBe` True
38-
it "Should gte Array" $ do
39-
2 >= (3 :: Array Double) `shouldBe` False
40-
it "Should gt Array" $ do
41-
2 > (3 :: Array Double) `shouldBe` False
36+
2 `shouldBeEps` sqrt @Double 4
37+
--it "Should lt Array" $ do
38+
-- 2 `A.lt` (3 :: Array Double) `shouldBe` 1
39+
--it "Should gt Array" $ do
40+
-- 2 `A.gt` (3 :: Array Double) `shouldBe` 1
4241
it "Should eq Array" $ do
4342
3 == (3 :: Array Double) `shouldBe` True
4443
it "Should and Array" $ do
@@ -94,3 +93,20 @@ spec =
9493
isZero (scalar @Double (acos 2)) `shouldBe` scalar @Double 0
9594
isZero (scalar @Double 0) `shouldBe` scalar @Double 1
9695
isZero (scalar @Double 1) `shouldBe` scalar @Double 0
96+
97+
shouldBeEps :: Array Double -> Array Double -> Expectation
98+
actual `shouldBeEps` expected = expect err_msg (cmpEps actual expected)
99+
where
100+
err_msg = "expected: " ++ show expected ++ "\n but got: " ++ show actual
101+
cmpEps :: Array Double -> Array Double -> Bool
102+
cmpEps a b =
103+
let x :: Double
104+
x = getScalar $ Prelude.abs $ a - b
105+
in x <= 1e-14
106+
107+
expect :: String -> Bool -> Expectation
108+
expect label f = if f
109+
then pure ()
110+
else do
111+
putStrLn label
112+
E.exitFailure

0 commit comments

Comments
 (0)