ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Sub.cpp File Reference
#include "Sub.h"
#include "Assert.h"

Go to the source code of this file.

Functions

bool subPrepare (const Shape &in1, const Shape &in2, Shape *out)
 

Function Documentation

◆ subPrepare()

bool subPrepare ( const Shape in1,
const Shape in2,
Shape out 
)

Definition at line 21 of file Sub.cpp.

22{
24 ASSERT(in1.type == in2.type);
25 if (SameShape(in1, in2))
26 {
27 return SetShape(in1, out);
28 }
29 else
30 {
31 // BroadcastSub needed
32 uint32_t numberOfDims1 = getNumberOfDimensions(in1);
33 uint32_t numberOfDims2 = getNumberOfDimensions(in2);
34 uint32_t maxDims = std::max(numberOfDims1, numberOfDims2);
35 out->dimensions = std::vector<uint32_t>(maxDims);
36 for (uint32_t i = 1; i <= maxDims; i++)
37 {
38 uint32_t dim1 = 1;
39 if (i <= numberOfDims1)
40 {
41 dim1 = getSizeOfDimension(in1, numberOfDims1 - i);
42 }
43 uint32_t dim2 = 1;
44 if (i <= numberOfDims2)
45 {
46 dim2 = getSizeOfDimension(in2, numberOfDims2 - i);
47 }
48 if (dim1 != dim2 && dim1 != 1 && dim2 != 1)
49 {
50 LOG(ERROR) << "Dimensions mismatch for BroadcastSub";
51 return false;
52 }
53 out->dimensions[maxDims - i] = std::max(dim1, dim2);
54 }
55 }
56 return true;
57}
#define ASSERT(v)
Definition Assert.h:24
#define LOG(...)
Definition Logging.h:36
bool SetShape(const Shape &in, Shape *out)
Definition Shape.cpp:38
uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
Definition Shape.cpp:60
bool SameShape(const Shape &in1, const Shape &in2)
Definition Shape.cpp:22
uint32_t getNumberOfDimensions(const Shape &shape)
Definition Shape.cpp:58
OperandType type
Definition Shape.h:29
std::vector< uint32_t > dimensions
Definition Shape.h:30

References ASSERT, Shape::dimensions, getNumberOfDimensions(), getSizeOfDimension(), LOG, SameShape(), SetShape(), and Shape::type.