From 6d9776676f59a0a9b19337962eeda12e61cdb996 Mon Sep 17 00:00:00 2001 From: Gord Stephen Date: Mon, 19 Sep 2016 17:02:22 -0400 Subject: [PATCH] Reindex transposed sparse contrast matrix into modelmat_cols column-wise for speed improvement (#1070) (cherry picked from commit d4ad15b53f1a12c0debcf5b364802444ffe74004) --- 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