From 5effea5a426b2793adcd3d474b412b8b7ac89c8b Mon Sep 17 00:00:00 2001 From: John Myles White Date: Sun, 2 Dec 2012 20:50:56 -0500 Subject: [PATCH] No more ambiguity warnings. Also renamed svd.jl to linalg.jl in preparation for DataMatrix type. --- src/datavec.jl | 6 ++---- src/{svd.jl => linalg.jl} | 0 src/operators.jl | 35 ++++++++++++++++++++++++++++++----- test/operators.jl | 21 ++++++++++++++++++--- 4 files changed, 50 insertions(+), 12 deletions(-) rename src/{svd.jl => linalg.jl} (100%) diff --git a/src/datavec.jl b/src/datavec.jl index 47ca709fa1..d2e5000990 100644 --- a/src/datavec.jl +++ b/src/datavec.jl @@ -195,10 +195,6 @@ end length(x::NAtype) = 1 size(x::NAtype) = () -==(na::NAtype, na2::NAtype) = NA -==(na::NAtype, b) = NA -==(a, na::NAtype) = NA - # constructor from type function _dv_most_generic_type(vals) # iterate over vals tuple to find the most generic non-NA type @@ -505,6 +501,7 @@ assign{T}(x::PooledDataVec{T}, n::NAtype, rng::Range1) = begin (x.refs[rng] = 0) # TODO: replace!(x::PooledDataVec{T}, from::T, to::T) # and similar to and from NA +replace!{R}(x::PooledDataVec{R}, fromval::NAtype, toval::NAtype) = NA # no-op to deal with warning function replace!{R, S, T}(x::PooledDataVec{R}, fromval::S, toval::T) # throw error if fromval isn't in the pool fromidx = findfirst(x.pool, fromval) @@ -649,6 +646,7 @@ function done(x::AbstractDataVec, state::Int) end # can promote in theory based on data type +promote_rule{T, T}(::Type{AbstractDataVec{T}}, ::Type{T}) = promote_rule(T, T) promote_rule{S, T}(::Type{AbstractDataVec{S}}, ::Type{T}) = promote_rule(S, T) promote_rule{T}(::Type{AbstractDataVec{T}}, ::Type{T}) = T # TODO: Abstract? Pooled? diff --git a/src/svd.jl b/src/linalg.jl similarity index 100% rename from src/svd.jl rename to src/linalg.jl diff --git a/src/operators.jl b/src/operators.jl index ff302e9727..0190f89147 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -20,18 +20,26 @@ scalar_comparison_operators = [:(==), :(!=), :isless, :(>), :(>=), array_comparison_operators = [:(.==), :(.!=), :(.>), :(.>=), :(.<), :(.<=)] binary_operators = [:(+), :(.+), :(-), :(.-), :(*), :(.*), :(/), :(./), - :(^), :(.^), :(div), :(mod), :(fld), :(rem), + :(div), :(mod), :(fld), :(rem), :(&), :(|), :($)] +induced_binary_operators = [:(^), :(.^)] + arithmetic_operators = [:(+), :(.+), :(-), :(.-), :(*), :(.*), :(/), :(./), - :(^), :(.^), :(div), :(mod), :(fld), :(rem)] + :(div), :(mod), :(fld), :(rem)] + +induced_arithmetic_operators = [:(^), :(.^)] biscalar_operators = [:(max), :(min)] -scalar_arithmetic_operators = [:(+), :(-), :(*), :(/), :(^), +scalar_arithmetic_operators = [:(+), :(-), :(*), :(/), :(div), :(mod), :(fld), :(rem)] -array_arithmetic_operators = [:(+), :(.+), :(-), :(.-), :(.*), :(./), :(.^)] +induced_scalar_arithmetic_operators = [:(^)] + +array_arithmetic_operators = [:(+), :(.+), :(-), :(.-), :(.*), :(./)] + +induced_array_arithmetic_operators = [:(.^)] bit_operators = [:(&), :(|), :($)] @@ -53,7 +61,7 @@ columnar_operators = [:colmins, :colmaxs, :colprods, :colsums, boolean_operators = [:any, :all] -# ^ is a special case as it's defined in terms of * +# TODO :(^) is a special case as it's defined in terms of :(*) for f in unary_operators @eval begin @@ -310,6 +318,23 @@ for f in binary_operators function ($f){T <: Union(String, Number)}(x::T, d::NAtype) return NA end + function ($f){T,N}(a::AbstractArray{T,N}, d::NAtype) + return NA + end + function ($f){T,N}(d::NAtype, a::AbstractArray{T,N}) + return NA + end + end +end + +for f in induced_binary_operators + @eval begin + function ($f)(d::NAtype, e::NAtype) + return NA + end + function ($f)(d::Union(String, Number), e::NAtype) + return NA + end end end diff --git a/test/operators.jl b/test/operators.jl index 7ae7183882..354d60ef54 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -22,15 +22,27 @@ scalar_comparison_operators = [:(==), :(!=), :isless, :(>), :(>=), array_comparison_operators = [:(.==), :(.!=), :(.>), :(.>=), :(.<), :(.<=)] +binary_operators = [:(+), :(.+), :(-), :(.-), :(*), :(.*), :(/), :(./), + :(div), :(mod), :(fld), :(rem), + :(&), :(|), :($)] + +induced_binary_operators = [:(^), :(.^)] + arithmetic_operators = [:(+), :(.+), :(-), :(.-), :(*), :(.*), :(/), :(./), - :(^), :(.^), :(div), :(mod), :(fld), :(rem)] + :(div), :(mod), :(fld), :(rem)] + +induced_arithmetic_operators = [:(^), :(.^)] biscalar_operators = [:(max), :(min)] -scalar_arithmetic_operators = [:(+), :(-), :(*), :(/), :(^), +scalar_arithmetic_operators = [:(+), :(-), :(*), :(/), :(div), :(mod), :(fld), :(rem)] -array_arithmetic_operators = [:(+), :(.+), :(-), :(.-), :(.*), :(./), :(.^)] +induced_scalar_arithmetic_operators = [:(^)] + +array_arithmetic_operators = [:(+), :(.+), :(-), :(.-), :(.*), :(./)] + +induced_array_arithmetic_operators = [:(.^)] bit_operators = [:(&), :(|), :($)] @@ -413,3 +425,6 @@ df = DataFrame(quote df[1, 1] = NA @assert isna(any(dv)) @assert isna(all(dv)) + +# TODO: Confirm that this is not true any longer: +# no method .^(NAtype,Int64)