casadi-bindings 2.2.0.7 → 2.2.0.8
raw patch · 3 files changed
+39/−14 lines, 3 filesdep +binarydep +vector-binary-instances
Dependencies added: binary, vector-binary-instances
Files
- casadi-bindings.cabal +3/−1
- src/Casadi/DMatrix.hs +20/−9
- src/Casadi/Sparsity.hs +16/−4
casadi-bindings.cabal view
@@ -1,5 +1,5 @@ name: casadi-bindings-version: 2.2.0.7+version: 2.2.0.8 synopsis: mid-level bindings to CasADi category: Numerical, Math description:@@ -59,6 +59,8 @@ vector, containers, cereal,+ binary,+ vector-binary-instances, casadi-bindings-internal == 0.1.2.1, casadi-bindings-core == 2.2.0.2 default-language: Haskell2010
src/Casadi/DMatrix.hs view
@@ -9,7 +9,9 @@ import qualified Data.Vector as V import System.IO.Unsafe ( unsafePerformIO ) import Linear.Conjugate ( Conjugate(..) )-import Data.Serialize ( Serialize(..) )+import qualified Data.Serialize as S+import qualified Data.Binary as B+import Data.Vector.Binary () -- instances import Casadi.Core.Classes.DMatrix import Casadi.Core.Classes.Sparsity ( Sparsity )@@ -18,14 +20,23 @@ import Casadi.Overloading ( Fmod(..), ArcTan2(..), SymOrd(..), Erf(..) ) import Casadi.CMatrix ( CMatrix(..) ) -instance Serialize DMatrix where- get = do- sp <- get- data' <- get- return (fromSparseData sp (V.fromList data'))- put x = do- put (sparsity x)- put (V.toList (ddata x))+getWith :: Monad m => m Sparsity -> m (V.Vector Double) -> m DMatrix+getWith get getVector = do+ sp <- get+ data' <- getVector+ return (fromSparseData sp data')+putWith :: Monad m => (Sparsity -> m ()) -> (V.Vector Double -> m ()) -> DMatrix -> m ()+putWith put putVector x = do+ put (sparsity x)+ putVector (ddata x)++-- Data.Vector.Cereal looks deprecated, it's not in master anymore+instance S.Serialize DMatrix where+ put = putWith S.put (S.put . V.toList)+ get = getWith S.get (fmap V.fromList S.get)+instance B.Binary DMatrix where+ put = putWith B.put B.put+ get = getWith B.get B.get instance Conjugate DMatrix where conjugate = id
src/Casadi/Sparsity.hs view
@@ -10,15 +10,27 @@ import qualified Data.Vector as V import System.IO.Unsafe ( unsafePerformIO )-import Data.Serialize ( Serialize(..) )+import qualified Data.Serialize as S+import qualified Data.Binary as B+import Data.Vector.Binary () -- instances import Casadi.Core.Classes.Sparsity import Casadi.SharedObject ( castSharedObject ) -instance Serialize Sparsity where- put = put . V.toList . compress- get = fmap (compressed . V.fromList) get+putWith :: (V.Vector Int -> m ()) -> Sparsity -> m ()+putWith putVector = putVector . compress++getWith :: Functor f => f (V.Vector Int) -> f Sparsity+getWith getVector = fmap compressed getVector++-- Data.Vector.Cereal looks deprecated, it's not in master anymore+instance S.Serialize Sparsity where+ put = putWith (S.put . V.toList)+ get = getWith (fmap V.fromList S.get)+instance B.Binary Sparsity where+ put = putWith B.put+ get = getWith B.get instance Show Sparsity where show x = show (castSharedObject x)