11#include < Core/Modelica.h>
22#include < Core/Math/ArrayOperations.h>
3+ #include < Core/Math/ArraySlice.h>
34#include < sstream>
45#include < stdio.h>
56using namespace std ;
@@ -19,7 +20,7 @@ size_t getNextIndex(vector<size_t> idx,size_t k)
1920Concatenates n real arrays along the k:th dimension.
2021*/
2122template < typename T >
22- void cat_array (int k,BaseArray<T>& a, vector<BaseArray<T>* >& x )
23+ void cat_array (int k, vector<BaseArray<T>* >& x, BaseArray<T>& a )
2324{
2425 unsigned int new_k_dim_size = 0 ;
2526 unsigned int n = x.size ();
@@ -159,19 +160,26 @@ void promote_array(unsigned int n,BaseArray<T>& s,BaseArray<T>& d)
159160 d.assign ( data );
160161}
161162
162-
163+ /* *
164+ * permutes the first two dimensions of x into a
165+ */
163166template < typename T >
164- void transpose_array (BaseArray< T >& a , BaseArray< T >& x )
167+ void transpose_array (BaseArray< T >& x , BaseArray< T >& a )
165168
166169{
167- if (a.getNumDims ()!=2 || x.getNumDims ()!=2 )
168- throw ModelicaSimulationError (MODEL_ARRAY_FUNCTION," Erro in transpose_array, number of dimensions does not match" );
169-
170- vector<size_t > ex = x.getDims ();
171- std::swap ( ex[0 ], ex[1 ] );
172- a.setDims (ex);
173- a.assign (x);
174-
170+ size_t ndims = x.getNumDims ();
171+ if (ndims < 2 || ndims != a.getNumDims ())
172+ throw ModelicaSimulationError (MODEL_ARRAY_FUNCTION,
173+ " Wrong dimensions in transpose_array" );
174+ vector<size_t > ex = x.getDims ();
175+ std::swap (ex[0 ], ex[1 ]);
176+ a.setDims (ex);
177+ vector<Slice> sx (ndims);
178+ vector<Slice> sa (ndims);
179+ for (int i = 1 ; i <= x.getDim (1 ); i++) {
180+ sa[1 ] = sx[0 ] = Slice (i);
181+ ArraySlice<T>(a, sa).assign (ArraySlice<T>(x, sx));
182+ }
175183}
176184
177185template < typename T>
@@ -390,13 +398,13 @@ void convertExternalF77(const BaseArray<S> &s, BaseArray<T> &d) {
390398/*
391399Explicit template instantiation for double, int, bool
392400*/
393- template void BOOST_EXTENSION_EXPORT_DECL cat_array<double >(int k,BaseArray<double >& a, vector< BaseArray<double >* >& x );
394- template void BOOST_EXTENSION_EXPORT_DECL cat_array<int >(int k,BaseArray<int >& a, vector< BaseArray<int >* >& x );
395- template void BOOST_EXTENSION_EXPORT_DECL cat_array<bool >(int k,BaseArray<bool >& a, vector< BaseArray<bool >* >& x );
401+ template void BOOST_EXTENSION_EXPORT_DECL cat_array<double >(int k, vector< BaseArray<double >* >& x, BaseArray<double >& a );
402+ template void BOOST_EXTENSION_EXPORT_DECL cat_array<int >(int k, vector< BaseArray<int >* >& x, BaseArray<int >& a );
403+ template void BOOST_EXTENSION_EXPORT_DECL cat_array<bool >(int k, vector< BaseArray<bool >* >& x, BaseArray<bool >& a );
396404
397- template void BOOST_EXTENSION_EXPORT_DECL transpose_array (BaseArray<double >& a , BaseArray< double >& x );
398- template void BOOST_EXTENSION_EXPORT_DECL transpose_array (BaseArray<int >& a , BaseArray< int >& x );
399- template void BOOST_EXTENSION_EXPORT_DECL transpose_array (BaseArray<bool >& a , BaseArray< bool >& x );
405+ template void BOOST_EXTENSION_EXPORT_DECL transpose_array (BaseArray<double >& x , BaseArray< double >& a );
406+ template void BOOST_EXTENSION_EXPORT_DECL transpose_array (BaseArray<int >& x , BaseArray< int >& a );
407+ // template void BOOST_EXTENSION_EXPORT_DECL transpose_array(BaseArray<bool>& x , BaseArray< bool >& a );
400408
401409template void BOOST_EXTENSION_EXPORT_DECL promote_array (unsigned int n, BaseArray<double >& s, BaseArray<double >& d);
402410template void BOOST_EXTENSION_EXPORT_DECL promote_array (unsigned int n, BaseArray<int >& s, BaseArray<int >& d);
0 commit comments