Giter Club home page Giter Club logo

arrayfire-haskell's Introduction

ArrayFire is a general-purpose library that simplifies the process of developing software that targets parallel and massively-parallel architectures including CPUs, GPUs, and other hardware acceleration devices.

arrayfire-haskell is a Haskell binding to ArrayFire.

Table of Contents

Installation

Install ArrayFire via the download page.

ArrayFire can also be fetched from nixpkgs master.

Haskell Installation

arrayfire can be installed w/ cabal, stack or nix.

cabal install arrayfire
stack install arrayfire

Also note, if you plan on using ArrayFire's visualization features, you must install fontconfig and glfw on OSX or Linux.

Documentation

Hacking

To hack on this library locally, complete the installation step above. We recommend installing the nix package manager to facilitate development.

After the above tools are installed, clone the source from Github.

git clone [email protected]:arrayfire/arrayfire-haskell.git
cd arrayfire-haskell

To build and run all tests in response to file changes

nix-shell --run test-runner

To perform interactive development w/ ghcid

nix-shell --run ghcid

To interactively evaluate code in the repl

nix-shell --run repl

To produce the haddocks and open them in a browser

nix-shell --run docs

Example

{-# LANGUAGE TypeApplications, ScopedTypeVariables #-}
module Main where

import qualified ArrayFire as A
import           Control.Exception (catch)

main :: IO ()
main = print newArray `catch` (\(e :: A.AFException) -> print e)
  where
    newArray = A.matrix @Double (2,2) [ [1..], [1..] ] * A.matrix @Double (2,2) [ [2..], [2..] ]

{-|

ArrayFire Array
[2 2 1 1]
    2.0000     6.0000
    2.0000     6.0000

-}

arrayfire-haskell's People

Contributors

danielkroeni avatar dmjio avatar leftaroundabout avatar twesterhout avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arrayfire-haskell's Issues

Missing dependency on a foreign library

I have installed arrayfire 3.6.4 from https://arrayfire.com/download/ to /opt/arrayfire as described on http://arrayfire.org/docs/installing.htm#Linux.

Running cabal install arrayfire yields the following error message:

Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
 - arrayfire-0.1.0.0 (lib:arrayfire, exe:gen, exe:main) (requires build)
Starting     arrayfire-0.1.0.0 (all, legacy fallback)

Failed to build arrayfire-0.1.0.0. The failure occurred during the configure
step.
Build log (
/home/jaro/.cabal/logs/ghc-8.8.1/arrayfire-0.1.0.0-5e7527530ca25ab12a051fd4d0f7055fae7a4dba9f99268656d18fb873a6c8ce.log
):
[1 of 1] Compiling Main             ( /tmp/cabal-install.-22655/dist-newstyle/tmp/src-22655/arrayfire-0.1.0.0/dist/setup/setup.hs, /tmp/cabal-install.-22655/dist-newstyle/tmp/src-22655/arrayfire-0.1.0.0/dist/setup/Main.o )
Linking /tmp/cabal-install.-22655/dist-newstyle/tmp/src-22655/arrayfire-0.1.0.0/dist/setup/setup ...
Configuring arrayfire-0.1.0.0...
setup: Missing dependency on a foreign library:
* Missing (or bad) C library: af
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

cabal: Failed to build arrayfire-0.1.0.0. See the build log above for details.

How to use drawImage?

Your documentation contains an example:

>>> drawImage window ('constant' \@'Int' 1) ('Cell' 10 10 "test" 'ColorMapSpectrum')

I adapted it to:

main = do
  w <- createWindow 512 512 "Test"
  drawImage w (constant @Int [512,512] 1) (Cell 10 10 "test" ColorMapSpectrum)

That gives the error:

AFException {afExceptionType = TypeError, afExceptionCode = 204, afExceptionMsg = "Function does not support this data type"}

Get doctests working

@chessai this would be a /very/ nice to have. Issue is that doctest can't resolve arrayfire third-party dep. when it runs.

Show instance transposed?

It looks like your Show instance for Array is transposed:

λ> A.lower (A.matrix (2,2) [[1,2],[3,4]]) False
ArrayFire Array
[2 2 1 1]
    1.0000     2.0000 
    0.0000     4.0000 

λ> A.upper (A.matrix (2,2) [[1,2],[3,4]]) False
ArrayFire Array
[2 2 1 1]
    1.0000     0.0000 
    3.0000     4.0000 

Another example: exceptions thrown by matmul suggest that the dimensions are (rows,columns):

λ> A.matmul (A.constant [2,3] 5) (A.constant [1,2] 2) A.None A.None
*** Exception: AFException {afExceptionType = SizeError, afExceptionCode = 203, afExceptionMsg = "Invalid input size"}
λ> A.matmul (A.constant [2,3] 5) (A.constant [3,1] 2) A.None A.None
ArrayFire Array
[2 1 1 1]
   30.0000    30.0000 

but the Show instance suggests the opposite:

λ> (A.constant [2,3] 5)
ArrayFire Array
[2 3 1 1]
    5.0000     5.0000 
    5.0000     5.0000 
    5.0000     5.0000 

Outstanding items before release

  • randn, randu, etc. should use a list for dimensions
  • Tests for file IO, reading / writing matrices
  • Add more tests
  • Add links to array fire things
  • AFConvMode, etc. needs to be wrapped
  • Features API needs to be fixed
  • AFConvMode, double check to/from is correct.
  • Constrain Util functions by AFType
  • Add a Bits instance?
  • Doctest on Darwin doesn't work since it forgets about being linked against arrayfire (cannot find .so errors abound)

Shields

Would be nice to have hackage version, build status, etc.

Smart constructors are transposed

This was mentioned in #22, but I'll make an Issue for it here. The data provided to the smart constructors matrix, cube, and tensor is validated (in terms of row and column sizes) in row-major order, but the constructors all flatten the input lists and use mkArray, which enters the data in the column-major order. This leads to, first, properly arranged rows and columns being invalid:

λ> A.matrix (3,2) [[1,2,3],[4,5,6]]
*** Exception: AFException {afExceptionType = SizeError, afExceptionCode = 203, afExceptionMsg = "Invalid elements provided. Expected 6 elements received 4"}

and, second, if the input lists are transposed so they validate OK, the data in the Array doesn't even follow the rows and columns provided:

λ> A.matrix (3,2) [[1,2],[3,4],[5,6]]
ArrayFire Array
[3 2 1 1]
    1.0000     4.0000 
    2.0000     5.0000 
    3.0000     6.0000 

Remove unimplemented internal functions.

Running cabal test fails because the linker can't find these functions:

In Image.hsc:

  • af_iterative_deconv
  • af_iverse_deconv

In LAPACK.hsc:

  • af_pinverse

In Signal.hsc:

  • af_approx1_uniform
  • af_approx2_uniform

Should these functions be removed?

Document linking Haskell wrapper when building from source

Currently the installation instructions for arrayfire-haskell target users who install binaries into /lib / lib64 on OSX/ Linux respectively. For "power users" (those who build from source), there should be instructions on how to install.

cabal configure -f-disable-default-paths --extra-lib-dirs=/path/to/arrayfire/lib --extra-include-dirs=/path/to/arrayfire/include

How does transfer an image array to such array?

Thanks for your excellent work!
I'm very interesting in this library. But I want to know how to interacting with other library. For example , When I read an image with JuicyPixels, how to transfer this data to arrayfire.

I often use accelerate library, and it has many auxiliary libraries.

Thanks again.

Windows not a supported platform? Installation errors

Error: setup.exe: Missing dependency on a foreign library:

  • Missing (or bad) C library: af
    This problem can usually be solved by installing the system package that
    provides this library (you may need the "-dev" version). If the library is
    already installed but in a non-standard location then you can use the flags
    --extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
    library file does exist, it may contain errors that are caught by the C
    compiler at the preprocessing stage. In this case you can re-run configure
    with the verbosity flag -v3 to see the error messages.

After cabal install.

Is this an issue with path configuration in Windows? Can I work around this with mingw? The problem with mingw, though, is that my CUDA drivers are on Windows.

Investigate Bits instance on Array CBool

Theoretically, there's no reason this can't be supported.

instance Bits (ArrayFire CBool) where
  (.&.) = A.and
  (.|.) = A.or
  xor = A.bitXor
  shiftL x n = A.shiftL x (scalar n)
  shiftR x n = A.shiftR x (scalar n)

Still need to look into implementing the following:

(rotate | rotateL, rotateR), bitSize, bitSizeMaybe, isSigned, testBit, bit, popCount

ArrayFire benchmarks

Would be very nice to have comparisons of ArrayFire vs. libraries like hmatrix, accelerate, etc. This might even warrant its own package due to the difficulty in procuring all the dependencies.

Getting a failure on these tests that is very strange

it "Should take cubed root" $ do
3 `shouldBe` cbrt @Double 27
it "Should take square root" $ do
2 `shouldBe` sqrt @Double 4

I am not sure this is entirely helpful, feel free to close. I would like to use arrayfire for a project I am starting. It is included in my nix setup via https://github.com/chiroptical/homing-pigeon/blob/main/default.nix.

However, I am getting errors from these tests after setting my LD_LIBRARY_PATH appropriately. Here is the output from the test,

  test/ArrayFire/ArithSpec.hs:31:7: 
  1) ArrayFire.Arith, Arith tests, Should take cubed root
       expected: ArrayFire Array
                 [1 1 1 1]
                     3.0000 
                 
        but got: ArrayFire Array
                 [1 1 1 1]
                     3.0000 

I am wondering if it is comparing the pointers and not doing an element-wise comparison? AFAICT, I tried some C++ code and arrayA == arrayB seems to generate an element-wise comparison but I am unsure how equals is handled in Haskell-land.

Most reductions in ArrayFire.Algorithms should return array, not scalar

The functions which take a dimension to reduce along should return a full matrix, with only that dimension flattened, rather than a single scalar. These are (at least) sum, sumNaN, product, productNaN, min, max, allTrue, anyTrue, and count. The correct array is being computed by the FFI, but the getScalar function is being applied and just extracts the first element, rather than returning the entire array. The current behaviour of (for instance) sum is

λ> A.mkArray @Int [2,3] [1..]
ArrayFire Array
[2 3 1 1]
         1          3          5 
         2          4          6 
λ> A.sum it 0
3
λ> A.sum it 1
9

as opposed to the expected output,

ArrayFire Array
[1 3 1 1]
         3          7         11 

and

ArrayFire Array
[2 1 1 1]
         9 
        12 

Strong types for logical operators

For example lt, gt, le, ge, eq, neq should have type AFType a => Array a -> Array a -> Array CBool.

And functions like and, or should have type Array CBool -> Array CBool -> Array CBool.

And not should have type Array CBool -> Array CBool.

By the way why is Bool not an instance of AFType? Would it be possible to write an instance that uses CBool under the hood?

Three major releases in 24 hours.

Please, sleep over the releases. No need to spam Hackage.

(edit: only three are in rapid succession, the first one is already two days ago...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.