Open3D (C++ API)  0.16.0
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-2021 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
32
33namespace open3d {
34namespace core {
35
36class Tensor;
37
38namespace shape_util {
39
48bool IsCompatibleBroadcastShape(const SizeVector& l_shape,
49 const SizeVector& r_shape);
50
58SizeVector BroadcastedShape(const SizeVector& l_shape,
59 const SizeVector& r_shape);
60
68bool CanBeBrocastedToShape(const SizeVector& src_shape,
69 const SizeVector& dst_shape);
70
78SizeVector ReductionShape(const SizeVector& src_shape,
79 const SizeVector& dims,
80 bool keepdim);
81
90int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive = false);
91
98SizeVector InferShape(SizeVector shape, int64_t num_elements);
99
101SizeVector Concat(const SizeVector& l_shape, const SizeVector& r_shape);
102
104SizeVector Iota(int64_t n);
105
107SizeVector DefaultStrides(const SizeVector& shape);
108
117std::pair<bool, SizeVector> Restride(const SizeVector& old_shape,
118 const SizeVector& old_strides,
119 const SizeVector& new_shape);
120
121} // namespace shape_util
122} // namespace core
123} // namespace open3d
SizeVector Iota(int64_t n)
Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota.
Definition: ShapeUtil.cpp:224
SizeVector BroadcastedShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns the broadcasted shape of two shapes.
Definition: ShapeUtil.cpp:75
SizeVector InferShape(SizeVector shape, int64_t num_elements)
Definition: ShapeUtil.cpp:169
SizeVector ReductionShape(const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
Returns the shape after reduction.
Definition: ShapeUtil.cpp:118
bool IsCompatibleBroadcastShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns true if two shapes are compatible for broadcasting.
Definition: ShapeUtil.cpp:51
std::pair< bool, SizeVector > Restride(const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape)
Definition: ShapeUtil.cpp:244
int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive)
Wrap around negative dim.
Definition: ShapeUtil.cpp:150
SizeVector DefaultStrides(const SizeVector &shape)
Compute default strides for a shape when a tensor is contiguous.
Definition: ShapeUtil.cpp:233
bool CanBeBrocastedToShape(const SizeVector &src_shape, const SizeVector &dst_shape)
Returns true if src_shape can be brocasted to dst_shape.
Definition: ShapeUtil.cpp:109
SizeVector Concat(const SizeVector &l_shape, const SizeVector &r_shape)
Concatenate two shapes.
Definition: ShapeUtil.cpp:218
Definition: PinholeCameraIntrinsic.cpp:35