| 125 | } |
| 126 | |
| 127 | MatrixXd 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: { |
no test coverage detected