Changeset 25479
- Timestamp:
- 2015-04-09T21:30:17+02:00 (9 years ago)
- Location:
- trunk/SimulationRuntime/cpp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp
r24878 r25479 185 185 }; 186 186 187 template <typename T> 188 void multiply_array(const BaseArray<T> &leftArray, const BaseArray<T> &rightArray, BaseArray<T> &resultArray) 189 { 190 size_t leftNumDims = leftArray.getNumDims(); 191 size_t rightNumDims = rightArray.getNumDims(); 192 size_t matchDim = rightArray.getDim(1); 193 if (leftArray.getDim(leftNumDims) != matchDim) 194 throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, 195 "Wrong sizes in multiply_array"); 196 if (matchDim == 0) { 197 fill_array(resultArray, T()); // zero 198 } 199 else if (leftNumDims == 1 && rightNumDims == 2) { 200 size_t rightDim = rightArray.getDim(2); 201 for (size_t j = 1; j <= rightDim; j++) { 202 T val = leftArray(1) * rightArray(1, j); 203 for (size_t k = 2; k <= matchDim; k++) 204 val += leftArray(k) * rightArray(k, j); 205 resultArray(j) = val; 206 } 207 } 208 else if (leftNumDims == 2 && rightNumDims == 1) { 209 size_t leftDim = leftArray.getDim(1); 210 for (size_t i = 1; i <= leftDim; i++) { 211 T val = leftArray(i, 1) * rightArray(1); 212 for (size_t k = 2; k <= matchDim; k++) 213 val += leftArray(i, k) * rightArray(k); 214 resultArray(i) = val; 215 } 216 } 217 else if (leftNumDims == 2 && rightNumDims == 2) { 218 size_t leftDim = leftArray.getDim(1); 219 size_t rightDim = rightArray.getDim(2); 220 for (size_t i = 1; i <= leftDim; i++) { 221 for (size_t j = 1; j <= rightDim; j++) { 222 T val = leftArray(i, 1) * rightArray(1, j); 223 for (size_t k = 2; k <= matchDim; k++) 224 val += leftArray(i, k) * rightArray(k, j); 225 resultArray(i, j) = val; 226 } 227 } 228 } 229 else 230 throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, 231 "Unsupported dimensions in multiply_array"); 232 } 233 187 234 template < typename T> 188 235 void divide_array(BaseArray<T>& inputArray, const T &b, BaseArray<T>& outputArray) … … 346 393 template void BOOST_EXTENSION_EXPORT_DECL multiply_array(BaseArray<bool>& inputArray, const bool &b, BaseArray<bool> & outputArray); 347 394 395 template void BOOST_EXTENSION_EXPORT_DECL multiply_array(const BaseArray<double> &leftArray, const BaseArray<double> &rightArray, BaseArray<double> &resultArray); 396 template void BOOST_EXTENSION_EXPORT_DECL multiply_array(const BaseArray<int> &leftArray, const BaseArray<int> &rightArray, BaseArray<int> &resultArray); 397 template void BOOST_EXTENSION_EXPORT_DECL multiply_array(const BaseArray<bool> &leftArray, const BaseArray<bool> &rightArray, BaseArray<bool> &resultArray); 398 348 399 template void BOOST_EXTENSION_EXPORT_DECL divide_array(BaseArray<double>& inputArray, const double &b, BaseArray<double>& outputArray); 349 400 template void BOOST_EXTENSION_EXPORT_DECL divide_array(BaseArray<int>& inputArray, const int &b, BaseArray<int>& outputArray); -
trunk/SimulationRuntime/cpp/Include/Core/Math/Array.h
r25448 r25479 40 40 }; 41 41 42 virtual T& operator()(size_t i, size_t j) 42 virtual T& operator()(size_t i, size_t j) 43 { 44 throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong virtual Array operator call"); 45 }; 46 47 virtual const T& operator()(size_t i, size_t j) const 43 48 { 44 49 throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong virtual Array operator call"); … … 1465 1470 return _multi_array[i][j]; 1466 1471 } 1472 inline virtual const T& operator()(size_t i, size_t j) const 1473 { 1474 return _multi_array[i][j]; 1475 } 1467 1476 1468 1477 void setDims(size_t size1, size_t size2) -
trunk/SimulationRuntime/cpp/Include/Core/Math/ArrayOperations.h
r22833 r25479 44 44 void create_array_from_shape(const spec_type& sp,BaseArray<T>& s,BaseArray<T>& d); 45 45 46 47 48 46 template < typename T > 49 47 void promote_array(unsigned int n,BaseArray<T>& s,BaseArray<T>& d); 50 51 52 48 53 49 template < typename T> 54 50 void multiply_array( BaseArray<T> & inputArray ,const T &b, BaseArray<T> & outputArray ); 55 51 52 template <typename T> 53 void multiply_array(const BaseArray<T> &leftArray, const BaseArray<T> &rightArray, BaseArray<T> &resultArray); 56 54 57 55 template < typename T> 58 56 void divide_array( BaseArray<T> & inputArray ,const T &b, BaseArray<T> & outputArray ); 59 60 57 61 58 template < typename T > -
trunk/SimulationRuntime/cpp/Include/Core/Math/ArraySlice.h
r25453 r25479 252 252 } 253 253 254 virtual T& operator()(size_t i, size_t j) { 254 virtual T& operator()(size_t i, size_t j) { 255 accessElement(2, i, j); 256 } 257 258 virtual const T& operator()(size_t i, size_t j) const { 255 259 accessElement(2, i, j); 256 260 }
Note: See TracChangeset
for help on using the changeset viewer.