-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[Relay][Op] concatenate, reshape, transpose, copy #1847
Conversation
src/relay/op/tensor/transform.cc
Outdated
} else { | ||
std::vector<int> axis_used(ndim, 0); | ||
for (const IndexExpr& e: axes) { | ||
int axis = _helper::ToInt(e); |
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.
there is a function as_const_int, we can also populate common helper functions in op_utils.h
It is OK(and encouraged when we intended to do so) to directly require IndexExpr to be int when they are in array, we can do #include <tvm/ir_operator.h>
for (size_t i = 0; i < axes.size(); ++i) {
const int64_t* paxis = as_const_int(axes[i]);
CHECK(paxis != nullptr);
...
} |
|
@tqchen @srkreddy1238 Hey folks could you help review this PR? |
src/relay/op/tensor/transform.cc
Outdated
<< ", and ndim = " << ndim; | ||
axis = axis < 0 ? ndim + axis : axis; | ||
// Calculate shape | ||
std::vector<IndexExpr> oshape; |
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.
Let us make it as a helper function AsVector<T>(const Array<T>&)
and put it under op_common.h in src/relay/op
# let's mimic a batch of sequences | ||
x = ib.param("x", relay.ty.TensorType((n, t, d), "float32")) | ||
y = ib.param("y", relay.ty.TensorType((n, t, d), "float32")) | ||
with ib.function(x, y) as func: |
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.
please test several case of axis
python/tvm/relay/op/tensor.py
Outdated
@@ -345,3 +330,41 @@ def ones_like(data): | |||
The computed result. | |||
""" | |||
return _make.ones_like(data) | |||
|
|||
def concatenate(data, axis=0): |
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.
Let us consider remove default axis in concatenate for now, The main reason is that historically concat usually defaults to axis=1, this new default will likely cause some confusion.
@tqchen hey could you help review this again at your convenience? Rebasing many times seems painful to me. |
The changes LGTM, let us wait the CI and then merge it in |
OP TODO
Misc TODO
Issues & discussion
numpy.concatenate
acceptsaxis=None
, in which case numpy flattens all input arrays before doing concat, while we do not supportaxis=None
.numpy.reshape
is a subset of ourreshape
. I think it is fine (or even better).transpose
directly convertArray<IndexExpr> axes
tovector<int>
?Related issue: #1799