Skip to content

Commit 721fac5

Browse files
Merge branch 'release-0.14.10'. Refs #302.
2 parents 41ae0e8 + c322c58 commit 721fac5

7 files changed

Lines changed: 55 additions & 3 deletions

File tree

yampa-test/CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2024-08-07 Ivan Perez <ivan.perez@keera.co.uk>
2+
* Version bump (0.14.10) (#302).
3+
* Add test for trapezoidIntegral (#263).
4+
15
2024-06-08 Ivan Perez <ivan.perez@keera.co.uk>
26
* Version bump (0.14.9) (#299).
37

yampa-test/tests/Test/FRP/Yampa/Integration.hs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ tests = testGroup "Regression tests for FRP.Yampa.Integration"
2727
, testProperty "imIntegral (0, qc)" testImIntegral0
2828
, testProperty "imIntegral (1, qc)" testImIntegral1
2929
, testProperty "imIntegral (2, qc)" testImIntegral2
30+
, testProperty "trapezoidIntegral (0, qc)" testTrapezoidIntegral0
31+
, testProperty "trapezoidIntegral (1, qc)" testTrapezoidIntegral1
3032
, testProperty "impulseIntegral (0, fixed)" (property $ utils_t7 ~= utils_t7r)
3133
, testProperty "count (0, fixed)" (property $ utils_t4 ~= utils_t4r)
3234
, testProperty "count (1, fixed)" (property $ utils_t5 ~= utils_t5r)
@@ -149,6 +151,40 @@ testImIntegral2 =
149151

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

154+
testTrapezoidIntegral0 :: Property
155+
testTrapezoidIntegral0 =
156+
forAll myStream $ evalT $
157+
Next $ Always $ prop ((sf &&& sfByHand), const close)
158+
159+
where
160+
myStream :: Gen (SignalSampleStream Double)
161+
myStream = uniDistStream
162+
163+
sf :: SF Double Double
164+
sf = trapezoidIntegral >>> derivative
165+
166+
sfByHand :: SF Double Double
167+
sfByHand = (identity &&& iPre 0) >>^ (\(x, y) -> (x + y) / 2)
168+
169+
close (x,y) = abs (x-y) < 0.05
170+
171+
testTrapezoidIntegral1 :: Property
172+
testTrapezoidIntegral1 =
173+
forAll myStream $ evalT $
174+
Next $ Always $ prop ((sf &&& sfByHand), const close)
175+
176+
where
177+
myStream :: Gen (SignalSampleStream Double)
178+
myStream = uniDistStream
179+
180+
sf :: SF Double Double
181+
sf = arr (*2) >>> trapezoidIntegral
182+
183+
sfByHand :: SF Double Double
184+
sfByHand = trapezoidIntegral >>> arr (*2)
185+
186+
close (x,y) = abs (x-y) < 0.05
187+
152188
utils_t7 :: [Double]
153189
utils_t7 = take 50 $ embed impulseIntegral
154190
(deltaEncode 0.1 (zip (repeat 1.0) evSeq))

yampa-test/yampa-test.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cabal-version: >= 1.10
3131
build-type: Simple
3232

3333
name: yampa-test
34-
version: 0.14.9
34+
version: 0.14.10
3535
author: Ivan Perez
3636
maintainer: ivan.perez@keera.co.uk
3737
homepage: http://github.com/ivanperez-keera/Yampa
@@ -84,7 +84,7 @@ library
8484
base >= 4 && < 5
8585
, normaldistribution >= 1.1.0.1 && < 1.2
8686
, QuickCheck >= 2.12 && < 2.15
87-
, Yampa >= 0.14.9 && < 0.15
87+
, Yampa >= 0.14.10 && < 0.15
8888

8989
default-language:
9090
Haskell2010

yampa/CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2024-08-07 Ivan Perez <ivan.perez@keera.co.uk>
2+
* Version bump (0.14.10) (#302).
3+
* Implement integral using trapezoid rule (#263).
4+
15
2024-06-08 Ivan Perez <ivan.perez@keera.co.uk>
26
* Version bump (0.14.9) (#299).
37
* Document FRP.Yampa.Random.streamToSF (#296).

yampa/Yampa.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cabal-version: >= 1.10
3030
build-type: Simple
3131

3232
name: Yampa
33-
version: 0.14.9
33+
version: 0.14.10
3434
author: Henrik Nilsson, Antony Courtney
3535
maintainer: Ivan Perez (ivan.perez@keera.co.uk)
3636
homepage: https://github.com/ivanperez-keera/Yampa/

yampa/src/FRP/Yampa.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ module FRP.Yampa
280280
-- ** Integration and differentiation
281281
, integral
282282
, imIntegral
283+
, trapezoidIntegral
283284
, impulseIntegral
284285
, count
285286
, derivative

yampa/src/FRP/Yampa/Integration.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module FRP.Yampa.Integration
3232
-- * Integration
3333
integral
3434
, imIntegral
35+
, trapezoidIntegral
3536
, impulseIntegral
3637
, count
3738

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

75+
-- | Trapezoid integral (using the average between the value at the last time
76+
-- and the value at the current time).
77+
trapezoidIntegral :: (Fractional s, VectorSpace a s) => SF a a
78+
trapezoidIntegral =
79+
iterFrom (\a a' dt v -> v ^+^ (realToFrac dt / 2) *^ (a ^+^ a')) zeroVector
80+
7481
-- | Integrate the first input signal and add the /discrete/ accumulation (sum)
7582
-- of the second, discrete, input signal.
7683
impulseIntegral :: (Fractional k, VectorSpace a k) => SF (a, Event a) a

0 commit comments

Comments
 (0)