-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | J in Haskell
--
-- Haskell library for calling J
@package j
@version 0.1.0.0
-- | Marshal a limited subset of J arrays into Repa arrays.
--
--
Tutorial
--
-- Suppose we wish to perform linear regression. In J we could do:
--
--
-- xs := 1 2 3
-- ys := 2 4 6
--
-- reg_result =: ys %. xs ^/ i.2
--
--
-- To do this with Haskell data:
--
--
-- do
-- jenv <- jinit libLinux
--
-- let hsArr0 = R.fromListUnboxed (R.ix1 3) [1.0,2.0,3.0]
-- hsArr1 = R.fromListUnboxed (R.ix1 3) [2.0,4.0,6.0]
-- jArr0 = JDoubleArr $ R.copyS $ R.map (realToFrac :: Double -> CDouble) hsArr0
-- jArr1 = JDoubleArr $ R.copyS $ R.map (realToFrac :: Double -> CDouble) hsArr1
--
-- setJData jenv "xs" jArr0
-- setJData jenv "ys" jArr1
--
-- bsDispatch jenv "reg_result =: ys %. xs ^/ i.2"
--
-- JDoubleArr res <- getJData jenv "reg_result"
-- R.toList res
--
--
-- There are three steps to do the calculation, plus one to get a J
-- environment.
--
--
-- - Use jinit with the appropriate file path for your
-- platform
-- - Marshal Haskell values and send them to the J environment. To do
-- so, we use setJData, which takes a JData containing a
-- repa array or a string.
-- - Perform calculations within the J environment. Here, we use
-- bsDispatch to compute some results and assign them within
-- J
-- - Marshal J values back to Haskell. We use getJData
-- again.
--
--
-- Since marshaling data between J and Haskell is expensive, it's best to
-- do as much computation as possible in J.
--
-- FFI
--
-- If you want to marshal data yourself, say to use a Vector,
-- look at JEnv.
module Language.J
data JEnv
JEnv :: Ptr J -> JDoType -> JGetMType -> JGetRType -> JSetAType -> JEnv
[context] :: JEnv -> Ptr J
[evaluator] :: JEnv -> JDoType
[reader] :: JEnv -> JGetMType
[out] :: JEnv -> JGetRType
[setter] :: JEnv -> JSetAType
-- | Get a J environment
--
-- Passing the resultant JEnv between threads can cause unexpected
-- bugs.
jinit :: RawFilePath -> IO JEnv
-- | Expected RawFilePath to the library on a Linux machine.
libLinux :: RawFilePath
-- | Expected RawFilePath to the library on Mac.
libMac :: JVersion -> RawFilePath
-- | Send some J code to the environment.
bsDispatch :: JEnv -> ByteString -> IO ()
-- | Read last output
--
-- For debugging
bsOut :: JEnv -> IO ByteString
type JVersion = [Int]
-- | J data backed by repa array
data JData sh
JIntArr :: !Array F sh CInt -> JData sh
JDoubleArr :: !Array F sh CDouble -> JData sh
JBoolArr :: !Array F sh CChar -> JData sh
JString :: !ByteString -> JData sh
-- | <math> in the array size
getJData :: Shape sh => JEnv -> ByteString -> IO (JData sh)
-- | <math> in the array size
setJData :: Shape sh => JEnv -> ByteString -> JData sh -> IO CInt
-- | Abstract context
data J
type JDoType = Ptr J -> CString -> IO CInt
type JGetMType = Ptr J -> CString -> Ptr CLLong -> Ptr CLLong -> Ptr (Ptr CLLong) -> Ptr (Ptr CChar) -> IO CInt
type JGetRType = Ptr J -> IO CString
type JSetAType = Ptr J -> CLLong -> CString -> CLLong -> Ptr () -> IO CInt