-
Notifications
You must be signed in to change notification settings - Fork 327
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
Support scipy special function with tuple output #3139
Conversation
Given your implementation, it is not hard to use one single operand for two outputs. You may take a look at mars/mars/tensor/linalg/svd.py Lines 44 to 46 in 424cfb9
use mars/mars/tensor/linalg/svd.py Lines 69 to 78 in 424cfb9
and use mars/mars/tensor/linalg/svd.py Lines 150 to 155 in 424cfb9
|
Thank you for your feedback! Will take a look. |
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.
Code structure LGTM. Do not use for i in range(len(list_obj))
. Using for i, obj in enumerate(obj_list)
when indices are needed or for obj in obj_list
is more pythonic.
mars/tensor/special/core.py
Outdated
for i in range(len(op.outputs)): | ||
ctx[op.outputs[i].key] = ret[i] |
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.
Loop over op.outputs
itself, not indices.
for i in range(len(op.outputs)): | |
ctx[op.outputs[i].key] = ret[i] | |
for output in op.outputs: | |
ctx[output] = ret[i] |
mars/tensor/special/core.py
Outdated
return ExecutableTuple(res_tensors) | ||
|
||
for i in range(len(res_tensors)): | ||
out[i].data = res_tensors[i].data |
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.
Ditto.
mars/tensor/special/core.py
Outdated
"dtype": res[i].dtype, | ||
"shape": res[i].shape, | ||
} | ||
for i in range(len(res)) |
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.
Ditto.
assert isinstance(r, ExecutableTuple) | ||
assert len(r) == 2 | ||
|
||
for i in range(len(r)): |
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.
Ditto.
assert len(out) == 2 | ||
assert len(r_out) == 2 | ||
|
||
for i in range(len(r_out)): |
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.
Ditto.
result = r.execute().fetch() | ||
expected = sp_func(raw) | ||
|
||
for i in range(len(result)): |
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.
Ditto.
mars/tensor/special/err_fresnel.py
Outdated
@_register_special_op | ||
class TensorFresnel(TensorTupleOp): | ||
_func_name = "fresnel" | ||
_func_outputs = 2 |
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.
Rename to _n_outputs
might be better.
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.
LGTM
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.
LGTM
…3151) Co-authored-by: RandomY-2 <[email protected]>
What do these changes do?
We can use ExecutableTuple and TensorTupleElementOp to support mars execution of scipy special functions with tuple returns. Specifically, the following syntaxes can be supported:
Also since we invoke scipy.special.fresnel during tensor executions, a cache is added in core.py so if we execute multiple elements of the same function during one execute() call, we don't need to do the scipy computation for each element. Later executes can just use the cached scipy outputs.
Related issue number
Check code requirements