summaryrefslogtreecommitdiff
path: root/packages/base/src
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-06-05 16:50:43 +0200
committerAlberto Ruiz <aruiz@um.es>2015-06-05 16:50:43 +0200
commit83f3371700441e50927f24a19e28164cc5194f03 (patch)
tree2c24b393c63db0750732b24e9d89433c6f87a3ea /packages/base/src
parent45ccf2b25783c656b5ecd48027d8f3a3f2dea001 (diff)
move vectorized
Diffstat (limited to 'packages/base/src')
-rw-r--r--packages/base/src/Internal/Vectorized.hs (renamed from packages/base/src/Numeric/Vectorized.hs)220
1 files changed, 145 insertions, 75 deletions
diff --git a/packages/base/src/Numeric/Vectorized.hs b/packages/base/src/Internal/Vectorized.hs
index 589cb49..ddb14c9 100644
--- a/packages/base/src/Numeric/Vectorized.hs
+++ b/packages/base/src/Internal/Vectorized.hs
@@ -1,3 +1,5 @@
1{-# LANGUAGE TypeOperators #-}
2
1----------------------------------------------------------------------------- 3-----------------------------------------------------------------------------
2-- | 4-- |
3-- Module : Numeric.Vectorized 5-- Module : Numeric.Vectorized
@@ -10,37 +12,23 @@
10-- 12--
11----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
12 14
13module Numeric.Vectorized ( 15module Internal.Vectorized where
14 sumF, sumR, sumQ, sumC, sumI, 16
15 prodF, prodR, prodQ, prodC, prodI, 17import Internal.Tools
16 FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, toScalarI, 18import Internal.Vector
17 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, vectorMapI, 19import Internal.Devel
18 FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, vectorMapValI,
19 FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, vectorZipI,
20 vectorScan, saveMatrix,
21 Seed, RandDist(..), randomVector,
22 roundVector,
23 range,
24-- compareD, compareF, compareI,
25-- chooseD, chooseF, chooseI
26) where
27
28import Data.Packed.Internal.Common
29import Data.Packed.Internal.Signatures
30import Data.Packed.Internal.Vector
31import Data.Packed.Internal.Matrix
32 20
33import Data.Complex 21import Data.Complex
34import Foreign.Marshal.Alloc(free,malloc) 22import Foreign.Marshal.Alloc(free,malloc)
35import Foreign.Marshal.Array(newArray,copyArray) 23import Foreign.Marshal.Array(newArray,copyArray)
36import Foreign.Ptr(Ptr) 24import Foreign.Ptr(Ptr)
37import Foreign.Storable(peek) 25import Foreign.Storable(peek,Storable)
38import Foreign.C.Types 26import Foreign.C.Types
39import Foreign.C.String 27import Foreign.C.String
40import System.IO.Unsafe(unsafePerformIO) 28import System.IO.Unsafe(unsafePerformIO)
41 29
42import Control.Monad(when) 30import Control.Monad(when)
43 31import Data.Vector.Storable ( unsafeWith )
44 32
45 33
46fromei x = fromIntegral (fromEnum x) :: CInt 34fromei x = fromIntegral (fromEnum x) :: CInt
@@ -118,11 +106,13 @@ sumg f x = unsafePerformIO $ do
118 app2 f vec x vec r "sum" 106 app2 f vec x vec r "sum"
119 return $ r @> 0 107 return $ r @> 0
120 108
121foreign import ccall unsafe "sumF" c_sumF :: TFF 109type TVV t = t :> t :> Ok
122foreign import ccall unsafe "sumR" c_sumR :: TVV 110
123foreign import ccall unsafe "sumQ" c_sumQ :: TQVQV 111foreign import ccall unsafe "sumF" c_sumF :: TVV Float
124foreign import ccall unsafe "sumC" c_sumC :: TCVCV 112foreign import ccall unsafe "sumR" c_sumR :: TVV Double
125foreign import ccall unsafe "sumC" c_sumI :: CV CInt (CV CInt (IO CInt)) 113foreign import ccall unsafe "sumQ" c_sumQ :: TVV (Complex Float)
114foreign import ccall unsafe "sumC" c_sumC :: TVV (Complex Double)
115foreign import ccall unsafe "sumI" c_sumI :: TVV CInt
126 116
127-- | product of elements 117-- | product of elements
128prodF :: Vector Float -> Float 118prodF :: Vector Float -> Float
@@ -151,18 +141,18 @@ prodg f x = unsafePerformIO $ do
151 return $ r @> 0 141 return $ r @> 0
152 142
153 143
154foreign import ccall unsafe "prodF" c_prodF :: TFF 144foreign import ccall unsafe "prodF" c_prodF :: TVV Float
155foreign import ccall unsafe "prodR" c_prodR :: TVV 145foreign import ccall unsafe "prodR" c_prodR :: TVV Double
156foreign import ccall unsafe "prodQ" c_prodQ :: TQVQV 146foreign import ccall unsafe "prodQ" c_prodQ :: TVV (Complex Float)
157foreign import ccall unsafe "prodC" c_prodC :: TCVCV 147foreign import ccall unsafe "prodC" c_prodC :: TVV (Complex Double)
158foreign import ccall unsafe "prodI" c_prodI :: CV CInt (CV CInt (IO CInt)) 148foreign import ccall unsafe "prodI" c_prodI :: TVV (CInt)
159 149
160------------------------------------------------------------------ 150------------------------------------------------------------------
161 151
162toScalarAux fun code v = unsafePerformIO $ do 152toScalarAux fun code v = unsafePerformIO $ do
163 r <- createVector 1 153 r <- createVector 1
164 app2 (fun (fromei code)) vec v vec r "toScalarAux" 154 app2 (fun (fromei code)) vec v vec r "toScalarAux"
165 return (r `at` 0) 155 return (r @> 0)
166 156
167vectorMapAux fun code v = unsafePerformIO $ do 157vectorMapAux fun code v = unsafePerformIO $ do
168 r <- createVector (dim v) 158 r <- createVector (dim v)
@@ -187,31 +177,31 @@ vectorZipAux fun code u v = unsafePerformIO $ do
187toScalarR :: FunCodeS -> Vector Double -> Double 177toScalarR :: FunCodeS -> Vector Double -> Double
188toScalarR oper = toScalarAux c_toScalarR (fromei oper) 178toScalarR oper = toScalarAux c_toScalarR (fromei oper)
189 179
190foreign import ccall unsafe "toScalarR" c_toScalarR :: CInt -> TVV 180foreign import ccall unsafe "toScalarR" c_toScalarR :: CInt -> TVV Double
191 181
192-- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. 182-- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.
193toScalarF :: FunCodeS -> Vector Float -> Float 183toScalarF :: FunCodeS -> Vector Float -> Float
194toScalarF oper = toScalarAux c_toScalarF (fromei oper) 184toScalarF oper = toScalarAux c_toScalarF (fromei oper)
195 185
196foreign import ccall unsafe "toScalarF" c_toScalarF :: CInt -> TFF 186foreign import ccall unsafe "toScalarF" c_toScalarF :: CInt -> TVV Float
197 187
198-- | obtains different functions of a vector: only norm1, norm2 188-- | obtains different functions of a vector: only norm1, norm2
199toScalarC :: FunCodeS -> Vector (Complex Double) -> Double 189toScalarC :: FunCodeS -> Vector (Complex Double) -> Double
200toScalarC oper = toScalarAux c_toScalarC (fromei oper) 190toScalarC oper = toScalarAux c_toScalarC (fromei oper)
201 191
202foreign import ccall unsafe "toScalarC" c_toScalarC :: CInt -> TCVV 192foreign import ccall unsafe "toScalarC" c_toScalarC :: CInt -> Complex Double :> Double :> Ok
203 193
204-- | obtains different functions of a vector: only norm1, norm2 194-- | obtains different functions of a vector: only norm1, norm2
205toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float 195toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float
206toScalarQ oper = toScalarAux c_toScalarQ (fromei oper) 196toScalarQ oper = toScalarAux c_toScalarQ (fromei oper)
207 197
208foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> TQVF 198foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> Complex Float :> Float :> Ok
209 199
210-- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. 200-- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.
211toScalarI :: FunCodeS -> Vector CInt -> CInt 201toScalarI :: FunCodeS -> Vector CInt -> CInt
212toScalarI oper = toScalarAux c_toScalarI (fromei oper) 202toScalarI oper = toScalarAux c_toScalarI (fromei oper)
213 203
214foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> CV CInt (CV CInt (IO CInt)) 204foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> TVV CInt
215 205
216------------------------------------------------------------------ 206------------------------------------------------------------------
217 207
@@ -219,31 +209,31 @@ foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> CV CInt (CV CInt
219vectorMapR :: FunCodeV -> Vector Double -> Vector Double 209vectorMapR :: FunCodeV -> Vector Double -> Vector Double
220vectorMapR = vectorMapAux c_vectorMapR 210vectorMapR = vectorMapAux c_vectorMapR
221 211
222foreign import ccall unsafe "mapR" c_vectorMapR :: CInt -> TVV 212foreign import ccall unsafe "mapR" c_vectorMapR :: CInt -> TVV Double
223 213
224-- | map of complex vectors with given function 214-- | map of complex vectors with given function
225vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) 215vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double)
226vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper) 216vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper)
227 217
228foreign import ccall unsafe "mapC" c_vectorMapC :: CInt -> TCVCV 218foreign import ccall unsafe "mapC" c_vectorMapC :: CInt -> TVV (Complex Double)
229 219
230-- | map of real vectors with given function 220-- | map of real vectors with given function
231vectorMapF :: FunCodeV -> Vector Float -> Vector Float 221vectorMapF :: FunCodeV -> Vector Float -> Vector Float
232vectorMapF = vectorMapAux c_vectorMapF 222vectorMapF = vectorMapAux c_vectorMapF
233 223
234foreign import ccall unsafe "mapF" c_vectorMapF :: CInt -> TFF 224foreign import ccall unsafe "mapF" c_vectorMapF :: CInt -> TVV Float
235 225
236-- | map of real vectors with given function 226-- | map of real vectors with given function
237vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float) 227vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float)
238vectorMapQ = vectorMapAux c_vectorMapQ 228vectorMapQ = vectorMapAux c_vectorMapQ
239 229
240foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TQVQV 230foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TVV (Complex Float)
241 231
242-- | map of real vectors with given function 232-- | map of real vectors with given function
243vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt 233vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt
244vectorMapI = vectorMapAux c_vectorMapI 234vectorMapI = vectorMapAux c_vectorMapI
245 235
246foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> CV CInt (CV CInt (IO CInt)) 236foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> TVV CInt
247 237
248------------------------------------------------------------------- 238-------------------------------------------------------------------
249 239
@@ -251,64 +241,66 @@ foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> CV CInt (CV CInt (IO
251vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double 241vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double
252vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper) 242vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper)
253 243
254foreign import ccall unsafe "mapValR" c_vectorMapValR :: CInt -> Ptr Double -> TVV 244foreign import ccall unsafe "mapValR" c_vectorMapValR :: CInt -> Ptr Double -> TVV Double
255 245
256-- | map of complex vectors with given function 246-- | map of complex vectors with given function
257vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) 247vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double)
258vectorMapValC = vectorMapValAux c_vectorMapValC 248vectorMapValC = vectorMapValAux c_vectorMapValC
259 249
260foreign import ccall unsafe "mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TCVCV 250foreign import ccall unsafe "mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TVV (Complex Double)
261 251
262-- | map of real vectors with given function 252-- | map of real vectors with given function
263vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float 253vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float
264vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper) 254vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper)
265 255
266foreign import ccall unsafe "mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TFF 256foreign import ccall unsafe "mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TVV Float
267 257
268-- | map of complex vectors with given function 258-- | map of complex vectors with given function
269vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float) 259vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float)
270vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) 260vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper)
271 261
272foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV 262foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TVV (Complex Float)
273 263
274-- | map of real vectors with given function 264-- | map of real vectors with given function
275vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt 265vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt
276vectorMapValI oper = vectorMapValAux c_vectorMapValI (fromei oper) 266vectorMapValI oper = vectorMapValAux c_vectorMapValI (fromei oper)
277 267
278foreign import ccall unsafe "mapValI" c_vectorMapValI :: CInt -> Ptr CInt -> CV CInt (CV CInt (IO CInt)) 268foreign import ccall unsafe "mapValI" c_vectorMapValI :: CInt -> Ptr CInt -> TVV CInt
279 269
280 270
281------------------------------------------------------------------- 271-------------------------------------------------------------------
282 272
273type TVVV t = t :> t :> t :> Ok
274
283-- | elementwise operation on real vectors 275-- | elementwise operation on real vectors
284vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double 276vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double
285vectorZipR = vectorZipAux c_vectorZipR 277vectorZipR = vectorZipAux c_vectorZipR
286 278
287foreign import ccall unsafe "zipR" c_vectorZipR :: CInt -> TVVV 279foreign import ccall unsafe "zipR" c_vectorZipR :: CInt -> TVVV Double
288 280
289-- | elementwise operation on complex vectors 281-- | elementwise operation on complex vectors
290vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) 282vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double)
291vectorZipC = vectorZipAux c_vectorZipC 283vectorZipC = vectorZipAux c_vectorZipC
292 284
293foreign import ccall unsafe "zipC" c_vectorZipC :: CInt -> TCVCVCV 285foreign import ccall unsafe "zipC" c_vectorZipC :: CInt -> TVVV (Complex Double)
294 286
295-- | elementwise operation on real vectors 287-- | elementwise operation on real vectors
296vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float 288vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float
297vectorZipF = vectorZipAux c_vectorZipF 289vectorZipF = vectorZipAux c_vectorZipF
298 290
299foreign import ccall unsafe "zipF" c_vectorZipF :: CInt -> TFFF 291foreign import ccall unsafe "zipF" c_vectorZipF :: CInt -> TVVV Float
300 292
301-- | elementwise operation on complex vectors 293-- | elementwise operation on complex vectors
302vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float) 294vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float)
303vectorZipQ = vectorZipAux c_vectorZipQ 295vectorZipQ = vectorZipAux c_vectorZipQ
304 296
305foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TQVQVQV 297foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TVVV (Complex Float)
306 298
307-- | elementwise operation on CInt vectors 299-- | elementwise operation on CInt vectors
308vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt 300vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt
309vectorZipI = vectorZipAux c_vectorZipI 301vectorZipI = vectorZipAux c_vectorZipI
310 302
311foreign import ccall unsafe "zipI" c_vectorZipI :: CInt -> CV CInt (CV CInt (CV CInt (IO CInt))) 303foreign import ccall unsafe "zipI" c_vectorZipI :: CInt -> TVVV CInt
312 304
313 305
314-------------------------------------------------------------------------------- 306--------------------------------------------------------------------------------
@@ -336,26 +328,6 @@ vectorScan s = do
336 328
337-------------------------------------------------------------------------------- 329--------------------------------------------------------------------------------
338 330
339foreign import ccall unsafe "saveMatrix" c_saveMatrix
340 :: CString -> CString -> TM
341
342{- | save a matrix as a 2D ASCII table
343-}
344saveMatrix
345 :: FilePath
346 -> String -- ^ \"printf\" format (e.g. \"%.2f\", \"%g\", etc.)
347 -> Matrix Double
348 -> IO ()
349saveMatrix name format m = do
350 cname <- newCString name
351 cformat <- newCString format
352 app1 (c_saveMatrix cname cformat) mat m "saveMatrix"
353 free cname
354 free cformat
355 return ()
356
357--------------------------------------------------------------------------------
358
359type Seed = Int 331type Seed = Int
360 332
361data RandDist = Uniform -- ^ uniform distribution in [0,1) 333data RandDist = Uniform -- ^ uniform distribution in [0,1)
@@ -372,7 +344,7 @@ randomVector seed dist n = unsafePerformIO $ do
372 app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" 344 app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector"
373 return r 345 return r
374 346
375foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV 347foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> Double :> Ok
376 348
377-------------------------------------------------------------------------------- 349--------------------------------------------------------------------------------
378 350
@@ -381,7 +353,7 @@ roundVector v = unsafePerformIO $ do
381 app2 c_round_vector vec v vec r "roundVector" 353 app2 c_round_vector vec v vec r "roundVector"
382 return r 354 return r
383 355
384foreign import ccall unsafe "round_vector" c_round_vector :: TVV 356foreign import ccall unsafe "round_vector" c_round_vector :: TVV Double
385 357
386-------------------------------------------------------------------------------- 358--------------------------------------------------------------------------------
387 359
@@ -395,5 +367,103 @@ range n = unsafePerformIO $ do
395 app1 c_range_vector vec r "range" 367 app1 c_range_vector vec r "range"
396 return r 368 return r
397 369
398foreign import ccall unsafe "range_vector" c_range_vector :: CV CInt (IO CInt) 370foreign import ccall unsafe "range_vector" c_range_vector :: CInt :> Ok
371
372
373float2DoubleV :: Vector Float -> Vector Double
374float2DoubleV = tog c_float2double
375
376double2FloatV :: Vector Double -> Vector Float
377double2FloatV = tog c_double2float
378
379double2IntV :: Vector Double -> Vector CInt
380double2IntV = tog c_double2int
381
382int2DoubleV :: Vector CInt -> Vector Double
383int2DoubleV = tog c_int2double
384
385float2IntV :: Vector Float -> Vector CInt
386float2IntV = tog c_float2int
387
388int2floatV :: Vector CInt -> Vector Float
389int2floatV = tog c_int2float
390
391
392tog f v = unsafePerformIO $ do
393 r <- createVector (dim v)
394 app2 f vec v vec r "tog"
395 return r
396
397foreign import ccall unsafe "float2double" c_float2double :: Float :> Double :> Ok
398foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok
399foreign import ccall unsafe "int2double" c_int2double :: CInt :> Double :> Ok
400foreign import ccall unsafe "double2int" c_double2int :: Double :> CInt :> Ok
401foreign import ccall unsafe "int2float" c_int2float :: CInt :> Float :> Ok
402foreign import ccall unsafe "float2int" c_float2int :: Float :> CInt :> Ok
403
404
405---------------------------------------------------------------
406
407stepg f v = unsafePerformIO $ do
408 r <- createVector (dim v)
409 app2 f vec v vec r "step"
410 return r
411
412stepD :: Vector Double -> Vector Double
413stepD = stepg c_stepD
414
415stepF :: Vector Float -> Vector Float
416stepF = stepg c_stepF
417
418stepI :: Vector CInt -> Vector CInt
419stepI = stepg c_stepI
420
421foreign import ccall unsafe "stepF" c_stepF :: TVV Float
422foreign import ccall unsafe "stepD" c_stepD :: TVV Double
423foreign import ccall unsafe "stepI" c_stepI :: TVV CInt
424
425
426--------------------------------------------------------------------------------
427
428conjugateAux fun x = unsafePerformIO $ do
429 v <- createVector (dim x)
430 app2 fun vec x vec v "conjugateAux"
431 return v
432
433conjugateQ :: Vector (Complex Float) -> Vector (Complex Float)
434conjugateQ = conjugateAux c_conjugateQ
435foreign import ccall unsafe "conjugateQ" c_conjugateQ :: TVV (Complex Float)
436
437conjugateC :: Vector (Complex Double) -> Vector (Complex Double)
438conjugateC = conjugateAux c_conjugateC
439foreign import ccall unsafe "conjugateC" c_conjugateC :: TVV (Complex Double)
440
441--------------------------------------------------------------------------------
442
443cloneVector :: Storable t => Vector t -> IO (Vector t)
444cloneVector v = do
445 let n = dim v
446 r <- createVector n
447 let f _ s _ d = copyArray d s n >> return 0
448 app2 f vec v vec r "cloneVector"
449 return r
450
451--------------------------------------------------------------------------------
452
453constantAux fun x n = unsafePerformIO $ do
454 v <- createVector n
455 px <- newArray [x]
456 app1 (fun px) vec v "constantAux"
457 free px
458 return v
459
460type TConst t = Ptr t -> t :> Ok
461
462foreign import ccall unsafe "constantF" cconstantF :: TConst Float
463foreign import ccall unsafe "constantR" cconstantR :: TConst Double
464foreign import ccall unsafe "constantQ" cconstantQ :: TConst (Complex Float)
465foreign import ccall unsafe "constantC" cconstantC :: TConst (Complex Double)
466foreign import ccall unsafe "constantI" cconstantI :: TConst CInt
467
468----------------------------------------------------------------------
399 469