Skip to content

Commit

Permalink
Matvec not dot. (#308)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Jan Tilly <[email protected]>
Co-authored-by: Jan Tilly <[email protected]>
  • Loading branch information
4 people authored Nov 12, 2020
1 parent 2eed716 commit 0654ad6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------

Expand Down
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/quantcore/glm/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/quantcore/glm_benchmarks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0654ad6

Please sign in to comment.