-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add Size
symbol
#50
Add Size
symbol
#50
Conversation
I am toying with renaming these to |
Still ruminating on this, but a few thoughts. One issue with calling it I am currently inclined to do something like s: Size = a.size(symbol=True) It's ugly, but nicely explicit. Alternatives
|
Ah, if we implement Something like def __index__(self) -> int:
return int(np.asarray(self)) would let us fall back on NumPy's error message albeit at the cost of some extra object creations. Or we could just copy their error message. |
With the addition of #72, we could now always return a symbol from |
9cfd9cc
to
80177f3
Compare
Ended up going with the approach where we return a symbol only for dynamic nodes. I hate the switching behavior of the return type, but I think it's the least confusion option for now. |
dwave/optimization/model.pyi
Outdated
@@ -174,7 +174,7 @@ class ArraySymbol(Symbol): | |||
def prod(self) -> Prod: ... | |||
def reshape(self, shape: _ShapeLike) -> Reshape: ... | |||
def shape(self) -> typing.Tuple[int, ...]: ... | |||
def size(self) -> int: ... | |||
def size(self) -> typng.Union[int, Size]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
|
||
void initialize_state(State& state) const override; | ||
|
||
// LenNode's value is always a non-negative integer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LenNode => SizeNode ?
yield b | ||
yield c | ||
|
||
def test_dynamic(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to get the length for disjoint_lists:
model = Model()
model.states.resize(1)
x, ys = model.disjoint_lists(5, 3)
length0 = ys[0].size()
length1 = ys[1].size()
length2 = ys[2].size()
x.set_state(0, [[0, 1, 2, 3, 4], [], []])
with model.lock():
print(length0.state(0))
print(length1.state(0))
print(length2.state(0))
Is there a better way for doing this? For example, can we make an array of all lengths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently no way to join them into another array unfortunately, we'd need #46 for that I think
dc163ed
to
0397b80
Compare
Closes #48