Skip to content

Commit

Permalink
remove Ops AutoOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
bvenn committed Jul 3, 2024
1 parent 08bb78d commit 20ab5a7
Show file tree
Hide file tree
Showing 30 changed files with 94 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Array =
let random = Random.rndgen
let pivotIndex = left + random.NextInt() % (right - left + 1)
let pivot = items.[pivotIndex]
if isNan pivot then
if Ops.isNan pivot then
~~~pivotIndex
else
swapInPlace pivotIndex right items // swap random pivot to right.
Expand All @@ -55,7 +55,7 @@ module Array =
let rec loop i j =
if j < right then
let v = items.[j]
if isNan v then // true if nan
if Ops.isNan v then // true if nan
loop (~~~j) right // break beacause nan
else
if (v <= pivot) then
Expand Down
10 changes: 5 additions & 5 deletions src/FSharp.Stats/DistanceMetrics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module DistanceMetrics =
let mutable dist = 0.
for i in 0 .. (dim - 1) do
let x = v1.[i] - v2.[i]
if not (isNan x) then
if not (Ops.isNan x) then
dist <- dist + abs x
dist

Expand Down Expand Up @@ -186,7 +186,7 @@ module DistanceMetrics =
let diff = abs (v1.[i] - v2.[i])
let d = diff ** p

if not (isNan d) then
if not (Ops.isNan d) then
dist <- dist + d

if p >= 1.0 then
Expand Down Expand Up @@ -273,7 +273,7 @@ module DistanceMetrics =
let mutable dist = 0.0
for i in 0 .. (dim - 1) do
let x = a1.[i] - a2.[i]
if not (isNan x) then
if not (Ops.isNan x) then
dist <- dist + (x * x)
float dist

Expand Down Expand Up @@ -311,7 +311,7 @@ module DistanceMetrics =
let mutable dist = 0.0
for i in 0 .. (dim - 1) do
let x = a1.[i] - a2.[i]
if not (isNan x) then
if not (Ops.isNan x) then
dist <- dist + System.Math.Abs x
dist

Expand Down Expand Up @@ -381,7 +381,7 @@ module DistanceMetrics =
let diff = abs (a1.[i] - a2.[i])
let d = diff ** p

if not (isNan d) then
if not (Ops.isNan d) then
dist <- dist + d

if p >= 1.0 then
Expand Down
6 changes: 3 additions & 3 deletions src/FSharp.Stats/Distributions/Bandwidth.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Bandwidth =
/// </code>
/// </example>
let sturges ndataLength =
ceil (1. + log2 ndataLength)
ceil (1. + Ops.log2 ndataLength)


/// <summary>The Rice Rule is presented as a simple alternative to Sturges's rule.</summary>
Expand Down Expand Up @@ -88,8 +88,8 @@ module Bandwidth =
let forHistogram data =
let data' =
data
|> Seq.filter (fun v -> not (isNan v))
|> Seq.filter (fun v -> not (isInf v))
|> Seq.filter (fun v -> not (Ops.isNan v))
|> Seq.filter (fun v -> not (Ops.isInf v))

let interval = Seq.range data'
let dmin,dmax = Interval.values interval
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Distributions/Continuous/Gamma.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type Gamma =
Gamma.CheckParam alpha beta
match alpha,beta with
| 0., 0. -> infNeg
| a , b when isPosInf(b) -> if a = x then infinity else 0.
| a , b when Ops.isPosInf(b) -> if a = x then infinity else 0.
| 1., _ -> beta * exp(-beta*x)
| _ -> Gamma.PDFLn alpha beta x |> exp

Expand All @@ -167,7 +167,7 @@ type Gamma =
//shape rate
match alpha,beta with
| 0., 0. -> 0.
| a , b when isPosInf(b) -> if a = x then infinity else infNeg
| a , b when Ops.isPosInf(b) -> if a = x then infinity else infNeg
| 1., _ -> log(beta) * (-beta*x)
| _ -> (alpha - 1.) * log(x) - x / beta - (alpha * log(beta)
+ SpecialFunctions.Gamma.gammaLn(alpha))
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Stats/Distributions/Discrete/Binomial.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Binomial =

// Binomial distribution helper functions.
static member CheckParam p n =
if n < 0 || p < 0. || p > 1. || isNan(p) then
if n < 0 || p < 0. || p > 1. || Ops.isNan(p) then
failwith "Binomial distribution should be parametrized by n > 0.0 and 0 ≤ p ≤ 1."

/// <summary>Computes the mode.</summary>
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Stats/Distributions/Discrete/Multinomial.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Multinomial =
if n < 0 then
failwith "Multinomial distribution should be parametrized by n >= 0."
let checkBetween p =
p < 0. || p > 1. || isNan(p)
p < 0. || p > 1. || Ops.isNan(p)
if (p |> Seq.map checkBetween |> Seq.exists id) then
failwith "Multinomial distribution should be parametrized by 0 ≤ p_i ≤ 1."

Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Fitting/GoodnessOfFit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,14 @@ module GoodnessOfFit =
else
let rnd = rnd.Next(0,n)
let tmp = zippedData.[rnd]
if not (isNan(fst tmp)) then
if not (Ops.isNan(fst tmp)) then
zippedData.[rnd] <- (nan,nan)
loop (i+1) (tmp::acc)
else loop i acc
loop 0 []
)
//generate the kth subset out of the left over values in the original data set
let rest = zippedData |> Array.filter (fun (a,b) -> not (isNan a))
let rest = zippedData |> Array.filter (fun (a,b) -> not (Ops.isNan a))
//combine all the subsets
let subsequence = Array.append [|rest|] chunks

Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Fitting/LinearRegression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,11 @@ module LinearRegression =
let factor =
//[for l = 0 to (level - 1) do yield i-l]
List.init level (fun l -> i-l)
|> List.filter (not << isNan)
|> List.filter (not << Ops.isNan)
|> List.fold (fun acc c -> acc * (float c)) 1.
factor * coef.Coefficients.[i] * (pown x (i-level))
)
|> Array.filter (not << isNan)
|> Array.filter (not << Ops.isNan)
|> Array.sum

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Stats/Fitting/NonLinearRegression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ module NonLinearRegression =
///
let private validateBounds (lowerBound: vector) (upperBound: vector) (parameters: vector) =
try
if Vector.map3 (fun l u x -> if l <= x && u >= x then x else nan) lowerBound upperBound parameters |> Vector.exists isNan then
if Vector.map3 (fun l u x -> if l <= x && u >= x then x else nan) lowerBound upperBound parameters |> Vector.exists Ops.isNan then
failwith "initial parameters are not within Bounds"
else
()
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Stats/Interpolation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ module Interpolation =
let xy =
Seq.zip xData yData
// Remove nan
|> Seq.filter (fun (x,y) -> not (isNan x || isNan y || isInf x || isInf y))
|> Seq.filter (fun (x,y) -> not (Ops.isNan x || Ops.isNan y || Ops.isInf x || Ops.isInf y))
// sort by x
|> Seq.sortBy fst
|> Seq.groupBy fst
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Stats/Interval.fs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ type Interval<'a when 'a : comparison> =
| true ->
let current = projection e.Current
// fail if collection contains nan
if isfloat && isNan current then
if isfloat && Ops.isNan current then
//Interval.Empty
invalidOp "Interval cannot be determined if collection contains nan"
else
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/List.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module List =
| [] ->
// place pivot in equal pile
cont [] 0 [x] 1 [] 0
| y::ys when isNan y -> y
| y::ys when Ops.isNan y -> y
| y::ys ->
if y < x then
// place item in less-than pile
Expand Down Expand Up @@ -84,7 +84,7 @@ module List =
let rec loop before xs after =
match xs with
| [] -> failwith "Median of empty list"
| x::xs when isNan x -> x
| x::xs when Ops.isNan x -> x
| x::xs ->
partition x xs (fun lts numlt eqs numeq gts numgt ->
if before + numlt > numeq + numgt + after then
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Stats/ML/Unsupervised/IterativeClustering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module IterativeClustering =
/// </code>
/// </example>
let private meanNaN (input: float []) =
let isValid f = not (isNan f || isInf f)
let isValid f = not (Ops.isNan f || Ops.isInf f)
let rec loop i sum count =
if i < input.Length then
let current = input.[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module PCA =
/// </code>
/// </example>
let center m =
if m |> Matrix.exists (fun x -> isNan x || isInf x) then
if m |> Matrix.exists (fun x -> Ops.isNan x || Ops.isInf x) then
failwith "Computation not possible. Matrix contains invalid entries. Check for the existence of values equal to nan, infinity or -infinity."
else
let columnMeans =
Expand Down Expand Up @@ -68,7 +68,7 @@ module PCA =
/// </code>
/// </example>
let compute m =
if m |> Matrix.exists (fun x -> isNan x || isInf x) then
if m |> Matrix.exists (fun x -> Ops.isNan x || Ops.isInf x) then
failwith "Computation not possible. Matrix contains invalid entries. Check for the existence of values equal to nan, infinity or -infinity."
else
let s,u,v = FSharp.Stats.Algebra.LinearAlgebra.SVD (m)
Expand Down
3 changes: 1 addition & 2 deletions src/FSharp.Stats/Ops.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ namespace FSharp.Stats
#nowarn "40"
#nowarn "42"

/// Operations module (automatically opened)
[<AutoOpen>]
/// Operations module
module Ops =
open System
open System
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Precision.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module Precision =
/// </code>
/// </example>
let almostEqualNormRelative maximumError a b =
if a |> isInf || b |> isInf then
if a |> Ops.isInf || b |> Ops.isInf then
a = b
elif a |> isNan || b |> isNan then
elif a |> Ops.isNan || b |> Ops.isNan then
false
elif ((a - b) |> abs) < maximumError then
true
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Quantile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ module Quantile =
if (q < 0. || q > 1. || data.Length = 0) then
nan
elif (h' <= 0 || q = 0.) then
if Array.exists isNan data then
if Array.exists Ops.isNan data then
nan
else Array.min data
elif (h' >= data.Length || q = 1.) then
if Array.exists isNan data then
if Array.exists Ops.isNan data then
nan
else Array.max data
else
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Random.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module Random =
/// </remarks>
let boxMullerTransform() =
let (u1,u2) = rndgen.NextFloat(),rndgen.NextFloat()
let z0 = sqrt(-2. * log u1) * cos (2. * pi * u2)
let z1 = sqrt(-2. * log u1) * sin (2. * pi * u2)
let z0 = sqrt(-2. * log u1) * cos (2. * Ops.pi * u2)
let z1 = sqrt(-2. * log u1) * sin (2. * Ops.pi * u2)
z0,z1

6 changes: 3 additions & 3 deletions src/FSharp.Stats/Seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ module Seq =
let random = Random.rndgen
let pivotIndex = left + random.NextInt() % (right - left + 1)
let pivot = items.[pivotIndex]
if isNan pivot then
if Ops.isNan pivot then
~~~pivotIndex
else
swapInPlace pivotIndex right items // swap random pivot to right.
Expand All @@ -287,7 +287,7 @@ module Seq =
let rec loop i j =
if j < right then
let v = items.[j]
if isNan v then // true if nan
if Ops.isNan v then // true if nan
loop (~~~j) right // break beacause nan
else
if (v <= pivot) then
Expand Down Expand Up @@ -1151,7 +1151,7 @@ module Seq =
/// <returns>sum of squares</returns>
let sumOfSquares (xData:seq<float>) (exData:seq<float>) =
let xX = Seq.zip xData exData
Seq.fold (fun acc (x,ex) -> acc + square (x - ex)) 0. xX
Seq.fold (fun acc (x,ex) -> acc + Ops.square (x - ex)) 0. xX


/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/Signal/FFT.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module FFT =
// FFT Helper function
let private fftAux (a : Complex array) n j sign m =
let w =
let t = pi * float (sign * m) / float j
let t = Ops.pi * float (sign * m) / float j
Complex(cos t, sin t)
let mutable i = m
while i < n do
Expand Down Expand Up @@ -90,7 +90,7 @@ module FFT =
let private bluestein a =

let bluesteinSequence n =
let s = pi / float n
let s = Ops.pi / float n
Array.init n ( fun k ->
let t = s * float(k * k)
Complex (cos t, sin t)
Expand Down
6 changes: 3 additions & 3 deletions src/FSharp.Stats/SpecialFunctions/Beta.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module Beta =
let ai = 1.0 / a
let ui = (1.0 - b) * x
let t1 = ui / (a + 1.0)
let z = epsilon * ai
let z = Ops.epsilon * ai

let rec loop u t v s n =
if (abs v > z) then
Expand All @@ -149,12 +149,12 @@ module Beta =
let s = loop ui ui t1 0. 2.
let u = a * log x

if ((a + b) < Gamma.maximum && abs u < logMax) then
if ((a + b) < Gamma.maximum && abs u < Ops.logMax) then
let t = Gamma.gamma (a + b) / (Gamma.gamma a * Gamma.gamma b)
s * t * System.Math.Pow(x, a)
else
let t = Gamma.gammaLn (a + b) - Gamma.gammaLn a - Gamma.gammaLn b + u + log s
if (t < logMin) then
if (t < Ops.logMin) then
0.0
else
exp t
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Stats/SpecialFunctions/Gamma.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module Gamma =
match x with
| x when x = 0. -> 0.
| x when (x < 0.0 || a <= 0.0) -> nan
| x when (isPosInf x) -> 1.
| x when (Ops.isPosInf x) -> 1.
| _ ->
if (x= 0.0) then 0.0
elif (a >= ASWITCH) then
Expand All @@ -205,7 +205,7 @@ module Gamma =
match x with
| x when x = 0. -> 1.
| x when (x < 0.0 || a <= 0.0) -> nan
| x when (isPosInf x) -> 0.
| x when (Ops.isPosInf x) -> 0.
| _ ->
if (x= 0.0) then 1.0
elif (a >= ASWITCH) then
Expand Down
8 changes: 4 additions & 4 deletions src/FSharp.Stats/Testing/MultipleTesting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ module MultipleTesting =
let pvaluesExtValid =
pvaluesExt
|> Array.indexed
|> Array.filter (fun (i,p) -> not (isNan p))
|> Array.filter (fun (i,p) -> not (Ops.isNan p))

let pvaluesExtInValid =
pvaluesExt
|> Array.indexed
|> Array.filter (fun (i,p) -> (isNan p))
|> Array.filter (fun (i,p) -> (Ops.isNan p))

// if all pvalues are none, just return the nans
if pvaluesExtValid.Length = 0 then
Expand Down Expand Up @@ -252,12 +252,12 @@ module MultipleTesting =
let pvaluesExtValid =
pvaluesExt
|> Array.indexed
|> Array.filter (fun (i,p) -> not (isNan p))
|> Array.filter (fun (i,p) -> not (Ops.isNan p))

let pvaluesExtInValid =
pvaluesExt
|> Array.indexed
|> Array.filter (fun (i,p) -> (isNan p))
|> Array.filter (fun (i,p) -> (Ops.isNan p))

// if all pvalues are none, just return the nans
if pvaluesExtValid.Length = 0 then
Expand Down
Loading

0 comments on commit 20ab5a7

Please sign in to comment.