packages feed

casadi-bindings 2.4.1.5 → 2.4.1.6

raw patch · 3 files changed

+162/−10 lines, 3 filesdep +doctestdep ~base

Dependencies added: doctest

Dependency ranges changed: base

Files

casadi-bindings.cabal view
@@ -1,5 +1,5 @@ name:                casadi-bindings-version:             2.4.1.5+version:             2.4.1.6 synopsis:            mid-level bindings to CasADi category:            Numerical, Math description:@@ -74,3 +74,13 @@ source-repository head   type: git   location: git://github.com/ghorn/casadi-bindings.git++test-suite doctests+  type:                exitcode-stdio-1.0+  main-is:             doctests.hs+  build-depends:       base >= 4 && < 5,+                       doctest >= 0.8+  default-language:    Haskell2010+  ghc-options:         -threaded+  hs-source-dirs:      tests+
src/Casadi/Overloading.hs view
@@ -1,10 +1,12 @@ {-# OPTIONS_GHC -Wall #-}  module Casadi.Overloading-       ( Fmod(..)-       , ArcTan2(..)-       , SymOrd(..)+       ( ArcTan2(..)        , Erf(..)+       , Fmod(..)+       , SymOrd(..)+       , lt, gt+       , ifLeqThen, ifGeqThen, ifEqThen, ifLtThen, ifGtThen        ) where  import Data.Fixed ( mod' )@@ -23,10 +25,48 @@ instance ArcTan2 Double where arctan2 = atan2 instance ArcTan2 Float where arctan2 = atan2 --- | Ord, but returns a 1 or a 0 instead of True or False-class SymOrd a where+-- | error function+class Erf a where+  erf :: a -> a+  erfinv :: a -> a+++-- | Ord, but returns a 1 or a 0 instead of True or False.+-- If you optimize functions which include these, you are responsible for+-- keeping things smooth enough.+--+-- >>> 41 `leq` 42 :: Double+-- 1.0+--+-- >>> 42 `leq` 42 :: Double+-- 1.0+--+-- >>> 43 `leq` 42 :: Double+-- 0.0+--+-- >>> 41 `geq` 42 :: Double+-- 0.0+--+-- >>> 42 `geq` 42 :: Double+-- 1.0+--+-- >>> 43 `geq` 42 :: Double+-- 1.0+--+-- >>> 41 `eq` 42 :: Double+-- 0.0+--+-- >>> 42 `eq` 42 :: Double+-- 1.0+--+-- >>> 43 `eq` 42 :: Double+-- 0.0+class Num a => SymOrd a where+  -- | @<=@   leq :: a -> a -> a+  -- | @>=@   geq :: a -> a -> a+  -- | @==@   eq :: a -> a -> a  instance SymOrd Double where@@ -38,7 +78,101 @@   x `geq` y = if x >= y then 1 else 0   x  `eq` y = if x == y then 1 else 0 --- | error function-class Erf a where-  erf :: a -> a-  erfinv :: a -> a+-- | @<@+-- >>> 41 `lt` 42 :: Double+-- 1.0+--+-- >>> 42 `lt` 42 :: Double+-- 0.0+--+-- >>> 43 `lt` 42 :: Double+-- 0.0+lt :: SymOrd a => a -> a -> a+lt x y = 1 - geq x y++-- | @>@+-- >>> 41 `gt` 42 :: Double+-- 0.0+--+-- >>> 42 `gt` 42 :: Double+-- 0.0+--+-- >>> 43 `gt` 42 :: Double+-- 1.0+gt :: SymOrd a => a -> a -> a+gt x y = 1 - leq x y++-- | @ifLeqThen x y ifX ifY == if x <= y then ifX else ifY@+-- >>> ifLeqThen 41 42 100 200 :: Double+-- 100.0+--+-- >>> ifLeqThen 42 42 100 200 :: Double+-- 100.0+--+-- >>> ifLeqThen 43 42 100 200 :: Double+-- 200.0+--+ifLeqThen :: SymOrd a => a -> a -> a -> a -> a+ifLeqThen = ifCondThen leq+++-- | @ifGeqThen x y ifX ifY == if x >= y then ifX else ifY@+-- >>> ifGeqThen 41 42 100 200 :: Double+-- 200.0+--+-- >>> ifGeqThen 42 42 100 200 :: Double+-- 100.0+--+-- >>> ifGeqThen 43 42 100 200 :: Double+-- 100.0+--+ifGeqThen :: SymOrd a => a -> a -> a -> a -> a+ifGeqThen = ifCondThen geq+++-- | @ifEqThen x y ifX ifY == if x == y then ifX else ifY@+-- >>> ifEqThen 41 42 100 200 :: Double+-- 200.0+--+-- >>> ifEqThen 42 42 100 200 :: Double+-- 100.0+--+-- >>> ifEqThen 43 42 100 200 :: Double+-- 200.0+--+ifEqThen :: SymOrd a => a -> a -> a -> a -> a+ifEqThen = ifCondThen eq+++-- | @ifLtThen x y ifX ifY == if x < y then ifX else ifY@+-- >>> ifLtThen 41 42 100 200 :: Double+-- 100.0+--+-- >>> ifLtThen 42 42 100 200 :: Double+-- 200.0+--+-- >>> ifLtThen 43 42 100 200 :: Double+-- 200.0+--+ifLtThen :: SymOrd a => a -> a -> a -> a -> a+ifLtThen = ifCondThen lt+++-- | @ifGtThen x y ifX ifY == if x > y then ifX else ifY@+-- >>> ifGtThen 41 42 100 200 :: Double+-- 200.0+--+-- >>> ifGtThen 42 42 100 200 :: Double+-- 200.0+--+-- >>> ifGtThen 43 42 100 200 :: Double+-- 100.0+--+ifGtThen :: SymOrd a => a -> a -> a -> a -> a+ifGtThen = ifCondThen gt+++ifCondThen :: Num a => (a -> a -> a) -> a -> a -> a -> a -> a+ifCondThen cond x y if' then' = true*if' + (1 - true)*then'+  where+    true = cond x y
+ tests/doctests.hs view
@@ -0,0 +1,8 @@+{-# OPTIONS_GHC -Wall #-}++module Main where++import Test.DocTest++main :: IO ()+main = doctest ["src/Casadi/Overloading.hs"]