Browse Source

perf(misc): use reinterpret_cast to convert valueshape

GitOrigin-RevId: ee14c7ce5e
release-1.10
Megvii Engine Team 3 years ago
parent
commit
4fb3d886b8
1 changed files with 5 additions and 11 deletions
  1. +5
    -11
      imperative/src/include/megbrain/imperative/utils/value_shape.h

+ 5
- 11
imperative/src/include/megbrain/imperative/utils/value_shape.h View File

@@ -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 {


Loading…
Cancel
Save