Skip to content

Commit

Permalink
Reindex transposed sparse contrast matrix into modelmat_cols column-w…
Browse files Browse the repository at this point in the history
…ise for speed improvement (#1070)
  • Loading branch information
Gord Stephen authored and nalimilan committed Sep 19, 2016
1 parent 968e980 commit d4ad15b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/statsmodels/formula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,12 @@ function modelmat_cols{T<:AbstractFloatMatrix}(::Type{T}, v::PooledDataVector, c
## contrast matrix
reindex = [findfirst(contrast.levels, l) for l in levels(v)]
contrastmatrix = convert(T, contrast.matrix)
return contrastmatrix[reindex[v.refs], :]
return indexrows(contrastmatrix, reindex[v.refs])
end

indexrows(m::SparseMatrixCSC, ind::Vector{Int}) = m'[:, ind]'
indexrows(m::AbstractMatrix, ind::Vector{Int}) = m[ind, :]

"""
expandcols{T<:AbstractFloatMatrix}(trm::Vector{T})
Create pairwise products of columns from a vector of matrices
Expand Down

0 comments on commit d4ad15b

Please sign in to comment.