packages feed

j 0.2.1.1 → 0.2.2.0

raw patch · 3 files changed

+36/−5 lines, 3 filesdep +vectorPVP ok

version bump matches the API change (PVP)

Dependencies added: vector

API changes (from Hackage documentation)

+ Language.J: TypeError :: JErr
+ Language.J: UnsupportedType :: JErr
+ Language.J: copyIntVect :: Vector Int -> JData DIM1
+ Language.J: data JErr
+ Language.J: instance GHC.Exception.Type.Exception Language.J.JErr
+ Language.J: instance GHC.Show.Show Language.J.JErr
+ Language.J: tryIntVect :: JData DIM1 -> Vector Int

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # j +## 0.2.2.0++  * Add `tryIntVect` and `copyIntVect`+ ## 0.2.1.1    * Test suite works with J 9.02
j.cabal view
@@ -1,6 +1,6 @@ cabal-version:   1.18 name:            j-version:         0.2.1.1+version:         0.2.2.0 license:         BSD3 license-file:    LICENSE copyright:       Copyright: (c) 2020 Vanessa McHale@@ -27,7 +27,8 @@     build-depends:         base >=4.8 && <5,         bytestring >=0.10,-        repa >=3.2.5.0+        repa >=3.2.5.0,+        vector >=0.5      if !os(windows)         build-depends: unix >=2.7.0.0
src/Language/J.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP               #-}+{-# LANGUAGE DeriveAnyClass    #-} {-# LANGUAGE FlexibleContexts  #-} {-# LANGUAGE OverloadedStrings #-} @@ -91,6 +92,11 @@                   , JData (..)                   , getJData                   , setJData+                  -- * Exceptions+                  , JErr (..)+                  -- * Vector helpers+                  , tryIntVect+                  , copyIntVect                   -- * FFI                   , J                   , JDoType@@ -100,6 +106,7 @@                   ) where  import           Control.Applicative             (pure, (<$>), (<*>))+import           Control.Exception               (Exception, throw) import qualified Data.Array.Repa                 as R import qualified Data.Array.Repa.Repr.ForeignPtr as RF import qualified Data.ByteString                 as BS@@ -108,6 +115,7 @@ import           Data.Complex                    (Complex (..)) import           Data.Functor                    (void) import           Data.Semigroup                  ((<>))+import qualified Data.Vector.Unboxed             as V import           Foreign.C.String                (CString) import           Foreign.C.Types                 (CChar, CDouble, CInt (..), CLLong (..)) import           Foreign.ForeignPtr              (ForeignPtr, castForeignPtr, mallocForeignPtrBytes, withForeignPtr)@@ -237,7 +245,6 @@     JEnv jt <$> jeval <*> jread <*> jOut <*> jSet #endif - -- | Send some J code to the environment. bsDispatch :: JEnv -> BS.ByteString -> IO () bsDispatch (JEnv ctx jdo _ _ _) bs =@@ -250,6 +257,8 @@ bsOut (JEnv ctx _ _ jout _) = BS.packCString =<< jout ctx  -- | \( O(n) \) in the array size+--+-- Throws 'JErr' for unspported conversion types. getJData :: R.Shape sh          => JEnv -> BS.ByteString -- ^ Name of the value in question          -> IO (JData sh)@@ -286,6 +295,23 @@               | JBoolArr !(R.Array RF.F sh CChar)               | JString !BS.ByteString +data JErr = TypeError+          | UnsupportedType+          deriving (Show, Exception)++-- | Copy into a 'V.Vector' 'Int', if possible.+--+-- Throws a 'JErr' on type error.+--+-- \( O(n) \)+tryIntVect :: JData R.DIM1 -> V.Vector Int+tryIntVect (JIntArr arr) = R.toUnboxed (R.copyS $ R.map fromIntegral arr)+tryIntVect _             = throw TypeError++-- | \( O(n) \)+copyIntVect :: V.Vector Int -> JData R.DIM1+copyIntVect = JIntArr . R.copyS . R.map fromIntegral . (\v -> R.fromUnboxed (R.ix1 $ V.length v) v)+ -- | \( O(n) \) in the array size setJData :: (R.Shape sh) => JEnv -> BS.ByteString -- ^ Name                          -> JData sh -> IO CInt@@ -312,7 +338,7 @@ repaArr jty arr = do     let (rank', sh) = repaSize arr         sz = product sh-    let wid = 32 + (fromIntegral $ jTypeWidth jty) * (rank' + sz)+    let wid = 32 + fromIntegral (jTypeWidth jty) * (rank' + sz)     ptr <- mallocBytes (fromIntegral wid)     pokeByteOff ptr 0 (227 :: CLLong) -- I think this is because it's non-boxed     pokeByteOff ptr (sizeOf (undefined :: CLLong)) (jTypeToInt jty)@@ -357,7 +383,7 @@ intToJType 4  = JInteger intToJType 8  = JDouble intToJType 16 = JComplex-intToJType _  = error "Unsupported type!"+intToJType _  = throw UnsupportedType  jTypeToInt :: JType -> CLLong jTypeToInt JBool    = 1