Skip to content
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

Merged
merged 4 commits into from
Mar 2, 2016

Conversation

pkofod
Copy link
Contributor

@pkofod pkofod commented Feb 29, 2016

Fixes #84 .

@@ -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)
Copy link
Member

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).

@nalimilan
Copy link
Member

Thanks! I've made some comments.

@pkofod
Copy link
Contributor Author

pkofod commented Feb 29, 2016

Great comments, I will address them, and add tests for sparse matrices.

@pkofod
Copy link
Contributor Author

pkofod commented Feb 29, 2016

Is this better? Notice I'm doing full(X), so it doesn't really work with sparse input, but I think such an addition belongs in a separate PR. I'm pretty sure several functions would have to be adapted, and the readme also states that only dense versions of the LinPred are supported.

@nalimilan
Copy link
Member

I don't like calling full automatically, as it may use too much memory without warning. It's no better than leaving the caller do the conversion manually. If it doesn't work, then let it fail for now. Does it work for GLMs?

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)
Copy link
Member

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).

@pkofod
Copy link
Contributor Author

pkofod commented Feb 29, 2016

Alright, I'll let it fail instead. Yes it works for glm.

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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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).

Copy link
Contributor Author

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.

@pkofod
Copy link
Contributor Author

pkofod commented Mar 1, 2016

I've "reverted" to AbstractMatrix. Notice the parametric type in the "first" fit method. I'm not using T for anything, so I'm unsure if it's non-Julian or not; it's basically just to enforce eltype<:FP as in glm.

andreasnoack added a commit that referenced this pull request Mar 2, 2016
Allow users to use integer arrays as input (but convert them).
@andreasnoack andreasnoack merged commit dc0dceb into JuliaStats:master Mar 2, 2016
@andreasnoack
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants