Skip to content
Open
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
21 changes: 20 additions & 1 deletion src/GLMNet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ function glmnet!(X::Matrix{Float64}, y::Vector{Float64},
@check_and_return
end

function glmnet!(X::Matrix{Float64}, y::Vector{Float64},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the code below requires that y be a Vector{Float64}, does it? Maybe we can just make this AbstractVector?

family::Binomial;
kw...)
n = length(y)
newy = zeros(n, 2)
for i in 1:n
if y[i] == 0.0
newy[i, 1], newy[i, 2] = 1, 0
else
newy[i, 1], newy[i, 2] = 0, 1
end
end
return glmnet!(X, newy, family, kw...)
end

function glmnet!(X::Matrix{Float64}, y::Matrix{Float64},
family::Binomial;
offsets::Vector{Float64}=zeros(size(y, 1)),
Expand Down Expand Up @@ -350,7 +365,11 @@ glmnet(X::AbstractMatrix, y::AbstractVector, family::Distribution=Normal(); kw..
glmnet(X::Matrix{Float64}, y::Matrix{Float64}, family::Binomial; kw...) =
glmnet!(copy(X), copy(y), family; kw...)
glmnet(X::Matrix, y::Matrix, family::Binomial; kw...) =
glmnet(float64(X), float64(y), family; kw...)
glmnet!(float64(X), float64(y), family; kw...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that there is always at least one unnecessary allocation happening here, but since float64() doesn't make a copy if the input already has the right type, this will e.g. cause X to be overwritten if it is already a Matrix{Float64} but y is not.

glmnet(X::Matrix{Float64}, y::Vector{Float64}, family::Binomial; kw...) =
glmnet!(copy(X), copy(y), family; kw...)
glmnet(X::Matrix, y::Vector, family::Binomial; kw...) =
glmnet!(float64(X), float64(y), family; kw...)

immutable GLMNetCrossValidation
path::GLMNetPath
Expand Down