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

adding ability to instantiate sparse variables given sparsity. #55

Closed
wants to merge 2 commits into from
Closed
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
25 changes: 14 additions & 11 deletions cvxpy/expressions/leaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,19 @@ def __init__(
'integer': integer, 'sparsity': sparsity, 'bounds': bounds}

if boolean:
self.boolean_idx = boolean if not isinstance(boolean, bool) else list(
np.ndindex(max(shape, (1,))))
self.boolean_idx = boolean if not isinstance(boolean, bool) else set(
np.ndindex(max(shape, (1,))))
else:
self.boolean_idx = []
self.boolean_idx = {}

if integer:
self.integer_idx = integer if not isinstance(integer, bool) else list(
np.ndindex(max(shape, (1,))))
self.integer_idx = integer if not isinstance(integer, bool) else set(
np.ndindex(max(shape, (1,))))
else:
self.integer_idx = []

self.integer_idx = {}
if sparsity:
self.sparsity = sparsity
"""
# Only one attribute be True (except can be boolean and integer).
true_attr = sum(1 for k, v in self.attributes.items() if v)
# HACK we should remove this feature or allow multiple attributes in general.
Expand All @@ -149,16 +151,15 @@ def __init__(
if true_attr > 1:
raise ValueError("Cannot set more than one special attribute in %s."
% self.__class__.__name__)

"""
if value is not None:
self.value = value

self.args = []

self.bounds = bounds

def _get_attr_str(self) -> str:
"""Get a string representing the attributes.
"""
Get a string representing the attributes.
"""
attr_str = ""
for attr, val in self.attributes.items():
Expand Down Expand Up @@ -418,6 +419,8 @@ def project(self, val):
return val
w[bad] = 0
return (V * w).dot(V.T)
elif self.attributes['sparsity']:
return np.where(val[self.sparsity], val, 0)
else:
return val

Expand Down
68 changes: 0 additions & 68 deletions cvxpy/tests/ram_limited.py

This file was deleted.

Loading
Loading