Skip to content

Commit

Permalink
Merge branch 'release-0.14.10'. Refs #302.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanperez-keera committed Aug 8, 2024
2 parents 41ae0e8 + c322c58 commit 721fac5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions yampa-test/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-08-07 Ivan Perez <ivan.perez@keera.co.uk>
* Version bump (0.14.10) (#302).
* Add test for trapezoidIntegral (#263).

2024-06-08 Ivan Perez <ivan.perez@keera.co.uk>
* Version bump (0.14.9) (#299).

Expand Down
36 changes: 36 additions & 0 deletions yampa-test/tests/Test/FRP/Yampa/Integration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ tests = testGroup "Regression tests for FRP.Yampa.Integration"
, testProperty "imIntegral (0, qc)" testImIntegral0
, testProperty "imIntegral (1, qc)" testImIntegral1
, testProperty "imIntegral (2, qc)" testImIntegral2
, testProperty "trapezoidIntegral (0, qc)" testTrapezoidIntegral0
, testProperty "trapezoidIntegral (1, qc)" testTrapezoidIntegral1
, testProperty "impulseIntegral (0, fixed)" (property $ utils_t7 ~= utils_t7r)
, testProperty "count (0, fixed)" (property $ utils_t4 ~= utils_t4r)
, testProperty "count (1, fixed)" (property $ utils_t5 ~= utils_t5r)
Expand Down Expand Up @@ -149,6 +151,40 @@ testImIntegral2 =

close (x,y) = abs (x-y) < 0.05

testTrapezoidIntegral0 :: Property
testTrapezoidIntegral0 =
forAll myStream $ evalT $
Next $ Always $ prop ((sf &&& sfByHand), const close)

where
myStream :: Gen (SignalSampleStream Double)
myStream = uniDistStream

sf :: SF Double Double
sf = trapezoidIntegral >>> derivative

sfByHand :: SF Double Double
sfByHand = (identity &&& iPre 0) >>^ (\(x, y) -> (x + y) / 2)

close (x,y) = abs (x-y) < 0.05

testTrapezoidIntegral1 :: Property
testTrapezoidIntegral1 =
forAll myStream $ evalT $
Next $ Always $ prop ((sf &&& sfByHand), const close)

where
myStream :: Gen (SignalSampleStream Double)
myStream = uniDistStream

sf :: SF Double Double
sf = arr (*2) >>> trapezoidIntegral

sfByHand :: SF Double Double
sfByHand = trapezoidIntegral >>> arr (*2)

close (x,y) = abs (x-y) < 0.05

utils_t7 :: [Double]
utils_t7 = take 50 $ embed impulseIntegral
(deltaEncode 0.1 (zip (repeat 1.0) evSeq))
Expand Down
4 changes: 2 additions & 2 deletions yampa-test/yampa-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cabal-version: >= 1.10
build-type: Simple

name: yampa-test
version: 0.14.9
version: 0.14.10
author: Ivan Perez
maintainer: ivan.perez@keera.co.uk
homepage: http://github.com/ivanperez-keera/Yampa
Expand Down Expand Up @@ -84,7 +84,7 @@ library
base >= 4 && < 5
, normaldistribution >= 1.1.0.1 && < 1.2
, QuickCheck >= 2.12 && < 2.15
, Yampa >= 0.14.9 && < 0.15
, Yampa >= 0.14.10 && < 0.15

default-language:
Haskell2010
Expand Down
4 changes: 4 additions & 0 deletions yampa/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-08-07 Ivan Perez <ivan.perez@keera.co.uk>
* Version bump (0.14.10) (#302).
* Implement integral using trapezoid rule (#263).

2024-06-08 Ivan Perez <ivan.perez@keera.co.uk>
* Version bump (0.14.9) (#299).
* Document FRP.Yampa.Random.streamToSF (#296).
Expand Down
2 changes: 1 addition & 1 deletion yampa/Yampa.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cabal-version: >= 1.10
build-type: Simple

name: Yampa
version: 0.14.9
version: 0.14.10
author: Henrik Nilsson, Antony Courtney
maintainer: Ivan Perez (ivan.perez@keera.co.uk)
homepage: https://github.com/ivanperez-keera/Yampa/
Expand Down
1 change: 1 addition & 0 deletions yampa/src/FRP/Yampa.hs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ module FRP.Yampa
-- ** Integration and differentiation
, integral
, imIntegral
, trapezoidIntegral
, impulseIntegral
, count
, derivative
Expand Down
7 changes: 7 additions & 0 deletions yampa/src/FRP/Yampa/Integration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module FRP.Yampa.Integration
-- * Integration
integral
, imIntegral
, trapezoidIntegral
, impulseIntegral
, count

Expand Down Expand Up @@ -71,6 +72,12 @@ integral = SF {sfTF = tf0}
imIntegral :: (Fractional s, VectorSpace a s) => a -> SF a a
imIntegral = ((\_ a' dt v -> v ^+^ realToFrac dt *^ a') `iterFrom`)

-- | Trapezoid integral (using the average between the value at the last time
-- and the value at the current time).
trapezoidIntegral :: (Fractional s, VectorSpace a s) => SF a a
trapezoidIntegral =
iterFrom (\a a' dt v -> v ^+^ (realToFrac dt / 2) *^ (a ^+^ a')) zeroVector

-- | Integrate the first input signal and add the /discrete/ accumulation (sum)
-- of the second, discrete, input signal.
impulseIntegral :: (Fractional k, VectorSpace a k) => SF (a, Event a) a
Expand Down

0 comments on commit 721fac5

Please sign in to comment.