提交 4fb3d886 编写于 作者: M Megvii Engine Team

perf(misc): use reinterpret_cast to convert valueshape

GitOrigin-RevId: ee14c7ce5e8e77a267db166a5369cd2c4e39bd58
上级 951ed476
......@@ -23,8 +23,7 @@ namespace mgb::imperative {
*
*/
struct ValueShape {
size_t shape[TensorShape::MAX_NDIM];
int ndim = 0;
size_t shape[TensorShape::MAX_NDIM], ndim = 0;
ValueShape() = default;
ValueShape(std::initializer_list<size_t> dims) {
......@@ -70,19 +69,14 @@ struct ValueShape {
return buffer;
}
static ValueShape from(TensorShape tensor_shape) {
static const ValueShape& from(const TensorShape& tensor_shape) {
mgb_assert(tensor_shape.ndim);
return Span<size_t>{tensor_shape.shape, tensor_shape.ndim};
return reinterpret_cast<const ValueShape&>(tensor_shape);
}
TensorShape as_tensor_shape() const {
const TensorShape& as_tensor_shape() const {
mgb_assert(ndim != 0);
TensorShape ret;
for (size_t i = 0; i < ndim; ++i) {
ret.shape[i] = shape[i];
}
ret.ndim = ndim;
return ret;
return reinterpret_cast<const TensorShape&>(*this);
}
bool operator==(const ValueShape& rhs) const {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册