Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty sparse matrices dont need np.zeros #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygam/penalties.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def none(n, coef):
-------
penalty matrix : sparse csc matrix of shape (n,n)
"""
return sp.sparse.csc_matrix(np.zeros((n, n)))
return sp.sparse.csc_matrix((n, n))

def wrap_penalty(p, fit_linear, linear_penalty=0.):
"""
Expand Down
8 changes: 4 additions & 4 deletions pygam/terms.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def __init__(self, feature, n_splines=20, spline_order=3, lam=0.6,
Type of basis function to use in the term.

'ps' : p-spline basis

'cp' : cyclic p-spline basis, useful for building periodic functions.
by default, the maximum and minimum of the feature values
are used to determine the function's period.
Expand Down Expand Up @@ -1315,7 +1315,7 @@ def build_penalties(self):
-------
P : sparse CSC matrix containing the model penalties in quadratic form
"""
P = sp.sparse.csc_matrix(np.zeros((self.n_coefs, self.n_coefs)))
P = sp.sparse.csc_matrix((self.n_coefs, self.n_coefs))
for i in range(len(self._terms)):
P += self._build_marginal_penalties(i)

Expand Down Expand Up @@ -1361,7 +1361,7 @@ def build_constraints(self, coef, constraint_lam, constraint_l2):
-------
C : sparse CSC matrix containing the model constraints in quadratic form
"""
C = sp.sparse.csc_matrix(np.zeros((self.n_coefs, self.n_coefs)))
C = sp.sparse.csc_matrix((self.n_coefs, self.n_coefs))
for i in range(len(self._terms)):
C += self._build_marginal_constraints(i, coef, constraint_lam, constraint_l2)

Expand Down Expand Up @@ -1397,7 +1397,7 @@ def _build_marginal_constraints(self, i, coef, constraint_lam, constraint_l2):
C : sparse CSC matrix containing the model constraints in quadratic form
"""

composite_C = np.zeros((len(coef), len(coef)))
composite_C = sp.sparse.csc_matrix((len(coef), len(coef)))

for slice_ in self._iterate_marginal_coef_slices(i):
# get the slice of coefficient vector
Expand Down