Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 17.7% 150 / 0 / 849
Functions: 23.8% 20 / 0 / 84
Branches: 5.7% 72 / 0 / 1274

OMCompiler/SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28 /** @addtogroup math
29 * @{
30 */
31
32 #include <Core/ModelicaDefine.h>
33 #include <Core/Modelica.h>
34 #include <Core/Math/ArrayOperations.h>
35 #include <Core/Math/ArraySlice.h>
36 #include <sstream>
37 #include <stdio.h>
38
39 using namespace std;
40
41 /**
42 Concatenates n real arrays along the k:th dimension.
43 */
44 template <typename T>
45
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✗ Branch 0 not taken.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
386159 void cat_array(int k, const vector<const BaseArray<T>*>& x, BaseArray<T>& a)
46 {
47 unsigned int new_k_dim_size = 0;
48 386159 unsigned int n = x.size();
49 /* check dim sizes of all inputs */
50
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✗ Branch 0 not taken.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
386159 if (n < 1)
51 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "No input arrays");
52
53
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✗ Branch 1 not taken.
✓ Branch 2 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
386159 if (x[0]->getNumDims() < k)
54 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "Wrong dimension for input array");
55
56 386159 new_k_dim_size = x[0]->getDim(k);
57
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 0 taken 386159 times.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
772318 for (int i = 1; i < n; i++)
58 {
59 //arrays must have same number of dimensions
60
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 2 taken 386159 times.
✗ Branch 3 not taken.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
386159 if (x[0]->getNumDims() != x[i]->getNumDims())
61 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "Wrong dimension for input array");
62 //Size matching: Arrays must have identical array sizes with the exception of the size of dimension k
63
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
386162 for (int j = 1; j < k; j++)
64
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if (x[0]->getDim(j) != x[i]->getDim(j))
65 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "Wrong size for input array");
66 //calculate new size of dimension k
67 386159 new_k_dim_size += x[i]->getDim(k);
68 //Size matching: Arrays must have identical array sizes with the exception of the size of dimension k
69
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
386162 for (int j = k + 1; j <= x[0]->getNumDims(); j++)
70
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if (x[0]->getDim(j) != x[i]->getDim(j))
71 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "Wrong size for input array");
72 }
73 /* calculate size of sub and super structure in 1-dim data representation */
74 unsigned int n_sub = 1;
75 unsigned int n_super = 1;
76
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
386162 for (int i = 1; i < k; i++)
77 3 n_super *= x[0]->getDim(i);
78
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
386162 for (int i = k + 1; i <= x[0]->getNumDims(); i++)
79 3 n_sub *= x[0]->getDim(i);
80 /* allocate output array */
81 386159 vector<size_t> ex = x[0]->getDims();
82
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✗ Branch 0 not taken.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
386159 ex[k-1] = new_k_dim_size;
83
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✗ Branch 0 not taken.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
386159 if (ex.size() < k)
84 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "Error resizing concatenate array");
85
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 1 taken 386159 times.
✗ Branch 2 not taken.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
386159 a.setDims(ex);
86
87 /* concatenation along k-th dimension */
88
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 1 taken 386159 times.
✗ Branch 2 not taken.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
386159 T* a_data = a.getData();
89 int j = 0;
90
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 0 taken 386162 times.
✓ Branch 1 taken 386159 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
772321 for (int i = 0; i < n_sub; i++)
91 {
92
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 0 taken 772324 times.
✓ Branch 1 taken 386162 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1158486 for (int c = 0; c < n; c++)
93 {
94
2/12
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 1 taken 772324 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 772324 times.
✗ Branch 5 not taken.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
772324 int n_super_k = n_super * x[c]->getDim(k);
95
1/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 1 taken 772324 times.
✗ Branch 2 not taken.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
772324 const T* x_data = x[c]->getData() + i * n_super_k;
96
2/6
void cat_array<bool>(int, std::vector<BaseArray<bool> const*, std::allocator<BaseArray<bool> const*> > const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void cat_array<double>(int, std::vector<BaseArray<double> const*, std::allocator<BaseArray<double> const*> > const&, BaseArray<double>&):
✓ Branch 0 taken 772321 times.
✓ Branch 1 taken 3 times.
void cat_array<int>(int, std::vector<BaseArray<int> const*, std::allocator<BaseArray<int> const*> > const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
772324 std::copy(x_data, x_data + n_super_k, a_data + j);
97 772324 j += n_super_k;
98 }
99 }
100 386159 }
101
102 ✗ void identity_alloc(size_t n, DynArrayDim2<int>& I)
103 {
104 ✗ I.setDims(n, n);
105 ✗ fill_array(I, 0);
106 ✗ for (size_t i = 1; i <= n; i++)
107 ✗ I(i, i) = 1;
108 ✗ }
109
110 template <typename T>
111 ✗ void diagonal_alloc(const BaseArray<T>& v, BaseArray<T>& D)
112 {
113 ✗ if (v.getNumDims() != 1)
114 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "Error in diagonal, input must be vector");
115 ✗ if (D.getNumDims() != 2)
116 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "Error in diagonal, output must be matrix");
117 ✗ vector<size_t> dims = v.getDims();
118 ✗ size_t n = dims[0];
119 ✗ dims.push_back(n);
120 ✗ D.setDims(dims);
121 ✗ const T* v_data = v.getData();
122 ✗ T* D_data = D.getData();
123 ✗ std::fill(D_data, D_data + n * n, 0);
124 ✗ for (size_t i = 0; i < n; i++)
125 ✗ D_data[i * n + i] = v_data[i];
126 ✗ }
127
128 /**
129 * appends dimensions of size 1 to the right of s up to dimension n
130 */
131 template <typename T>
132 ✗ void promote_array(size_t n, const BaseArray<T>& s, BaseArray<T>& d)
133 {
134 ✗ vector<size_t> ex = s.getDims();
135 ✗ for (size_t i = ex.size(); i < n; i++)
136 ✗ ex.push_back(1);
137 ✗ d.setDims(ex);
138 ✗ d.assign(s.getData());
139 ✗ }
140
141 /**
142 * permutes the first two dimensions of x into a
143 */
144 template <typename T>
145 ✗ void transpose_array(const BaseArray<T>& x, BaseArray<T>& a)
146
147 {
148 ✗ size_t ndims = x.getNumDims();
149 ✗ if(ndims < 2 || ndims != a.getNumDims())
150 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
151 "Wrong dimensions in transpose_array");
152 ✗ vector<size_t> ex = x.getDims();
153 std::swap(ex[0], ex[1]);
154 ✗ a.setDims(ex);
155 ✗ vector<Slice> sx(ndims);
156 ✗ vector<Slice> sa(ndims);
157 ✗ for (int i = 1; i <= x.getDim(1); i++) {
158 ✗ sa[1] = sx[0] = Slice(i);
159 ✗ ArraySlice<T>(a, sa).assign(ArraySliceConst<T>(x, sx));
160 }
161 ✗ }
162
163 template <typename T>
164 12 void multiply_array(const BaseArray<T>& inputArray, const T &b, BaseArray<T>& outputArray)
165 {
166 12 size_t dim = inputArray.getNumElems();
167
1/6
void multiply_array<bool>(BaseArray<bool> const&, bool const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void multiply_array<double>(BaseArray<double> const&, double const&, BaseArray<double>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void multiply_array<int>(BaseArray<int> const&, int const&, BaseArray<int>&):
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(dim > 0)
168 {
169
1/6
void multiply_array<bool>(BaseArray<bool> const&, bool const&, BaseArray<bool>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void multiply_array<double>(BaseArray<double> const&, double const&, BaseArray<double>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void multiply_array<int>(BaseArray<int> const&, int const&, BaseArray<int>&):
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 outputArray.setDims(inputArray.getDims());
170 12 const T* data = inputArray.getData();
171 12 T* aim = outputArray.getData();
172 24 std::transform (data, data + inputArray.getNumElems(), aim, [&](const T& a) { return a*b; });
173 }
174 12 };
175
176 template <typename T>
177 ✗ void multiply_array(const BaseArray<T> &leftArray, const BaseArray<T> &rightArray, BaseArray<T> &resultArray)
178 {
179 ✗ size_t leftNumDims = leftArray.getNumDims();
180 ✗ size_t rightNumDims = rightArray.getNumDims();
181 ✗ size_t matchDim = rightArray.getDim(1);
182 ✗ if (leftArray.getDim(leftNumDims) != matchDim)
183 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
184 "Wrong sizes in multiply_array");
185 ✗ if (leftNumDims == 1 && rightNumDims == 2) {
186 ✗ size_t rightDim = rightArray.getDim(2);
187 vector<size_t> dims;
188 ✗ dims.push_back(rightDim);
189 ✗ resultArray.setDims(dims);
190 ✗ for (size_t j = 1; j <= rightDim; j++) {
191 T val = T();
192 ✗ for (size_t k = 1; k <= matchDim; k++)
193 ✗ val += leftArray(k) * rightArray(k, j);
194 ✗ resultArray(j) = val;
195 }
196 }
197 ✗ else if (leftNumDims == 2 && rightNumDims == 1) {
198 ✗ size_t leftDim = leftArray.getDim(1);
199 vector<size_t> dims;
200 ✗ dims.push_back(leftDim);
201 ✗ resultArray.setDims(dims);
202 ✗ for (size_t i = 1; i <= leftDim; i++) {
203 T val = T();
204 ✗ for (size_t k = 1; k <= matchDim; k++)
205 ✗ val += leftArray(i, k) * rightArray(k);
206 ✗ resultArray(i) = val;
207 }
208 }
209 ✗ else if (leftNumDims == 2 && rightNumDims == 2) {
210 ✗ size_t leftDim = leftArray.getDim(1);
211 ✗ size_t rightDim = rightArray.getDim(2);
212 vector<size_t> dims;
213 ✗ dims.push_back(leftDim);
214 ✗ dims.push_back(rightDim);
215 ✗ resultArray.setDims(dims);
216 ✗ for (size_t i = 1; i <= leftDim; i++) {
217 ✗ for (size_t j = 1; j <= rightDim; j++) {
218 T val = T();
219 ✗ for (size_t k = 1; k <= matchDim; k++)
220 ✗ val += leftArray(i, k) * rightArray(k, j);
221 ✗ resultArray(i, j) = val;
222 }
223 }
224 }
225 else
226 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
227 "Unsupported dimensions in multiply_array");
228 ✗ }
229
230 template <typename T>
231 ✗ void multiply_array_elem_wise(const BaseArray<T> &leftArray, const BaseArray<T> &rightArray, BaseArray<T> &resultArray)
232 {
233 ✗ size_t dimLeft = leftArray.getNumElems();
234 ✗ size_t dimRight = rightArray.getNumElems();
235
236 ✗ if(dimLeft != dimRight)
237 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
238 "Right and left array must have the same size for element wise multiplication");
239
240 ✗ resultArray.setDims(leftArray.getDims());
241 ✗ const T* leftData = leftArray.getData();
242 ✗ const T* rightData = rightArray.getData();
243 ✗ T* aim = resultArray.getData();
244
245 ✗ std::transform (leftData, leftData + leftArray.getNumElems(), rightData, aim, std::multiplies<T>());
246 ✗ }
247
248 template <typename T>
249 12996 void divide_array(const BaseArray<T>& inputArray, const T &b, BaseArray<T>& outputArray)
250 {
251 12996 size_t nelems = inputArray.getNumElems();
252
1/6
void divide_array<bool>(BaseArray<bool> const&, bool const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void divide_array<double>(BaseArray<double> const&, double const&, BaseArray<double>&):
✓ Branch 1 taken 12996 times.
✗ Branch 2 not taken.
void divide_array<int>(BaseArray<int> const&, int const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
12996 if (outputArray.getNumElems() != nelems)
253 {
254
1/6
void divide_array<bool>(BaseArray<bool> const&, bool const&, BaseArray<bool>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void divide_array<double>(BaseArray<double> const&, double const&, BaseArray<double>&):
✓ Branch 2 taken 12996 times.
✗ Branch 3 not taken.
void divide_array<int>(BaseArray<int> const&, int const&, BaseArray<int>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
25992 outputArray.setDims(inputArray.getDims());
255 }
256 12996 const T* data = inputArray.getData();
257 12996 T* aim = outputArray.getData();
258 51984 std::transform(data, data + nelems, aim, [&](const T& a) { return a/b; });
259 12996 }
260
261 template <typename T>
262 ✗ void divide_array(const T &b, const BaseArray<T>& inputArray, BaseArray<T>& outputArray)
263 {
264 ✗ size_t nelems = inputArray.getNumElems();
265 ✗ if (outputArray.getNumElems() != nelems)
266 {
267 ✗ outputArray.setDims(inputArray.getDims());
268 }
269 ✗ const T* data = inputArray.getData();
270 ✗ T* aim = outputArray.getData();
271 ✗ std::transform(data, data + nelems, aim, [&](const T& a) { return b/a; });
272 ✗ }
273
274 template <typename T>
275 ✗ void divide_array_elem_wise(const BaseArray<T> &leftArray, const BaseArray<T> &rightArray, BaseArray<T> &resultArray)
276 {
277 ✗ size_t dimLeft = leftArray.getNumElems();
278 ✗ size_t dimRight = rightArray.getNumElems();
279
280 ✗ if(dimLeft != dimRight)
281 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
282 "Right and left array must have the same size for element wise division");
283
284 ✗ resultArray.setDims(leftArray.getDims());
285 ✗ const T* leftData = leftArray.getData();
286 ✗ const T* rightData = rightArray.getData();
287 ✗ T* result = resultArray.getData();
288
289 ✗ std::transform (leftData, leftData + leftArray.getNumElems(), rightData, result, std::divides<T>());
290 ✗ }
291
292 template <typename T>
293 7 void fill_array(BaseArray<T>& inputArray, T b)
294 {
295 7 T* data = inputArray.getData();
296 7 std::fill(data, data + inputArray.getNumElems(), b);
297 7 }
298
299 template <typename T>
300 ✗ void pow_array_scalar(const BaseArray<double> &inputArray, T exponent,
301 BaseArray<double> &outputArray)
302 {
303 ✗ size_t nelems = inputArray.getNumElems();
304 ✗ if (outputArray.getNumElems() != nelems)
305 ✗ outputArray.setDims(inputArray.getDims());
306 ✗ const double *data = inputArray.getData();
307 ✗ double *dest = outputArray.getData();
308 ✗ double *end = dest + nelems;
309 ✗ while (dest != end)
310 ✗ *dest++ = pow(*data++, exponent);
311 ✗ }
312
313 template <typename T>
314 1 void subtract_array(const BaseArray<T>& leftArray, const BaseArray<T>& rightArray, BaseArray<T>& resultArray)
315 {
316 1 size_t dimLeft = leftArray.getNumElems();
317 1 size_t dimRight = rightArray.getNumElems();
318
319
1/6
void subtract_array<bool>(BaseArray<bool> const&, BaseArray<bool> const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void subtract_array<double>(BaseArray<double> const&, BaseArray<double> const&, BaseArray<double>&):
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
void subtract_array<int>(BaseArray<int> const&, BaseArray<int> const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 if(dimLeft != dimRight)
320 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
321 "Right and left array must have the same size for element wise substraction");
322
323
1/6
void subtract_array<bool>(BaseArray<bool> const&, BaseArray<bool> const&, BaseArray<bool>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void subtract_array<double>(BaseArray<double> const&, BaseArray<double> const&, BaseArray<double>&):
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
void subtract_array<int>(BaseArray<int> const&, BaseArray<int> const&, BaseArray<int>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 resultArray.setDims(leftArray.getDims());
324 1 const T* data1 = leftArray.getData();
325 1 const T* data2 = rightArray.getData();
326 1 T* aim = resultArray.getData();
327
328 1 std::transform (data1, data1 + dimLeft, data2, aim, std::minus<T>());
329 1 }
330
331 template <typename T>
332 ✗ void subtract_array_scalar(const BaseArray<T>& inputArray, T b, BaseArray<T>& outputArray)
333 {
334 ✗ size_t dim = inputArray.getNumElems();
335 ✗ if(dim > 0)
336 {
337 ✗ outputArray.setDims(inputArray.getDims());
338 ✗ const T* data = inputArray.getData();
339 ✗ T* aim = outputArray.getData();
340 ✗ std::transform (data, data + inputArray.getNumElems(), aim, [&](const T& a) { return a-b; });
341 }
342 ✗ }
343
344 template <typename T>
345 12 void add_array(const BaseArray<T>& leftArray, const BaseArray<T>& rightArray, BaseArray<T>& resultArray)
346 {
347 12 size_t dimLeft = leftArray.getNumElems();
348 12 size_t dimRight = rightArray.getNumElems();
349
350
1/6
void add_array<bool>(BaseArray<bool> const&, BaseArray<bool> const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void add_array<double>(BaseArray<double> const&, BaseArray<double> const&, BaseArray<double>&):
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
void add_array<int>(BaseArray<int> const&, BaseArray<int> const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
12 if(dimLeft != dimRight)
351 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
352 "Right and left array must have the same size for element wise addition");
353
354
1/6
void add_array<bool>(BaseArray<bool> const&, BaseArray<bool> const&, BaseArray<bool>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
void add_array<double>(BaseArray<double> const&, BaseArray<double> const&, BaseArray<double>&):
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
void add_array<int>(BaseArray<int> const&, BaseArray<int> const&, BaseArray<int>&):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 resultArray.setDims(leftArray.getDims());
355 12 const T* data1 = leftArray.getData();
356 12 const T* data2 = rightArray.getData();
357 12 T* aim = resultArray.getData();
358
359 12 std::transform(data1, data1 + leftArray.getNumElems(), data2, aim, std::plus<T>());
360 12 }
361
362 template <typename T>
363 ✗ void add_array_scalar(const BaseArray<T>& inputArray, T b, BaseArray<T>& outputArray)
364 {
365 ✗ size_t dim = inputArray.getNumElems();
366 ✗ if (dim > 0) {
367 ✗ outputArray.setDims(inputArray.getDims());
368 ✗ const T* data = inputArray.getData();
369 ✗ T* result = outputArray.getData();
370 ✗ std::transform (data, data + inputArray.getNumElems(), result, [&](const T& a) { return a+b; });
371 }
372 ✗ }
373
374 template <typename T>
375 ✗ void usub_array(const BaseArray<T>& a, BaseArray<T>& b)
376 {
377 ✗ size_t nelems = a.getNumElems();
378 ✗ if (nelems > 0) {
379 ✗ b.setDims(a.getDims());
380 ✗ const T* data = a.getData();
381 ✗ T* result = b.getData();
382 ✗ for (size_t i = 0; i < nelems; i++)
383 ✗ result[i] = -data[i];
384 }
385 ✗ }
386
387 template <typename T>
388 1840421 T sum_array (const BaseArray<T>& x)
389 {
390 1840421 const T* data = x.getData();
391 1840421 T val = std::accumulate(data, data + x.getNumElems(), T());
392 1840421 return val;
393 }
394
395 template <typename T>
396 3 T product_array(const BaseArray<T>& x)
397 {
398 3 const T* data = x.getData();
399 3 T val = std::accumulate(data, data + x.getNumElems(), T(1), std::multiplies<T>());
400 3 return val;
401 }
402
403 /**
404 scalar product of two arrays (a,b type as template parameter)
405 */
406 template <typename T>
407 39240 T dot_array(const BaseArray<T>& a, const BaseArray<T>& b)
408 {
409
2/12
bool dot_array<bool>(BaseArray<bool> const&, BaseArray<bool> const&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
double dot_array<double>(BaseArray<double> const&, BaseArray<double> const&):
✓ Branch 1 taken 39240 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 39240 times.
int dot_array<int>(BaseArray<int> const&, BaseArray<int> const&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
39240 if (a.getNumDims() != 1 || b.getNumDims() != 1)
410 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "error in dot array function. Wrong dimension");
411 39240 const T* data1 = a.getData();
412 39240 const T* data2 = b.getData();
413 39240 T r = std::inner_product(data1, data1 + a.getNumElems(), data2, 0.0);
414 39240 return r;
415 }
416
417 /**
418 cross product of two arrays (a,b type as template parameter)
419 */
420 template <typename T>
421 ✗ void cross_array(const BaseArray<T>& a, const BaseArray<T>& b, BaseArray<T>& res)
422 {
423 ✗ res(1) = (a(2) * b(3)) - (a(3) * b(2));
424 ✗ res(2) = (a(3) * b(1)) - (a(1) * b(3));
425 ✗ res(3) = (a(1) * b(2)) - (a(2) * b(1));
426 ✗ };
427
428 /**
429 finds min/max elements of an array
430 */
431 template <typename T>
432 38 std::pair<T,T> min_max(const BaseArray<T>& x)
433 {
434
2/6
std::pair<bool, bool> min_max<bool>(BaseArray<bool> const&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
std::pair<double, double> min_max<double>(BaseArray<double> const&):
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
std::pair<int, int> min_max<int>(BaseArray<int> const&):
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
38 if (x.getNumElems() < 1)
435 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION, "min/max requires at least one element");
436 38 const T* data = x.getData();
437 std::pair<const T*, const T*>
438 38 ret = minmax_element(data, data + x.getNumElems());
439 38 return std::make_pair(*(ret.first), *(ret.second));
440 }
441
442 template <typename S, typename T>
443 ✗ void cast_array(const BaseArray<S>& a, BaseArray<T>& b)
444 {
445 ✗ b.setDims(a.getDims());
446 ✗ int numElems = a.getNumElems();
447 ✗ const S* src_data = a.getData();
448 ✗ T* dst_data = b.getData();
449 ✗ for (int i = 0; i < numElems; i++)
450 ✗ *dst_data++ = (T)(*src_data++);
451 ✗ }
452
453 /**
454 * helper for assignRowMajorData
455 * recursive function for muli-dimensional assignment of raw data
456 */
457 template <typename T>
458 17501 static size_t assignRowMajorDim(size_t dim, const T* data,
459 BaseArray<T> &array, vector<size_t> &idx) {
460 size_t processed = 0;
461 17501 size_t size = array.getDim(dim);
462
6/8
unsigned long assignRowMajorDim<bool>(unsigned long, bool const*, BaseArray<bool>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
unsigned long assignRowMajorDim<double>(unsigned long, double const*, BaseArray<double>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 53275 times.
✓ Branch 1 taken 17459 times.
unsigned long assignRowMajorDim<int>(unsigned long, int const*, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 201 times.
✓ Branch 1 taken 25 times.
unsigned long assignRowMajorDim<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 17 times.
71012 for (size_t i = 1; i <= size; i++) {
463
5/8
unsigned long assignRowMajorDim<bool>(unsigned long, bool const*, BaseArray<bool>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
unsigned long assignRowMajorDim<double>(unsigned long, double const*, BaseArray<double>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 13027 times.
✓ Branch 1 taken 40248 times.
unsigned long assignRowMajorDim<int>(unsigned long, int const*, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 183 times.
unsigned long assignRowMajorDim<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
53511 idx[dim - 1] = i;
464
5/8
unsigned long assignRowMajorDim<bool>(unsigned long, bool const*, BaseArray<bool>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
unsigned long assignRowMajorDim<double>(unsigned long, double const*, BaseArray<double>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 13027 times.
✓ Branch 1 taken 40248 times.
unsigned long assignRowMajorDim<int>(unsigned long, int const*, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 183 times.
unsigned long assignRowMajorDim<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
53511 if (dim < idx.size())
465 13045 processed += assignRowMajorDim(dim + 1, data + processed, array, idx);
466 else
467 40466 array(idx) = data[processed++];
468 }
469 17501 return processed;
470 }
471
472 template <typename T>
473 4456 void assignRowMajorData(const T *data, BaseArray<T> &array) {
474 4456 vector<size_t> idx(array.getNumDims());
475
3/6
void assignRowMajorData<bool>(bool const*, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void assignRowMajorData<double>(double const*, BaseArray<double>&):
✓ Branch 1 taken 4432 times.
void assignRowMajorData<int>(int const*, BaseArray<int>&):
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
void assignRowMajorData<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&):
✓ Branch 1 taken 17 times.
4456 assignRowMajorDim(1, data, array, idx);
476 4456 }
477
478 /**
479 * helper for convertArrayLayout
480 * recursive function for changing between row and column major
481 */
482 template <typename S, typename T>
483 82 static void convertArrayDim(size_t dim,
484 const BaseArray<S> &s, vector<size_t> &sidx,
485 BaseArray<T> &d, vector<size_t> &didx) {
486 82 size_t ndims = s.getNumDims();
487 82 size_t size = s.getDim(dim);
488
2/10
void convertArrayDim<bool, int>(unsigned long, BaseArray<bool> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<double, double>(unsigned long, BaseArray<double> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<double>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 82 times.
void convertArrayDim<int, bool>(unsigned long, BaseArray<int> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<bool>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<int, int>(unsigned long, BaseArray<int> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(unsigned long, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
382 for (size_t i = 1; i <= size; i++) {
489
2/10
void convertArrayDim<bool, int>(unsigned long, BaseArray<bool> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<double, double>(unsigned long, BaseArray<double> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<double>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 221 times.
void convertArrayDim<int, bool>(unsigned long, BaseArray<int> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<bool>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<int, int>(unsigned long, BaseArray<int> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(unsigned long, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
300 didx[ndims - dim] = sidx[dim - 1] = i;
490
2/10
void convertArrayDim<bool, int>(unsigned long, BaseArray<bool> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<double, double>(unsigned long, BaseArray<double> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<double>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 221 times.
void convertArrayDim<int, bool>(unsigned long, BaseArray<int> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<bool>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<int, int>(unsigned long, BaseArray<int> const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<int>&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayDim<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(unsigned long, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, std::vector<unsigned long, std::allocator<unsigned long> >&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, std::vector<unsigned long, std::allocator<unsigned long> >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
300 if (dim < sidx.size())
491 79 convertArrayDim(dim + 1, s, sidx, d, didx);
492 else
493 221 d(didx) = s(sidx);
494 }
495 82 }
496
497
498 /**
499 * permutes dims between row and column major storage layout,
500 * including optional type conversion if supported in assignment from S to T
501 */
502 template <typename S, typename T>
503 3 void convertArrayLayout(const BaseArray<S> &s, BaseArray<T> &d) {
504 3 size_t ndims = s.getNumDims();
505
1/10
void convertArrayLayout<bool, int>(BaseArray<bool> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<double, double>(BaseArray<double> const&, BaseArray<double>&):
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
void convertArrayLayout<int, bool>(BaseArray<int> const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<int, int>(BaseArray<int> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
3 if (ndims != d.getNumDims())
506 ✗ throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
507 "Wrong dimensions in convertArrayLayout");
508 3 vector<size_t> sdims = s.getDims();
509
1/20
void convertArrayLayout<bool, int>(BaseArray<bool> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
void convertArrayLayout<double, double>(BaseArray<double> const&, BaseArray<double>&):
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
void convertArrayLayout<int, bool>(BaseArray<int> const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
void convertArrayLayout<int, int>(BaseArray<int> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
void convertArrayLayout<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
3 vector<size_t> ddims(ndims);
510
2/10
void convertArrayLayout<bool, int>(BaseArray<bool> const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayLayout<double, double>(BaseArray<double> const&, BaseArray<double>&):
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
void convertArrayLayout<int, bool>(BaseArray<int> const&, BaseArray<bool>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayLayout<int, int>(BaseArray<int> const&, BaseArray<int>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void convertArrayLayout<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
9 for (size_t dim = 1; dim <= ndims; dim++)
511 6 ddims[ndims - dim] = sdims[dim - 1];
512
1/10
void convertArrayLayout<bool, int>(BaseArray<bool> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<double, double>(BaseArray<double> const&, BaseArray<double>&):
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
void convertArrayLayout<int, bool>(BaseArray<int> const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<int, int>(BaseArray<int> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
3 d.resize(ddims);
513
1/10
void convertArrayLayout<bool, int>(BaseArray<bool> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<double, double>(BaseArray<double> const&, BaseArray<double>&):
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
void convertArrayLayout<int, bool>(BaseArray<int> const&, BaseArray<bool>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<int, int>(BaseArray<int> const&, BaseArray<int>&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
void convertArrayLayout<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, BaseArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
3 convertArrayDim(1, s, sdims, d, ddims);
514 3 }
515
516 /*
517 Explicit template instantiation for double, int, bool
518 */
519 template void BOOST_EXTENSION_EXPORT_DECL
520 cat_array<double>(int k, const vector<const BaseArray<double>*>& x, BaseArray<double>& a);
521 template void BOOST_EXTENSION_EXPORT_DECL
522 cat_array<int>(int k, const vector<const BaseArray<int>*>& x, BaseArray<int>& a);
523 template void BOOST_EXTENSION_EXPORT_DECL
524 cat_array<bool>(int k, const vector<const BaseArray<bool>*>& x, BaseArray<bool>& a);
525
526 template void BOOST_EXTENSION_EXPORT_DECL
527 transpose_array(const BaseArray<double>& x, BaseArray<double>& a);
528 template void BOOST_EXTENSION_EXPORT_DECL
529 transpose_array(const BaseArray<int>& x, BaseArray<int>& a);
530 template void BOOST_EXTENSION_EXPORT_DECL
531 transpose_array(const BaseArray<bool>& x, BaseArray<bool>& a);
532
533 template void BOOST_EXTENSION_EXPORT_DECL
534 diagonal_alloc(const BaseArray<double>& v, BaseArray<double>& D);
535 template void BOOST_EXTENSION_EXPORT_DECL
536 diagonal_alloc(const BaseArray<int>& v, BaseArray<int>& D);
537
538 template void BOOST_EXTENSION_EXPORT_DECL
539 promote_array(size_t n, const BaseArray<double>& s, BaseArray<double>& d);
540 template void BOOST_EXTENSION_EXPORT_DECL
541 promote_array(size_t n, const BaseArray<int>& s, BaseArray<int>& d);
542 template void BOOST_EXTENSION_EXPORT_DECL
543 promote_array(size_t n, const BaseArray<bool>& s, BaseArray<bool>& d);
544
545 template void BOOST_EXTENSION_EXPORT_DECL
546 multiply_array(const BaseArray<double>& inputArray, const double &b, BaseArray<double>& outputArray);
547 template void BOOST_EXTENSION_EXPORT_DECL
548 multiply_array(const BaseArray<int>& inputArray, const int &b, BaseArray<int>& outputArray);
549 template void BOOST_EXTENSION_EXPORT_DECL
550 multiply_array(const BaseArray<bool>& inputArray, const bool &b, BaseArray<bool>& outputArray);
551
552 template void BOOST_EXTENSION_EXPORT_DECL
553 multiply_array(const BaseArray<double> &leftArray, const BaseArray<double> &rightArray, BaseArray<double> &resultArray);
554 template void BOOST_EXTENSION_EXPORT_DECL
555 multiply_array(const BaseArray<int> &leftArray, const BaseArray<int> &rightArray, BaseArray<int> &resultArray);
556 template void BOOST_EXTENSION_EXPORT_DECL
557 multiply_array(const BaseArray<bool> &leftArray, const BaseArray<bool> &rightArray, BaseArray<bool> &resultArray);
558
559 template void BOOST_EXTENSION_EXPORT_DECL
560 multiply_array_elem_wise(const BaseArray<double> &leftArray, const BaseArray<double> &rightArray, BaseArray<double> &resultArray);
561 template void BOOST_EXTENSION_EXPORT_DECL
562 multiply_array_elem_wise(const BaseArray<int> &leftArray, const BaseArray<int> &rightArray, BaseArray<int> &resultArray);
563 template void BOOST_EXTENSION_EXPORT_DECL
564 multiply_array_elem_wise(const BaseArray<bool> &leftArray, const BaseArray<bool> &rightArray, BaseArray<bool> &resultArray);
565
566 template void BOOST_EXTENSION_EXPORT_DECL
567 divide_array(const BaseArray<double>& inputArray, const double &b, BaseArray<double>& outputArray);
568 template void BOOST_EXTENSION_EXPORT_DECL
569 divide_array(const BaseArray<int>& inputArray, const int &b, BaseArray<int>& outputArray);
570 template void BOOST_EXTENSION_EXPORT_DECL
571 divide_array(const BaseArray<bool>& inputArray, const bool &b, BaseArray<bool>& outputArray);
572
573 template void BOOST_EXTENSION_EXPORT_DECL
574 divide_array(const double &b, const BaseArray<double>& inputArray, BaseArray<double>& outputArray);
575 template void BOOST_EXTENSION_EXPORT_DECL
576 divide_array(const int &b, const BaseArray<int>& inputArray, BaseArray<int>& outputArray);
577
578 template void BOOST_EXTENSION_EXPORT_DECL
579 divide_array_elem_wise(const BaseArray<double> &leftArray, const BaseArray<double> &rightArray, BaseArray<double> &resultArray);
580 template void BOOST_EXTENSION_EXPORT_DECL
581 divide_array_elem_wise(const BaseArray<int> &leftArray, const BaseArray<int> &rightArray, BaseArray<int> &resultArray);
582 template void BOOST_EXTENSION_EXPORT_DECL
583 divide_array_elem_wise(const BaseArray<bool> &leftArray, const BaseArray<bool> &rightArray, BaseArray<bool> &resultArray);
584
585 template void BOOST_EXTENSION_EXPORT_DECL
586 fill_array(BaseArray<double>& inputArray, double b);
587 template void BOOST_EXTENSION_EXPORT_DECL
588 fill_array(BaseArray<int>& inputArray, int b);
589 template void BOOST_EXTENSION_EXPORT_DECL
590 fill_array(BaseArray<bool>& inputArray, bool b);
591
592 template void BOOST_EXTENSION_EXPORT_DECL
593 pow_array_scalar(const BaseArray<double>& inputArray, double exponent, BaseArray<double>& outputArray);
594 template void BOOST_EXTENSION_EXPORT_DECL
595 pow_array_scalar(const BaseArray<double>& inputArray, int exponent, BaseArray<double>& outputArray);
596
597 template void BOOST_EXTENSION_EXPORT_DECL
598 subtract_array(const BaseArray<double>& leftArray, const BaseArray<double>& rightArray, BaseArray<double>& resultArray);
599 template void BOOST_EXTENSION_EXPORT_DECL
600 subtract_array(const BaseArray<int>& leftArray, const BaseArray<int>& rightArray, BaseArray<int>& resultArray);
601 template void BOOST_EXTENSION_EXPORT_DECL
602 subtract_array(const BaseArray<bool>& leftArray, const BaseArray<bool>& rightArray, BaseArray<bool>& resultArray);
603
604 template void BOOST_EXTENSION_EXPORT_DECL
605 subtract_array_scalar(const BaseArray<double>& inputArray, double b, BaseArray<double>& outputArray);
606 template void BOOST_EXTENSION_EXPORT_DECL
607 subtract_array_scalar(const BaseArray<int>& inputArray, int b, BaseArray<int>& outputArray);
608 template void BOOST_EXTENSION_EXPORT_DECL
609 subtract_array_scalar(const BaseArray<bool>& inputArray, bool b, BaseArray<bool>& outputArray);
610
611 template void BOOST_EXTENSION_EXPORT_DECL
612 add_array(const BaseArray<double>& leftArray, const BaseArray<double>& rightArray, BaseArray<double>& resultArray);
613 template void BOOST_EXTENSION_EXPORT_DECL
614 add_array(const BaseArray<int>& leftArray, const BaseArray<int>& rightArray, BaseArray<int>& resultArray);
615 template void BOOST_EXTENSION_EXPORT_DECL
616 add_array(const BaseArray<bool>& leftArray, const BaseArray<bool>& rightArray, BaseArray<bool>& resultArray);
617
618 template void BOOST_EXTENSION_EXPORT_DECL
619 add_array_scalar(const BaseArray<double>& inputArray, double b, BaseArray<double>& outputArray);
620 template void BOOST_EXTENSION_EXPORT_DECL
621 add_array_scalar(const BaseArray<int>& inputArray, int b, BaseArray<int>& outputArray);
622 template void BOOST_EXTENSION_EXPORT_DECL
623 add_array_scalar(const BaseArray<bool>& inputArray, bool b, BaseArray<bool>& outputArray);
624
625 template void BOOST_EXTENSION_EXPORT_DECL
626 usub_array(const BaseArray<double>& a, BaseArray<double>& b);
627 template void BOOST_EXTENSION_EXPORT_DECL
628 usub_array(const BaseArray<int>& a, BaseArray<int>& b);
629 template void BOOST_EXTENSION_EXPORT_DECL
630 usub_array(const BaseArray<bool>& a, BaseArray<bool>& b);
631
632 template double BOOST_EXTENSION_EXPORT_DECL
633 sum_array(const BaseArray<double>& x);
634 template int BOOST_EXTENSION_EXPORT_DECL
635 sum_array(const BaseArray<int>& x);
636 template bool BOOST_EXTENSION_EXPORT_DECL
637 sum_array(const BaseArray<bool>& x);
638
639 template double BOOST_EXTENSION_EXPORT_DECL
640 product_array(const BaseArray<double>& x);
641 template int BOOST_EXTENSION_EXPORT_DECL
642 product_array(const BaseArray<int>& x);
643
644 template void BOOST_EXTENSION_EXPORT_DECL
645 cross_array(const BaseArray<double>& a, const BaseArray<double>& b, BaseArray<double>& res);
646 template void BOOST_EXTENSION_EXPORT_DECL
647 cross_array(const BaseArray<int>& a, const BaseArray<int>& b, BaseArray<int>& res);
648 template void BOOST_EXTENSION_EXPORT_DECL
649 cross_array(const BaseArray<bool>& a, const BaseArray<bool>& b, BaseArray<bool>& res);
650
651 template double BOOST_EXTENSION_EXPORT_DECL
652 dot_array(const BaseArray<double>&a, const BaseArray<double>& b);
653 template int BOOST_EXTENSION_EXPORT_DECL
654 dot_array(const BaseArray<int>&a, const BaseArray<int>& b);
655 template bool BOOST_EXTENSION_EXPORT_DECL
656 dot_array(const BaseArray<bool>&a, const BaseArray<bool>& b);
657
658 template std::pair<double,double> BOOST_EXTENSION_EXPORT_DECL
659 min_max(const BaseArray<double>& x);
660 template std::pair<int,int> BOOST_EXTENSION_EXPORT_DECL
661 min_max(const BaseArray<int>& x);
662 template std::pair<bool,bool> BOOST_EXTENSION_EXPORT_DECL
663 min_max(const BaseArray<bool>& x);
664
665 template void BOOST_EXTENSION_EXPORT_DECL
666 cast_array(const BaseArray<int> &a, BaseArray<double> &b);
667 template void BOOST_EXTENSION_EXPORT_DECL
668 cast_array(const BaseArray<int> &a, BaseArray<bool> &b);
669 template void BOOST_EXTENSION_EXPORT_DECL
670 cast_array(const BaseArray<bool> &a, BaseArray<int> &b);
671
672 template void BOOST_EXTENSION_EXPORT_DECL
673 convertArrayLayout(const BaseArray<double> &s, BaseArray<double> &d);
674 template void BOOST_EXTENSION_EXPORT_DECL
675 convertArrayLayout(const BaseArray<int> &s, BaseArray<int> &d);
676 template void BOOST_EXTENSION_EXPORT_DECL
677 convertArrayLayout(const BaseArray<bool> &s, BaseArray<int> &d);
678 template void BOOST_EXTENSION_EXPORT_DECL
679 convertArrayLayout(const BaseArray<int> &s, BaseArray<bool> &d);
680 template void BOOST_EXTENSION_EXPORT_DECL
681 convertArrayLayout(const BaseArray<string> &s, BaseArray<string> &d);
682
683
684 template void BOOST_EXTENSION_EXPORT_DECL
685 assignRowMajorData(const double *data, BaseArray<double> &d);
686 template void BOOST_EXTENSION_EXPORT_DECL
687 assignRowMajorData(const int *data, BaseArray<int> &d);
688 template void BOOST_EXTENSION_EXPORT_DECL
689 assignRowMajorData(const bool *data, BaseArray<bool> &d);
690 template void BOOST_EXTENSION_EXPORT_DECL
691 assignRowMajorData(const string *data, BaseArray<string> &d);
692 /** @} */ // end of math
693