Skip to content

Commit

Permalink
fix a bug; passed all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hua-Zhou committed Apr 19, 2018
1 parent e334ee0 commit a4b084a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion perf/convert_memleak.jl
Expand Up @@ -8,7 +8,8 @@ outv = zeros(n)
# @benchmark copy!(outv, view(hapmap, :, 1), :additive, false, false, false)
# @benchmark copy!(outv, hapmap[:, 1], :additive, false, false, false)
@time for s in 1:snps
copy!(outv, view(hapmap, :, s), :additive, false, false, false)
copy!(outv, hapmap[:, s], :additive, false, false, false)
# @views copy!(outv, hapmap[:, s], :additive, false, false, false)
end

# outm = zeros(n, snps)
Expand Down
10 changes: 4 additions & 6 deletions src/SnpArrays.jl
Expand Up @@ -232,19 +232,19 @@ function Base.convert{T <: Real, N}(t::Type{Array{T, N}}, A::SnpLike{N};
copy!(B, A; model = model, impute = impute, center = center, scale = scale)
end # function Base.convert

function Base.copy!{T <: Real}(B::AbstractMatrix{T}, A::SnpLike{2},
function Base.copy!{T <: Real}(B::AbstractMatrix{T}, A::SnpLike{2};
model::Symbol = :additive, impute::Bool = false, center::Bool = false,
scale::Bool = false)
size(B) == size(A) || throw(ArgumentError("Dimensions do not match"))
n = size(A, 2)
# convert column by column
@inbounds for j in 1:n
@views copy!(B[:, j], A[:, j], model, impute, center)
@views copy!(B[:, j], A[:, j]; model=model, impute=impute, center=center, scale=scale)
end
return B
end # function Base.copy!

function Base.copy!{T <: Real}(B::AbstractVector{T}, A::SnpLike{1},
function Base.copy!{T <: Real}(B::AbstractVector{T}, A::SnpLike{1};
model::Symbol = :additive, impute::Bool = false, center::Bool = false,
scale::Bool = false)
length(B) == length(A) || throw(ArgumentError("Lengths do not match"))
Expand Down Expand Up @@ -656,9 +656,7 @@ function pca_sp{T <: Real, TI}(A::SnpLike{2}, pcs::Integer = 6,
pcscore = zeros(eltype(center), n, pcs)
Acs_mul_B!(pcscore, G, pcloading, center, weight)
# scale by n-1 to obtain eigenvalues of the covariance matrix G'G / (n - 1)
@inbounds @simd for i in 1:pcs
pcvariance[i] = pcvariance[i] / (n - 1)
end
pcvariance ./= n - 1
return pcscore, pcloading, pcvariance
end # function pca_sp

Expand Down

0 comments on commit a4b084a

Please sign in to comment.