From bd3a0cf58dac0c3e31ba19af4b640808c020c748 Mon Sep 17 00:00:00 2001 From: Gord Stephen Date: Sun, 18 Sep 2016 09:05:47 -0400 Subject: [PATCH] Reindex transposed sparse contrast matrix into modelmat_cols column-wise for speed improvement --- src/statsmodels/formula.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/statsmodels/formula.jl b/src/statsmodels/formula.jl index 82c7a74d27..fde0e36466 100644 --- a/src/statsmodels/formula.jl +++ b/src/statsmodels/formula.jl @@ -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