![]() |
ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
|
Functions | |
| static SizeVector | ExpandFrontDims (const SizeVector &shape, int64_t ndims) |
| 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, SizeVector > | Restride (const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape) |
| SizeVector cloudViewer::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
Definition at line 56 of file ShapeUtil.cpp.
References ExpandFrontDims(), IsCompatibleBroadcastShape(), LogError, max(), and cloudViewer::core::SmallVectorBase< Size_T >::size().
Referenced by cloudViewer::core::Tensor::Add(), cloudViewer::core::kernel::BinaryEW(), CanBeBrocastedToShape(), cloudViewer::core::Tensor::Div(), cloudViewer::core::Tensor::Eq(), cloudViewer::core::AdvancedIndexPreprocessor::ExpandToCommonShapeExceptZeroDim(), cloudViewer::core::Tensor::Ge(), cloudViewer::core::Tensor::Gt(), cloudViewer::core::Tensor::Le(), cloudViewer::core::Tensor::LogicalAnd(), cloudViewer::core::Tensor::LogicalOr(), cloudViewer::core::Tensor::LogicalXor(), cloudViewer::core::Tensor::Lt(), cloudViewer::core::Maximum(), cloudViewer::core::Minimum(), cloudViewer::core::Tensor::Mul(), cloudViewer::core::Tensor::Ne(), and cloudViewer::core::Tensor::Sub().
| bool cloudViewer::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
| src_shape | Source tensor shape. |
| dst_shape | Destination tensor shape. |
src_shape can be brocasted to dst_shape. Definition at line 90 of file ShapeUtil.cpp.
References BroadcastedShape(), and IsCompatibleBroadcastShape().
Referenced by cloudViewer::core::Tensor::Broadcast(), cloudViewer::core::kernel::Copy(), cloudViewer::core::Tensor::Expand(), and cloudViewer::core::kernel::UnaryEW().
| SizeVector cloudViewer::core::shape_util::Concat | ( | const SizeVector & | l_shape, |
| const SizeVector & | r_shape | ||
| ) |
Concatenate two shapes.
Definition at line 199 of file ShapeUtil.cpp.
References cloudViewer::core::SmallVectorTemplateCommon< T, typename >::begin(), cloudViewer::core::SmallVectorTemplateCommon< T, typename >::end(), and cloudViewer::core::SmallVectorImpl< T >::insert().
Referenced by cloudViewer::core::TensorList::FromTensor(), cloudViewer::t::geometry::Image::Image(), cloudViewer::core::TensorList::ResizeWithExpand(), and cloudViewer::core::TensorList::TensorList().
| SizeVector cloudViewer::core::shape_util::DefaultStrides | ( | const SizeVector & | shape | ) |
Compute default strides for a shape when a tensor is contiguous.
Definition at line 214 of file ShapeUtil.cpp.
References cloudViewer::core::SmallVectorBase< Size_T >::size().
Referenced by cloudViewer::core::HashMap::GetKeyTensor(), cloudViewer::core::HashMap::GetValueTensor(), cloudViewer::core::HashMap::GetValueTensors(), cloudViewer::core::TensorRef::IsContiguous(), cloudViewer::core::Tensor::IsContiguous(), and cloudViewer::t::io::NumpyArray::ToTensor().
|
static |
Expand a shape with ones in front. Returning a shape with size of ndims. E.g. ExpandFrontDims({2, 3}, 5) == {1, 1, 1, 2, 3}
Definition at line 21 of file ShapeUtil.cpp.
References cloudViewer::core::SmallVectorTemplateCommon< T, typename >::begin(), copy, cloudViewer::core::SmallVectorTemplateCommon< T, typename >::end(), LogError, and cloudViewer::core::SmallVectorBase< Size_T >::size().
Referenced by BroadcastedShape().
| SizeVector cloudViewer::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
Definition at line 150 of file ShapeUtil.cpp.
References LogError, cloudViewer::core::SmallVectorBase< Size_T >::size(), and cloudViewer::core::SizeVector::ToString().
Referenced by cloudViewer::core::Tensor::Reshape(), and cloudViewer::core::Tensor::View().
| SizeVector cloudViewer::core::shape_util::Iota | ( | int64_t | n | ) |
Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota.
Definition at line 205 of file ShapeUtil.cpp.
References cloudViewer::core::SmallVectorTemplateCommon< T, typename >::begin(), cloudViewer::core::SmallVectorTemplateCommon< T, typename >::end(), and LogError.
Referenced by cloudViewer::core::Tensor::All(), and cloudViewer::core::Tensor::Any().
| bool cloudViewer::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
l_shape and r_shape are compatible for broadcasting. Definition at line 32 of file ShapeUtil.cpp.
References min(), and cloudViewer::core::SmallVectorBase< Size_T >::size().
Referenced by BroadcastedShape(), and CanBeBrocastedToShape().
| SizeVector cloudViewer::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
| src_shape | shape to reduce |
| dims | A list of dimensions to be reduced. |
| keepdim | If true, the reduced dims will be retained as size 1. |
Definition at line 99 of file ShapeUtil.cpp.
References LogError, cloudViewer::core::SmallVectorImpl< T >::resize(), cloudViewer::core::SmallVectorBase< Size_T >::size(), and WrapDim().
Referenced by cloudViewer::core::Tensor::All(), cloudViewer::core::Tensor::Any(), cloudViewer::core::Tensor::ArgMax(), cloudViewer::core::Tensor::ArgMin(), cloudViewer::core::Indexer::Indexer(), cloudViewer::core::Tensor::Max(), cloudViewer::core::Tensor::Min(), cloudViewer::core::Tensor::Prod(), cloudViewer::core::kernel::Reduction(), and cloudViewer::core::Tensor::Sum().
| std::pair< bool, SizeVector > cloudViewer::core::shape_util::Restride | ( | const SizeVector & | old_shape, |
| const SizeVector & | old_strides, | ||
| const SizeVector & | new_shape | ||
| ) |
oldshape into chunks of dimensions, where the dimensions are `‘contiguous’' in each chunk, i.e., oldstride[i] = oldshape[i+1] * oldstride[i+1]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 Definition at line 225 of file ShapeUtil.cpp.
References cloudViewer::core::SmallVectorTemplateCommon< T, typename >::back(), cloudViewer::core::SmallVectorBase< Size_T >::empty(), cloudViewer::core::make_pair(), cloudViewer::core::SizeVector::NumElements(), and cloudViewer::core::SmallVectorBase< Size_T >::size().
Referenced by cloudViewer::core::Tensor::Reshape(), and cloudViewer::core::Tensor::View().
| int64_t cloudViewer::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.
| dim | Dimension index |
| max_dim | Maximum dimension index |
| inclusive | Set to true to allow dim == max_dim. E.g. for slice T[start:end], we allow end == max_dim. |
Definition at line 131 of file ShapeUtil.cpp.
References LogError, max(), and min().
Referenced by cloudViewer::core::ConcatenateImpl(), cloudViewer::core::Tensor::Flatten(), cloudViewer::core::Tensor::GetShape(), cloudViewer::core::Tensor::GetStride(), cloudViewer::core::Tensor::IndexExtract(), cloudViewer::core::TensorList::operator[](), cloudViewer::core::TensorRef::Permute(), cloudViewer::core::Tensor::Permute(), ReductionShape(), cloudViewer::core::Tensor::Slice(), and cloudViewer::core::Tensor::Transpose().