File tree Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -128,7 +128,8 @@ foreign import ccall unsafe mxDestroyArray :: MXArrayPtr -> IO ()
128
128
freeMXArray :: MXArray a -> MIO ()
129
129
freeMXArray a = withMXArray a mxDestroyArray
130
130
131
- -- | Create and populate an MXArray in one go.
131
+ -- | Create and populate an MXArray in one go. Named without 'mx' due to possible
132
+ -- | conformity to a typeclass function.
132
133
fromListIO :: (Foldable t , MXArrayComponent a ) => t a -> MIO (MXArray a )
133
134
fromListIO xs = do
134
135
arr <- createMXArray [length xs]
@@ -138,7 +139,8 @@ fromListIO xs = do
138
139
xsList = toList xs
139
140
140
141
-- | Like fromListIO but wraps elements in a cell. Most useful for converting a list of strings
141
- -- | to a MATLAB cell array of strings.
142
+ -- | to a MATLAB cell array of strings. Named in conjunction with `fromListIO`, which is used
143
+ -- | as part of the implementation.
142
144
cellFromListsIO :: (Traversable s , Foldable t , MXArrayComponent a ) => s (t a ) -> MIO (MXArray MCell )
143
145
cellFromListsIO xss = do
144
146
listOfStructArrays <- sequence $ fromListIO <$> xss
Original file line number Diff line number Diff line change @@ -11,11 +11,15 @@ module Foreign.Matlab.Engine.Wrappers (
11
11
, getArrayFromByteStream
12
12
, getByteStreamFromArray
13
13
, MEither (.. ), isMLeft , isMRight
14
+ , VarArgIn , mxVarArgs
14
15
) where
15
16
16
- import Foreign.Matlab
17
- import Foreign.Matlab.Engine
18
- import Path
17
+ import qualified Data.Map.Strict as DM
18
+ import Foreign.Matlab
19
+ import Foreign.Matlab.Engine
20
+ import Path
21
+
22
+ type VarArgIn = DM. Map String MAnyArray
19
23
20
24
-- | We require an absolute path in this case
21
25
addpath :: Engine -> Path Abs Dir -> IO ()
@@ -55,3 +59,10 @@ isMRight :: MEither -> IO Bool
55
59
isMRight me = do
56
60
sFields <- mStructFields $ unMXEither me
57
61
pure $ " right" `elem` sFields
62
+
63
+ -- | Utility function to create an eval-able list of arguments for a vararg map.
64
+ mxVarArgs :: VarArgIn -> [EngineEvalArg MAny ]
65
+ mxVarArgs varargin = DM. toList varargin >>= kvToArg
66
+ where
67
+ kvToArg :: (String , MAnyArray ) -> [EngineEvalArg MAny ]
68
+ kvToArg kv = [EvalStr $ fst kv, EvalArray $ snd kv]
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ module Foreign.Matlab.Types (
35
35
36
36
-- * Opaque types
37
37
MXArray ,
38
- MAnyArray ,
38
+ MAny , MAnyArray ,
39
39
MCell (MCell ), mCell ,
40
40
MStruct ,
41
41
MFun
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ library
68
68
69
69
if flag(engine)
70
70
Exposed-modules : Foreign.Matlab.Engine
71
+ Build-depends : containers
71
72
extra-libraries : eng
72
73
73
74
Source-repository head
You can’t perform that action at this time.
0 commit comments