Open3D (C++ API)
ShapeUtil.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include "Open3D/Core/Dispatch.h"
30 #include "Open3D/Core/SizeVector.h"
31 #include "Open3D/Utility/Console.h"
32 
33 namespace open3d {
34 
35 class Tensor;
36 
37 namespace shape_util {
38 
47 bool IsCompatibleBroadcastShape(const SizeVector& l_shape,
48  const SizeVector& r_shape);
49 
57 SizeVector BroadcastedShape(const SizeVector& l_shape,
58  const SizeVector& r_shape);
59 
67 bool CanBeBrocastedToShape(const SizeVector& src_shape,
68  const SizeVector& dst_shape);
69 
77 SizeVector ReductionShape(const SizeVector& src_shape,
78  const SizeVector& dims,
79  bool keepdim);
80 
84 int64_t WrapDim(int64_t dim, int64_t max_dim);
85 
86 // Infers the size of a dim with size -1, if it exists. Also checks that new
87 // shape is compatible with the number of elements.
88 //
89 // E.g. Shape({2, -1, 4}) with num_elemnts 24, will be inferred as {2, 3, 4}.
90 //
91 // Ref: PyTorch's aten/src/ATen/InferSize.h
92 SizeVector InferShape(SizeVector shape, int64_t num_elements);
93 
94 } // namespace shape_util
95 } // namespace open3d
SizeVector InferShape(SizeVector shape, int64_t num_elements)
Definition: ShapeUtil.cpp:163
Definition: Open3DViewer.h:29
int64_t WrapDim(int64_t dim, int64_t max_dim)
Wrap around negative dim.
Definition: ShapeUtil.cpp:147
bool IsCompatibleBroadcastShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns true if two shapes are compatible for broadcasting.
Definition: ShapeUtil.cpp:48
SizeVector BroadcastedShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns the broadcasted shape of two shapes.
Definition: ShapeUtil.cpp:72
bool CanBeBrocastedToShape(const SizeVector &src_shape, const SizeVector &dst_shape)
Returns true if src_shape can be brocasted to dst_shape.
Definition: ShapeUtil.cpp:106
SizeVector ReductionShape(const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
Returns the shape after reduction.
Definition: ShapeUtil.cpp:115