module Phonetic.Languages.Filters (
intervalNRealFrac
, unsafeTransfer1I5
, transfer1IEq3
, unsafeRearrangeIG
, unsafeRearrangeIGV
, unsafeSwapIWithMaxI
, unsafeSwapVecIWithMaxI
) where
import Data.Filters.Basic
import GHC.Arr
import CaseBi.Arr
unsafeRearrangeIG
:: (RealFrac b, Integral c) => b
-> b
-> c
-> [(c,c)]
-> b
-> b
unsafeRearrangeIG :: b -> b -> c -> [(c, c)] -> b -> b
unsafeRearrangeIG b
minE b
maxE c
n [(c, c)]
xs b
x
| b
minE b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
maxE = b
x
| Bool
otherwise = b
x b -> b -> b
forall a. Num a => a -> a -> a
+ c -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (c -> [(c, c)] -> c -> c
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstLSorted' c
n0 [(c, c)]
xs c
n0 c -> c -> c
forall a. Num a => a -> a -> a
- c
n0) b -> b -> b
forall a. Num a => a -> a -> a
* (b
maxE b -> b -> b
forall a. Num a => a -> a -> a
- b
minE) b -> b -> b
forall a. Fractional a => a -> a -> a
/ c -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral c
n
where n0 :: c
n0 = b -> b -> c -> b -> c
forall b c. (RealFrac b, Integral c) => b -> b -> c -> b -> c
intervalNRealFrac b
minE b
maxE c
n b
x
unsafeRearrangeIGV
:: (RealFrac b, Integral c) => b
-> b
-> c
-> [c]
-> b
-> b
unsafeRearrangeIGV :: b -> b -> c -> [c] -> b -> b
unsafeRearrangeIGV b
minE b
maxE c
n [c]
xs = b -> b -> c -> [(c, c)] -> b -> b
forall b c.
(RealFrac b, Integral c) =>
b -> b -> c -> [(c, c)] -> b -> b
unsafeRearrangeIG b
minE b
maxE c
n ([(c, c)] -> b -> b) -> ([c] -> [(c, c)]) -> [c] -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [c] -> [c] -> [(c, c)]
forall a b. [a] -> [b] -> [(a, b)]
zip [c
1..c
n] ([c] -> b -> b) -> [c] -> b -> b
forall a b. (a -> b) -> a -> b
$ [c]
xs
{-# INLINE unsafeRearrangeIGV #-}
unsafeSwapIWithMaxI
:: (RealFrac b, Integral c) => b
-> b
-> c
-> c
-> b
-> b
unsafeSwapIWithMaxI :: b -> b -> c -> c -> b -> b
unsafeSwapIWithMaxI b
minE b
maxE c
n c
k = b -> b -> c -> [c] -> b -> b
forall b c.
(RealFrac b, Integral c) =>
b -> b -> c -> [c] -> b -> b
unsafeRearrangeIGV b
minE b
maxE c
n ([c] -> b -> b) -> ([c] -> [c]) -> [c] -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> c) -> [c] -> [c]
forall a b. (a -> b) -> [a] -> [b]
map (c -> c -> c -> c
forall a. (Eq a, Num a) => a -> a -> a -> a
f c
k c
n) ([c] -> b -> b) -> [c] -> b -> b
forall a b. (a -> b) -> a -> b
$ [c
0..c
n c -> c -> c
forall a. Num a => a -> a -> a
- c
1]
where f :: a -> a -> a -> a
f a
k a
n a
x
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
k a -> a -> a
forall a. Num a => a -> a -> a
- a
1 = a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
1
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
1 = a
k a -> a -> a
forall a. Num a => a -> a -> a
- a
1
| Bool
otherwise = a
x
{-# INLINE f #-}
{-# INLINE unsafeSwapIWithMaxI #-}
unsafeSwapVecIWithMaxI
:: (RealFrac b, Integral c) => b
-> b
-> c
-> [c]
-> b
-> b
unsafeSwapVecIWithMaxI :: b -> b -> c -> [c] -> b -> b
unsafeSwapVecIWithMaxI b
minE b
maxE c
n [c]
xs = b -> b -> c -> [c] -> b -> b
forall b c.
(RealFrac b, Integral c) =>
b -> b -> c -> [c] -> b -> b
unsafeRearrangeIGV b
minE b
maxE c
n ((c -> c) -> [c] -> [c]
forall a b. (a -> b) -> [a] -> [b]
map c -> c
h [c
0..c
n c -> c -> c
forall a. Num a => a -> a -> a
- c
1])
where h :: c -> c
h c
i
| Bool -> [(c, Bool)] -> c -> Bool
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstLSorted' Bool
False ([c] -> [Bool] -> [(c, Bool)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((c -> c) -> [c] -> [c]
forall a b. (a -> b) -> [a] -> [b]
map (c -> c -> c
forall a. Num a => a -> a -> a
+ (-c
1)) [c]
xs) ([Bool] -> [(c, Bool)]) -> (Bool -> [Bool]) -> Bool -> [(c, Bool)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> [Bool]
forall a. Int -> a -> [a]
replicate (c -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral c
n) (Bool -> [(c, Bool)]) -> Bool -> [(c, Bool)]
forall a b. (a -> b) -> a -> b
$ Bool
True) c
i = c
n c -> c -> c
forall a. Num a => a -> a -> a
- c
1
| c
i c -> c -> Bool
forall a. Eq a => a -> a -> Bool
== c
n c -> c -> c
forall a. Num a => a -> a -> a
- c
1 = [c] -> c
forall a. [a] -> a
head [c]
xs
| Bool
otherwise = c
i
{-# INLINE unsafeSwapVecIWithMaxI #-}