Open3D (C++ API)  0.18.0
Functions
open3d::core::shape_util Namespace Reference

Functions

bool IsCompatibleBroadcastShape (const SizeVector &l_shape, const SizeVector &r_shape)
 Returns true if two shapes are compatible for broadcasting. More...
 
SizeVector BroadcastedShape (const SizeVector &l_shape, const SizeVector &r_shape)
 Returns the broadcasted shape of two shapes. More...
 
bool CanBeBrocastedToShape (const SizeVector &src_shape, const SizeVector &dst_shape)
 Returns true if src_shape can be brocasted to dst_shape. More...
 
SizeVector ReductionShape (const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
 Returns the shape after reduction. More...
 
int64_t WrapDim (int64_t dim, int64_t max_dim, bool inclusive=false)
 Wrap around negative dim. More...
 
SizeVector InferShape (SizeVector shape, int64_t num_elements)
 
SizeVector Concat (const SizeVector &l_shape, const SizeVector &r_shape)
 Concatenate two shapes. More...
 
SizeVector Iota (int64_t n)
 Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota. More...
 
SizeVector DefaultStrides (const SizeVector &shape)
 Compute default strides for a shape when a tensor is contiguous. More...
 
std::pair< bool, SizeVectorRestride (const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape)
 

Function Documentation

◆ BroadcastedShape()

SizeVector open3d::core::shape_util::BroadcastedShape ( const SizeVector l_shape,
const SizeVector r_shape 
)

Returns the broadcasted shape of two shapes.

E.g. BroadcastedShape({3, 1, 2}, {5, 1}) -> {3, 5, 2} BroadcastedShape({3, 1, 2}, {5, 3}) -> Exception

Parameters
l_shapeShape of the left-hand-side Tensor.
r_shapeShape of the left-hand-side Tensor.
Returns
The broadcasted shape.

◆ CanBeBrocastedToShape()

bool open3d::core::shape_util::CanBeBrocastedToShape ( const SizeVector src_shape,
const SizeVector dst_shape 
)

Returns true if src_shape can be brocasted to dst_shape.

E.g. CanBeBrocastedToShape({1, 2}, {3, 5, 2}) -> true CanBeBrocastedToShape({1, 2}, {3, 5, 3}) -> false

Parameters
src_shapeSource tensor shape.
dst_shapeDestination tensor shape.
Returns
Returns true if src_shape can be brocasted to dst_shape.

◆ Concat()

SizeVector open3d::core::shape_util::Concat ( const SizeVector l_shape,
const SizeVector r_shape 
)

Concatenate two shapes.

◆ DefaultStrides()

SizeVector open3d::core::shape_util::DefaultStrides ( const SizeVector shape)

Compute default strides for a shape when a tensor is contiguous.

◆ InferShape()

SizeVector open3d::core::shape_util::InferShape ( SizeVector  shape,
int64_t  num_elements 
)

Infers the size of a dim with size -1, if it exists. Also checks that new shape is compatible with the number of elements.

E.g. Shape({2, -1, 4}) with num_elemnts 24, will be inferred as {2, 3, 4}.

Ref: PyTorch's aten/src/ATen/InferSize.h

◆ Iota()

SizeVector open3d::core::shape_util::Iota ( int64_t  n)

Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota.

◆ IsCompatibleBroadcastShape()

bool open3d::core::shape_util::IsCompatibleBroadcastShape ( const SizeVector l_shape,
const SizeVector r_shape 
)

Returns true if two shapes are compatible for broadcasting.

E.g. IsCompatibleBroadcastShape({3, 1, 2}, {5, 1}) -> true IsCompatibleBroadcastShape({3, 1, 2}, {5, 3}) -> false

Parameters
l_shapeShape of the left-hand-side Tensor.
r_shapeShape of the left-hand-side Tensor.
Returns
Returns true if l_shape and r_shape are compatible for broadcasting.

◆ ReductionShape()

SizeVector open3d::core::shape_util::ReductionShape ( const SizeVector src_shape,
const SizeVector dims,
bool  keepdim 
)

Returns the shape after reduction.

E.g. CanBeBrocastedToShape({1, 2}, {3, 5, 2}) -> true CanBeBrocastedToShape({1, 2}, {3, 5, 3}) -> false

Parameters
src_shapeshape to reduce
dimsA list of dimensions to be reduced.
keepdimIf true, the reduced dims will be retained as size 1.

◆ Restride()

std::pair< bool, SizeVector > open3d::core::shape_util::Restride ( const SizeVector old_shape,
const SizeVector old_strides,
const SizeVector new_shape 
)
  1. Separate oldshape into chunks of dimensions, where the dimensions are `‘contiguous’' in each chunk, i.e., oldstride[i] = oldshape[i+1] * oldstride[i+1]
  2. newshape must be able to be separated into same number of chunks as oldshape was separated into, where each chunk of newshape has matching `‘numel’', i.e., number of subspaces, as the corresponding chunk of oldshape. Ref: aten/src/ATen/TensorUtils.cpp

◆ WrapDim()

int64_t open3d::core::shape_util::WrapDim ( int64_t  dim,
int64_t  max_dim,
bool  inclusive = false 
)

Wrap around negative dim.

E.g. If max_dim == 5, dim -1 will be converted to 4.

Parameters
dimDimension index
max_dimMaximum dimension index
inclusiveSet to true to allow dim == max_dim. E.g. for slice T[start:end], we allow end == max_dim.