-
Notifications
You must be signed in to change notification settings - Fork 114
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
Allow users to use integer arrays as input (but convert them). #130
Conversation
@@ -64,7 +64,7 @@ end | |||
cholfact(x::LinearModel) = cholfact(x.pp) | |||
|
|||
function fit{LmRespT<:LmResp,LinPredT<:LinPred}(::Type{LinearModel{LmRespT,LinPredT}}, | |||
X::AbstractMatrix, y::Vector) | |||
X::@compat(Union{Matrix,SparseMatrixCSC{FP}}), y::FPVector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SparseMatrixCSC{FP}
will only accept matrices with the abstract type FP
, and not of any concrete subtypes. Use T<:FP
as for GLMs.
BTW, it would be great to test sparse matrices (which would have caught this problem).
Thanks! I've made some comments. |
Great comments, I will address them, and add tests for sparse matrices. |
Is this better? Notice I'm doing |
I don't like calling |
yy = convert(Vector{T}, y) | ||
return fit(LinearModel{LmResp{typeof(yy)}, DensePredQR{T}}, X, y) | ||
function fit(::Type{LinearModel}, X::@compat(Union{Matrix,SparseMatrixCSC}), y::Vector) | ||
y = float(y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For type stability, assign the result to yy
(even if here the function is pretty short so it shouldn't make a big difference).
Alright, I'll let it fail instead. Yes it works for |
…test with sparse X.
function fit{LmRespT<:LmResp,LinPredT<:LinPred}(::Type{LinearModel{LmRespT,LinPredT}}, | ||
X::AbstractMatrix, y::Vector) | ||
function fit{LmRespT<:LmResp,LinPredT<:LinPred, T<:FP}(::Type{LinearModel{LmRespT,LinPredT}}, | ||
X::@compat(Union{Matrix{T},SparseMatrixCSC{T}}), y::FPVector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why restrict the matrix type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just followed the glm code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If AbstractMatrix
doesn't cause any issues, I'd stick with that here and change glm
instead (in a separate PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll change it later.
I've "reverted" to AbstractMatrix. Notice the parametric type in the "first" |
Allow users to use integer arrays as input (but convert them).
Thanks |
Fixes #84 .