Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch non Float-arrays to Base methods #21

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/NaNMath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function sum{T<:AbstractFloat}(x::AbstractArray{T})
return result
end

sum(x) = Base.sum(x)

"""
NaNMath.maximum(A)

Expand Down Expand Up @@ -93,6 +95,8 @@ function maximum{T<:AbstractFloat}(x::AbstractArray{T})
return result
end

maximum(x) = Base.maximum(x)

"""
NaNMath.minimum(A)

Expand Down Expand Up @@ -120,6 +124,8 @@ function minimum{T<:AbstractFloat}(x::AbstractArray{T})
return result
end

minimum(x) = Base.minimum(x)

"""
NaNMath.extrema(A)

Expand Down Expand Up @@ -149,6 +155,8 @@ function extrema{T<:AbstractFloat}(x::AbstractArray{T})
return resultmin, resultmax
end

extrema(x) = Base.extrema(x)

"""
NaNMath.mean(A)

Expand All @@ -168,6 +176,8 @@ function mean{T<:AbstractFloat}(x::AbstractArray{T})
return mean_count(x)[1]
end

mean(x) = Base.mean(x)

"""
Returns a tuple of the arithmetic mean of all elements in the array, ignoring NaN's,
and the number of non-NaN values in the array.
Expand Down Expand Up @@ -209,7 +219,7 @@ using NaNMath as nm
nm.var([1., 2., NaN]) # result: 0.5
```
"""
function var{T<:AbstractFloat}(x::Vector{T})
function var{T<:AbstractFloat}(x::AbstractVector{T})
mean_val, n = mean_count(x)
if !isnan(mean_val)
sum_square = zero(eltype(x))
Expand All @@ -224,6 +234,8 @@ function var{T<:AbstractFloat}(x::Vector{T})
end
end

var(x) = Base.var(x)

"""
NaNMath.std(A)

Expand All @@ -243,9 +255,10 @@ using NaNMath as nm
nm.std([1., 2., NaN]) # result: 0.7071067811865476
```
"""
function std{T<:AbstractFloat}(x::Vector{T})
function std{T<:AbstractFloat}(x::AbstractVector{T})
return sqrt(var(x))
end
std(x) = Base.std(x)

"""
NaNMath.min(x, y)
Expand Down