ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ShapeUtil.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Logging.h>
11 
14 
15 namespace cloudViewer {
16 namespace core {
17 
18 class Tensor;
19 
20 namespace shape_util {
21 
30 bool IsCompatibleBroadcastShape(const SizeVector& l_shape,
31  const SizeVector& r_shape);
32 
40 SizeVector BroadcastedShape(const SizeVector& l_shape,
41  const SizeVector& r_shape);
42 
50 bool CanBeBrocastedToShape(const SizeVector& src_shape,
51  const SizeVector& dst_shape);
52 
60 SizeVector ReductionShape(const SizeVector& src_shape,
61  const SizeVector& dims,
62  bool keepdim);
63 
72 int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive = false);
73 
80 SizeVector InferShape(SizeVector shape, int64_t num_elements);
81 
83 SizeVector Concat(const SizeVector& l_shape, const SizeVector& r_shape);
84 
86 SizeVector Iota(int64_t n);
87 
89 SizeVector DefaultStrides(const SizeVector& shape);
90 
99 std::pair<bool, SizeVector> Restride(const SizeVector& old_shape,
100  const SizeVector& old_strides,
101  const SizeVector& new_shape);
102 
103 } // namespace shape_util
104 } // namespace core
105 } // namespace cloudViewer
SizeVector Concat(const SizeVector &l_shape, const SizeVector &r_shape)
Concatenate two shapes.
Definition: ShapeUtil.cpp:199
int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive)
Wrap around negative dim.
Definition: ShapeUtil.cpp:131
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 BroadcastedShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns the broadcasted shape of two shapes.
Definition: ShapeUtil.cpp:56
SizeVector ReductionShape(const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
Returns the shape after reduction.
Definition: ShapeUtil.cpp:99
std::pair< bool, SizeVector > Restride(const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape)
Definition: ShapeUtil.cpp:225
SizeVector Iota(int64_t n)
Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota.
Definition: ShapeUtil.cpp:205
SizeVector InferShape(SizeVector shape, int64_t num_elements)
Definition: ShapeUtil.cpp:150
SizeVector DefaultStrides(const SizeVector &shape)
Compute default strides for a shape when a tensor is contiguous.
Definition: ShapeUtil.cpp:214
bool IsCompatibleBroadcastShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns true if two shapes are compatible for broadcasting.
Definition: ShapeUtil.cpp:32
Generic file read and write utility for python interface.