Skip to content

Commit

Permalink
replace float64(x) with convert(Float64, x)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindahua committed Apr 18, 2015
1 parent fc2ad78 commit a1e8a94
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
11 changes: 5 additions & 6 deletions src/generics.jl
Expand Up @@ -12,18 +12,18 @@ Base.length(a::AbstractPDMat) = abs2(dim(a))

pdadd!(r::Matrix{Float64}, a::Matrix{Float64}, b::AbstractPDMat) = pdadd!(r, a, b, 1.0)

pdadd!(a::Matrix{Float64}, b::AbstractPDMat, c::Real) = pdadd!(a, a, b, float64(c))
pdadd!(a::Matrix{Float64}, b::AbstractPDMat, c::Real) = pdadd!(a, a, b, convert(Float64, c))
pdadd!(a::Matrix{Float64}, b::AbstractPDMat) = pdadd!(a, a, b, 1.0)

pdadd(a::Matrix{Float64}, b::AbstractPDMat, c::Real) = pdadd!(similar(a), a, b, float64(c))
pdadd(a::Matrix{Float64}, b::AbstractPDMat, c::Real) = pdadd!(similar(a), a, b, convert(Float64, c))
pdadd(a::Matrix{Float64}, b::AbstractPDMat) = pdadd!(similar(a), a, b, 1.0)

+ (a::Matrix{Float64}, b::AbstractPDMat) = pdadd(a, b)
+ (a::AbstractPDMat, b::Matrix{Float64}) = pdadd(b, a)

* (a::AbstractPDMat, c::Real) = a * float64(c)
* (c::Real, a::AbstractPDMat) = a * float64(c)
/ (a::AbstractPDMat, c::Real) = a * float64(inv(c))
* (a::AbstractPDMat, c::Real) = a * convert(Float64, c)
* (c::Real, a::AbstractPDMat) = a * convert(Float64, c)
/ (a::AbstractPDMat, c::Real) = a * convert(Float64, inv(c))


## whiten and unwhiten
Expand All @@ -46,4 +46,3 @@ function invquad(a::AbstractPDMat, x::DenseMatrix{Float64})
@check_argdims dim(a) == size(x, 1)
invquad!(Array(Float64, size(x,2)), a, x)
end

19 changes: 9 additions & 10 deletions src/pdiagmat.jl
Expand Up @@ -4,9 +4,9 @@ immutable PDiagMat <: AbstractPDMat
dim::Int
diag::Vector{Float64}
inv_diag::Vector{Float64}
PDiagMat(v::Vector{Float64}) = new(length(v), v, 1.0 ./ v)

PDiagMat(v::Vector{Float64}) = new(length(v), v, 1.0 ./ v)

function PDiagMat(v::Vector{Float64}, inv_v::Vector{Float64})
@check_argdims length(v) == length(inv_v)
new(length(v), v, inv_v)
Expand All @@ -26,9 +26,9 @@ diag(a::PDiagMat) = copy(a.diag)
function pdadd!(r::Matrix{Float64}, a::Matrix{Float64}, b::PDiagMat, c::Real)
@check_argdims size(r) == size(a) == size(b)
if is(r, a)
_adddiag!(r, b.diag, float64(c))
_adddiag!(r, b.diag, convert(Float64, c))
else
_adddiag!(copy!(r, a), b.diag, float64(c))
_adddiag!(copy!(r, a), b.diag, convert(Float64, c))
end
return r
end
Expand All @@ -46,7 +46,7 @@ eigmax(a::PDiagMat) = maximum(a.diag)
eigmin(a::PDiagMat) = minimum(a.diag)


### whiten and unwhiten
### whiten and unwhiten

function whiten!(r::DenseVector{Float64}, a::PDiagMat, x::DenseVector{Float64})
n = dim(a)
Expand All @@ -68,10 +68,10 @@ function unwhiten!(r::DenseVector{Float64}, a::PDiagMat, x::DenseVector{Float64}
return r
end

whiten!(r::DenseMatrix{Float64}, a::PDiagMat, x::DenseMatrix{Float64}) =
whiten!(r::DenseMatrix{Float64}, a::PDiagMat, x::DenseMatrix{Float64}) =
broadcast!(*, r, x, sqrt(a.inv_diag))

unwhiten!(r::DenseMatrix{Float64}, a::PDiagMat, x::DenseMatrix{Float64}) =
unwhiten!(r::DenseMatrix{Float64}, a::PDiagMat, x::DenseMatrix{Float64}) =
broadcast!(*, r, x, sqrt(a.diag))


Expand All @@ -86,7 +86,7 @@ invquad!(r::AbstractArray, a::PDiagMat, x::Matrix{Float64}) = At_mul_B!(r, abs2(

### tri products

function X_A_Xt(a::PDiagMat, x::DenseMatrix{Float64})
function X_A_Xt(a::PDiagMat, x::DenseMatrix{Float64})
z = x .* reshape(sqrt(a.diag), 1, dim(a))
A_mul_Bt(z, z)
end
Expand All @@ -105,4 +105,3 @@ function Xt_invA_X(a::PDiagMat, x::DenseMatrix{Float64})
z = x .* sqrt(a.inv_diag)
At_mul_B(z, z)
end

6 changes: 3 additions & 3 deletions src/pdmat.jl
Expand Up @@ -32,7 +32,7 @@ diag(a::PDMat) = diag(a.mat)

function pdadd!(r::Matrix{Float64}, a::Matrix{Float64}, b::PDMat, c::Real)
@check_argdims size(r) == size(a) == size(b)
_addscal!(r, a, b.mat, float64(c))
_addscal!(r, a, b.mat, convert(Float64, c))
end

* (a::PDMat, c::Float64) = PDMat(a.mat * c)
Expand Down Expand Up @@ -67,15 +67,15 @@ end

quad(a::PDMat, x::DenseVector{Float64}) = dot(x, a * x)
invquad(a::PDMat, x::DenseVector{Float64}) = dot(x, a \ x)

quad!(r::AbstractArray, a::PDMat, x::DenseMatrix{Float64}) = colwise_dot!(r, x, a.mat * x)
invquad!(r::AbstractArray, a::PDMat, x::DenseMatrix{Float64}) = colwise_dot!(r, x, a.mat \ x)


### tri products

function X_A_Xt(a::PDMat, x::DenseMatrix{Float64})
z = copy(x)
z = copy(x)
cf = a.chol[:UL]
istriu(cf) ? A_mul_Bc!(z, cf) : A_mul_B!(z, cf)
A_mul_Bt(z, z)
Expand Down
9 changes: 4 additions & 5 deletions src/scalmat.jl
Expand Up @@ -4,7 +4,7 @@ immutable ScalMat <: AbstractPDMat
dim::Int
value::Float64
inv_value::Float64

ScalMat(d::Int, v::Float64) = new(d, v, 1.0 / v)
ScalMat(d::Int, v::Float64, inv_v::Float64) = new(d, v, inv_v)
end
Expand All @@ -22,9 +22,9 @@ diag(a::ScalMat) = fill(a.value, a.dim)
function pdadd!(r::Matrix{Float64}, a::Matrix{Float64}, b::ScalMat, c::Real)
@check_argdims size(r) == size(a) == size(b)
if is(r, a)
_adddiag!(r, b.value * float64(c))
_adddiag!(r, b.value * convert(Float64, c))
else
_adddiag!(copy!(r, a), b.value * float64(c))
_adddiag!(copy!(r, a), b.value * convert(Float64, c))
end
return r
end
Expand All @@ -43,7 +43,7 @@ eigmax(a::ScalMat) = a.value
eigmin(a::ScalMat) = a.value


### whiten and unwhiten
### whiten and unwhiten

function whiten!(r::DenseVecOrMat{Float64}, a::ScalMat, x::DenseVecOrMat{Float64})
@check_argdims dim(a) == size(x, 1)
Expand Down Expand Up @@ -94,4 +94,3 @@ function Xt_invA_X(a::ScalMat, x::DenseMatrix{Float64})
@check_argdims dim(a) == size(x, 1)
gemm('T', 'N', a.inv_value, x, x)
end

0 comments on commit a1e8a94

Please sign in to comment.