Open3D (C++ API)  0.18.0+252c867
ShapeUtil.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include "open3d/core/Dispatch.h"
11 #include "open3d/core/SizeVector.h"
12 #include "open3d/utility/Logging.h"
13 
14 namespace open3d {
15 namespace core {
16 
17 class Tensor;
18 
19 namespace shape_util {
20 
29 bool IsCompatibleBroadcastShape(const SizeVector& l_shape,
30  const SizeVector& r_shape);
31 
39 SizeVector BroadcastedShape(const SizeVector& l_shape,
40  const SizeVector& r_shape);
41 
49 bool CanBeBrocastedToShape(const SizeVector& src_shape,
50  const SizeVector& dst_shape);
51 
59 SizeVector ReductionShape(const SizeVector& src_shape,
60  const SizeVector& dims,
61  bool keepdim);
62 
71 int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive = false);
72 
79 SizeVector InferShape(SizeVector shape, int64_t num_elements);
80 
82 SizeVector Concat(const SizeVector& l_shape, const SizeVector& r_shape);
83 
85 SizeVector Iota(int64_t n);
86 
88 SizeVector DefaultStrides(const SizeVector& shape);
89 
98 std::pair<bool, SizeVector> Restride(const SizeVector& old_shape,
99  const SizeVector& old_strides,
100  const SizeVector& new_shape);
101 
102 } // namespace shape_util
103 } // namespace core
104 } // namespace open3d
SizeVector Iota(int64_t n)
Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota.
Definition: ShapeUtil.cpp:205
SizeVector BroadcastedShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns the broadcasted shape of two shapes.
Definition: ShapeUtil.cpp:56
SizeVector InferShape(SizeVector shape, int64_t num_elements)
Definition: ShapeUtil.cpp:150
SizeVector ReductionShape(const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
Returns the shape after reduction.
Definition: ShapeUtil.cpp:99
bool IsCompatibleBroadcastShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns true if two shapes are compatible for broadcasting.
Definition: ShapeUtil.cpp:32
std::pair< bool, SizeVector > Restride(const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape)
Definition: ShapeUtil.cpp:225
int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive)
Wrap around negative dim.
Definition: ShapeUtil.cpp:131
SizeVector DefaultStrides(const SizeVector &shape)
Compute default strides for a shape when a tensor is contiguous.
Definition: ShapeUtil.cpp:214
bool CanBeBrocastedToShape(const SizeVector &src_shape, const SizeVector &dst_shape)
Returns true if src_shape can be brocasted to dst_shape.
Definition: ShapeUtil.cpp:90
SizeVector Concat(const SizeVector &l_shape, const SizeVector &r_shape)
Concatenate two shapes.
Definition: ShapeUtil.cpp:199
Definition: PinholeCameraIntrinsic.cpp:16