From 0654ad6c7db779d5bf365131b42d434adae4bb5e Mon Sep 17 00:00:00 2001 From: Ben Thompson Date: Thu, 12 Nov 2020 12:44:37 -0500 Subject: [PATCH] Matvec not dot. (#308) * Matvec not dot. * Updated matrix version * Update conda recipe * Use matvec instead of dot. .dot() had a comeback when the master was merged into this branch. * Add changelog entry. Co-authored-by: Elizabeth Santorella Co-authored-by: Jan Tilly Co-authored-by: Jan Tilly --- CHANGELOG.rst | 6 ++++++ conda.recipe/meta.yaml | 2 +- environment.yml | 2 +- src/quantcore/glm/_util.py | 7 ++----- src/quantcore/glm_benchmarks/util.py | 6 +++++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 787aaf9c..9f1dd8ef 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,12 @@ Changelog ========= +1.0.1 - 2020-11-12 +------------------ + +This is a maintenance release to be compatible with `quantcore.matrix>=1.0.0`. + + 1.0.0 - 2020-11-11 ------------------ diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 51473366..4736872c 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -41,7 +41,7 @@ requirements: - scikit-learn >=0.23 - scipy - sparse_dot_mkl >=0.4.0 - - quantcore.matrix >=0.0.3,<1.0.0 + - quantcore.matrix >=1.0.0 test: requires: diff --git a/environment.yml b/environment.yml index b5692b14..90f63053 100644 --- a/environment.yml +++ b/environment.yml @@ -35,7 +35,7 @@ dependencies: - xsimd - dask-ml - tqdm - - quantcore.matrix>=0.0.6,<1.0.0 + - quantcore.matrix>=1.0.0 - sphinx - sphinx_rtd_theme - sphinxcontrib-apidoc diff --git a/src/quantcore/glm/_util.py b/src/quantcore/glm/_util.py index b248444b..e2a203c9 100644 --- a/src/quantcore/glm/_util.py +++ b/src/quantcore/glm/_util.py @@ -13,10 +13,7 @@ def _safe_lin_pred( """Compute the linear predictor taking care if intercept is present.""" idx_offset = 0 if X.shape[1] == coef.shape[0] else 1 nonzero_coefs = np.where(coef[idx_offset:] != 0.0)[0].astype(np.int32) - res = X.dot( - coef[idx_offset:], - cols=nonzero_coefs, - ) + res = X.matvec(coef[idx_offset:], cols=nonzero_coefs) if idx_offset == 1: res += coef[0] @@ -47,7 +44,7 @@ def _safe_sandwich_dot( dim = result.shape[0] + 1 res_including_intercept = np.empty((dim, dim), dtype=X.dtype) res_including_intercept[0, 0] = d.sum() - res_including_intercept[1:, 0] = X.transpose_dot(d, rows, cols) + res_including_intercept[1:, 0] = X.transpose_matvec(d, rows, cols) res_including_intercept[0, 1:] = res_including_intercept[1:, 0] res_including_intercept[1:, 1:] = result else: diff --git a/src/quantcore/glm_benchmarks/util.py b/src/quantcore/glm_benchmarks/util.py index 46d85022..317bc264 100644 --- a/src/quantcore/glm_benchmarks/util.py +++ b/src/quantcore/glm_benchmarks/util.py @@ -95,7 +95,11 @@ def get_obj_val( full_coefs = np.concatenate(([intercept], coefs)) offset = dat.get("offset") - X_dot_coef = dat["X"].dot(coefs) + intercept + if isinstance(dat["X"], mx.MatrixBase): + X_dot_coef = dat["X"].matvec(coefs) + else: + X_dot_coef = dat["X"].dot(coefs) + X_dot_coef += intercept if isinstance(X_dot_coef, pd.Series): X_dot_coef = X_dot_coef.values if offset is not None: