diff --git a/OMCompiler/Compiler/Template/CodegenCppCommon.tpl b/OMCompiler/Compiler/Template/CodegenCppCommon.tpl index 8d8448d5724..4ae53795c7e 100644 --- a/OMCompiler/Compiler/Template/CodegenCppCommon.tpl +++ b/OMCompiler/Compiler/Template/CodegenCppCommon.tpl @@ -1068,31 +1068,11 @@ template daeExpReduction(Exp exp, Context context, Text &preExp, let rec_name = '<%underscorePath(ClassInf.getStateName(record_state))%>' '<%rec_name%>_array_get(<%res%>, 1, <%arrIndex%>++) = <%reductionBodyExpr%>;' case T_ARRAY(__) then - let tmp_shape = tempDecl("vector", &varDecls /*BUFD*/) - let tmp_indeces = tempDecl("idx_type", &varDecls /*BUFD*/) - /*let idx_str = (dims |> dim => - let tmp_idx = tempDecl("vector", &varDecls) - let &preExp += '<%tmp_shape%>.push_back(1);<%\n%> - <%tmp_indeces%>.push_back(<%tmp_idx%>);<%\n%>' - '' - )*/ - let tmp_idx = tempDecl("vector", &varDecls /*BUFD*/) - /*let &preExp += '<%tmp_shape%>.push_back(0);<%\n%> - <%tmp_idx%>.push_back(<%arrIndex%>++);<%\n%> - <%tmp_indeces%>.push_back(<%tmp_idx%>);<%\n%>' - let tmp = 'make_pair(<%tmp_shape%>,<%tmp_indeces%>)' - */ - + let tmp_slice = tempDecl("vector", &varDecls) << - <%(dims |> dim => - let tmp_idx = tempDecl("vector", &varDecls /*BUFD*/) - '<%tmp_shape%>.push_back(1);<%\n%> - <%tmp_indeces%>.push_back(<%tmp_idx%>);<%\n%>' - )%> - <%tmp_shape%>.push_back(0);<%\n%> - <%tmp_idx%>.push_back(<%arrIndex%>++);<%\n%> - <%tmp_indeces%>.push_back(<%tmp_idx%>);<%\n%> - fill_array_from_shape(make_pair(<%tmp_shape%>,<%tmp_indeces%>),<%reductionBodyExpr%>,<%res%>); + <%tmp_slice%>.clear(); + <%tmp_slice%>.push_back(Slice(<%arrIndex%>++)); + ArraySlice<<%expTypeShort(ty)%>>(<%res%>, <%tmp_slice%>).assign(<%reductionBodyExpr%>); >> else '<%res%>(<%arrIndex%>++) = <%reductionBodyExpr%>;' diff --git a/OMCompiler/SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp b/OMCompiler/SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp index a6911bf9307..183188958cf 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp @@ -86,120 +86,6 @@ void cat_array(int k, const vector*>& x, BaseArray& a) } } -/* -creates an array (d) for passed multi array shape (sp) and initialized it with elements from passed source array (s) -s source array -d destination array -sp (shape,indices) of source array -*/ -template < typename T > -void create_array_from_shape(const spec_type& sp,BaseArray& s,BaseArray& d) -{ - //alocate target array - vector shape; - vector::const_iterator iter; - for(iter = (sp.first).begin();iter!=(sp.first).end();++iter) - { - if(*iter!=0) - shape.push_back(*iter); - - } - d.setDims(shape); - - //Check if the dimension of passed indices match the dimension of target array - if(sp.second.size()!=s.getNumDims()) - throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in create array from shape, number of dimensions does not match"); - - T* data = new T[d.getNumElems()]; - - idx_type::const_iterator spec_iter; - //calc number of indeces - size_t n =1; - for(spec_iter = sp.second.begin();spec_iter!=sp.second.end();++spec_iter) - { - - n*=spec_iter->size(); - } - size_t k =0; - size_t index=0; - vector::const_iterator indeces_iter; - - //initialize target array with elements of source array using passed indices - vector idx; - for(int i=0;i(d.getNumElems()-1)) - { - throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in create array from shape, number of dimensions does not match"); - } - data[index] = s(idx); - idx.clear(); - index++; - } - //assign elemets to target array - d.assign( data ); - delete [] data; -} - - - - -/* -fills an array (d) with passed multi array shape (sp) and initialized it with elements from passed source array (s) -s source array -d destination array -sp (shape,indices) of source array -*/ -template < typename T > -void fill_array_from_shape(const spec_type& sp,BaseArray& s,BaseArray& d) -{ - - - T* data = new T[d.getNumElems()]; - - idx_type::const_iterator spec_iter; - //calc number of indeces - size_t n =1; - for(spec_iter = sp.second.begin();spec_iter!=sp.second.end();++spec_iter) - { - - n*=spec_iter->size(); - } - size_t k =0; - size_t index=0; - vector::const_iterator indeces_iter; - - //initialize target array with elements of source array using passed indices - vector idx; - for(int i=0;i(d.getNumElems()-1)) - { - throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in create array from shape, number of dimensions does not match"); - } - data[index] = s(idx); - idx.clear(); - index++; - } - //assign elemets to target array - d.assign( data ); - delete [] data; -} - void identity_alloc(size_t n, DynArrayDim2& I) { I.setDims(n, n); @@ -226,7 +112,9 @@ void diagonal_alloc(const BaseArray& v, BaseArray& D) D_data[i * n + i] = v_data[i]; } - //template < typename T , size_t NumDims, size_t NumDims2 > +/** + * appends dimensions of size 1 to the right of s up to dimension n + */ template void promote_array(size_t n, const BaseArray& s, BaseArray& d) { @@ -644,15 +532,6 @@ promote_array(size_t n, const BaseArray& s, BaseArray& d); template void BOOST_EXTENSION_EXPORT_DECL promote_array(size_t n, const BaseArray& s, BaseArray& d); -template void BOOST_EXTENSION_EXPORT_DECL create_array_from_shape(const spec_type& sp, BaseArray& s, BaseArray& d); -template void BOOST_EXTENSION_EXPORT_DECL create_array_from_shape(const spec_type& sp, BaseArray& s, BaseArray& d); -template void BOOST_EXTENSION_EXPORT_DECL create_array_from_shape(const spec_type& sp, BaseArray& s, BaseArray& d); - - -template void BOOST_EXTENSION_EXPORT_DECL fill_array_from_shape(const spec_type& sp, BaseArray& s, BaseArray& d); -template void BOOST_EXTENSION_EXPORT_DECL fill_array_from_shape(const spec_type& sp, BaseArray& s, BaseArray& d); -template void BOOST_EXTENSION_EXPORT_DECL fill_array_from_shape(const spec_type& sp, BaseArray& s, BaseArray& d); - template void BOOST_EXTENSION_EXPORT_DECL multiply_array(const BaseArray& inputArray, const double &b, BaseArray& outputArray); template void BOOST_EXTENSION_EXPORT_DECL diff --git a/OMCompiler/SimulationRuntime/cpp/Include/Core/Math/ArrayOperations.h b/OMCompiler/SimulationRuntime/cpp/Include/Core/Math/ArrayOperations.h index d53cd4967b7..91bcd11ae9e 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/Core/Math/ArrayOperations.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/Core/Math/ArrayOperations.h @@ -36,19 +36,6 @@ void cat_array(int k, const vector*>& x, BaseArray& a); template void transpose_array(const BaseArray& x, BaseArray& a); -/* -creates an array (d) for passed multi array shape (sp) and initialized it with elements from passed source array (s) -s source array -d destination array -sp (shape,indices) of source array -*/ - -template < typename T > -void create_array_from_shape(const spec_type& sp,BaseArray& s,BaseArray& d); - -template < typename T > -void fill_array_from_shape(const spec_type& sp,BaseArray& s,BaseArray& d); - void BOOST_EXTENSION_EXPORT_DECL identity_alloc(size_t n, DynArrayDim2& I); template