ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::NodeFiller< ARG_TYPE_1, ARG_TYPE_2 > Class Template Referencefinal

#include <NodeFiller.h>

Public Member Functions

 NodeFiller (ARG_TYPE_1 **arg_1, ARG_TYPE_2 **arg_2)
 
template<class COMM_NODE >
bool with_commutative_args_of (const COMM_NODE *node)
 
template<class COMM_NODE >
bool with_args_of (const COMM_NODE *node)
 

Detailed Description

template<class ARG_TYPE_1, class ARG_TYPE_2>
class luci::NodeFiller< ARG_TYPE_1, ARG_TYPE_2 >

INTRODUCTION Binary operation f(x,y) is 'commutative' when f(x,y) == f(y,x) holds for all x, y. For examples, ADD, MUL and SQUARED_DIFFERENCE are commutative. These helpers make it easy to find commutative arguments of commutative node.

HOW TO USE COMM_NODE *node; ARG_TYPE_1 *arg1; ARG_TYPE_2 *arg2;

bool ok = fill(&arg1, &arg2).with_commutative_args_of(node);

Result If 'node's commutative argument types are actually {ARG_TYPE_1, ARG_TYPE_2} (as a set), 'arg1' and 'arg2' set as actual 'node's arguments with matching type, and return value 'ok' is true. Otherwise, 'arg1' and 'arg2' not changed, 'ok' is false.

Definition at line 41 of file NodeFiller.h.

Constructor & Destructor Documentation

◆ NodeFiller()

template<class ARG_TYPE_1 , class ARG_TYPE_2 >
luci::NodeFiller< ARG_TYPE_1, ARG_TYPE_2 >::NodeFiller ( ARG_TYPE_1 **  arg_1,
ARG_TYPE_2 **  arg_2 
)
inline

Definition at line 44 of file NodeFiller.h.

44 : _arg_1(arg_1), _arg_2(arg_2)
45 {
46 // DO NOTHING
47 }

Member Function Documentation

◆ with_args_of()

template<class ARG_TYPE_1 , class ARG_TYPE_2 >
template<class COMM_NODE >
bool luci::NodeFiller< ARG_TYPE_1, ARG_TYPE_2 >::with_args_of ( const COMM_NODE *  node)
Note
Similar as with_commutative_args_of but not commutative. _arg_1 and _arg_2 must match that of ARG_TYPE_1 and ARG_TYPE_2.

Definition at line 112 of file NodeFiller.h.

113{
114 // X == ARG_TYPE_1 / Y == ARG_TYPE_2
115 {
116 auto x = dynamic_cast<ARG_TYPE_1 *>(node->x());
117 auto y = dynamic_cast<ARG_TYPE_2 *>(node->y());
118
119 if (x && y)
120 {
121 *_arg_1 = x;
122 *_arg_2 = y;
123 return true;
124 }
125 }
126
127 return false;
128}

◆ with_commutative_args_of()

template<class ARG_TYPE_1 , class ARG_TYPE_2 >
template<class COMM_NODE >
bool luci::NodeFiller< ARG_TYPE_1, ARG_TYPE_2 >::with_commutative_args_of ( const COMM_NODE *  node)
Returns
true When 'node's argument types are 'ARG_TYPE_1' and 'ARG_TYPE_2' In such case, it assign '_arg_1' and '_arg_2' to actual arguments
false When 'node's argument types are NOT matched with 'ARG_TYPE_*' In such case, it does not amend '_arg_1' and '_arg_2'

@require COMM_NODE has member x() and y()

Definition at line 79 of file NodeFiller.h.

80{
81 // Case 1) X == ARG_TYPE_1 / Y == ARG_TYPE_2
82 {
83 auto x = dynamic_cast<ARG_TYPE_1 *>(node->x());
84 auto y = dynamic_cast<ARG_TYPE_2 *>(node->y());
85
86 if (x && y)
87 {
88 *_arg_1 = x;
89 *_arg_2 = y;
90 return true;
91 }
92 }
93
94 // Case 2) X == ARG_TYPE_2 / Y == ARG_TYPE_1
95 {
96 auto x = dynamic_cast<ARG_TYPE_2 *>(node->x());
97 auto y = dynamic_cast<ARG_TYPE_1 *>(node->y());
98
99 if (x && y)
100 {
101 *_arg_1 = y;
102 *_arg_2 = x;
103 return true;
104 }
105 }
106
107 return false;
108}

The documentation for this class was generated from the following file: