MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / _eval

Method _eval

Core/Variational/var.cpp:127–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127MatrixXd var::_eval()
128{
129 auto op = this->getOp();
130 auto operands = this->getChildren();
131 switch (op) {
132 case op_type::plus: {
133 if (_is_scalar(operands[0]))
134 return _sval(operands[0]) + _mval(operands[1]).array();
135 else if (_is_scalar(operands[1]))
136 return _mval(operands[0]).array() + _sval(operands[1]);
137 else
138 return _mval(operands[0]).array() + _mval(operands[1]).array();
139 }
140 case op_type::minus: {
141 if (_is_scalar(operands[0]))
142 return _sval(operands[0]) - _mval(operands[1]).array();
143 else if (_is_scalar(operands[1]))
144 return _mval(operands[0]).array() - _sval(operands[1]);
145 else
146 return _mval(operands[0]).array() - _mval(operands[1]).array();
147 }
148 case op_type::multiply: {
149 if (_is_scalar(operands[0]))
150 return _sval(operands[0]) * _mval(operands[1]).array();
151 else if (_is_scalar(operands[1]))
152 return _mval(operands[0]).array() * _sval(operands[1]);
153 else
154 return _mval(operands[0]).array() * _mval(operands[1]).array();
155 }
156 case op_type::divide: {
157 if (_is_scalar(operands[0]))
158 return _sval(operands[0]) / _mval(operands[1]).array();
159 else if (_is_scalar(operands[1]))
160 return _mval(operands[0]).array() / _sval(operands[1]);
161 else
162 return _mval(operands[0]).array() / _mval(operands[1]).array();
163 }
164 case op_type::exponent: {
165 return _mval(operands[0]).array().exp();
166 }
167 case op_type::log: {
168 return _mval(operands[0]).array().log();
169 }
170 case op_type::polynomial: {
171 return _mval(operands[0]).array().pow(_sval(operands[1]));
172 }
173 case op_type::dot: {
174 return _mval(operands[0]) * _mval(operands[1]);
175 }
176
177 // add trigonometric function
178 case op_type::sin: {
179 return _mval(operands[0]).array().sin();
180 }
181 case op_type::cos: {
182 return _mval(operands[0]).array().cos();
183 }
184 case op_type::tan: {

Callers 2

_rpropagateFunction · 0.80
propagateMethod · 0.80

Calls 15

getOpMethod · 0.95
_is_scalarFunction · 0.85
_svalFunction · 0.85
_mvalFunction · 0.85
scalarFunction · 0.85
_is_vectorFunction · 0.85
exceptionClass · 0.85
_is_matrixFunction · 0.85
vector2matFunction · 0.85
getChildrenMethod · 0.80
sinMethod · 0.80
cosMethod · 0.80

Tested by

no test coverage detected