Skip to content
Snippets Groups Projects
Select Git revision
  • 491e70ab7be74543f2ebc384845bc3b48c020162
  • master default protected
  • julia protected
  • 6.x protected
  • python-codegen
  • llvm-15
  • 5.x protected
  • 4.6 protected
  • uop
  • rework_pac
  • aux_vars_fix
  • julia-7.0.0
  • julia-6.4.0
  • julia-6.3.0
  • julia-6.2.0
15 results

FileOutputType.hh

Blame
  • ModelTree.cc 72.28 KiB
    /*
     * Copyright © 2003-2022 Dynare Team
     *
     * This file is part of Dynare.
     *
     * Dynare is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * Dynare is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
     */
    
    #include "ModelTree.hh"
    #include "VariableDependencyGraph.hh"
    
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wold-style-cast"
    #pragma GCC diagnostic ignored "-Wsign-compare"
    #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
    #include <boost/graph/adjacency_list.hpp>
    #include <boost/graph/max_cardinality_matching.hpp>
    #include <boost/graph/topological_sort.hpp>
    #pragma GCC diagnostic pop
    
    #ifdef __APPLE__
    # include <mach-o/dyld.h>
    #endif
    
    #include <regex>
    #include <utility>
    #include <algorithm>
    
    /* NB: The workers must be listed *after* all the other static variables
       related to MEX compilation, so that when the preprocessor exits, the workers
       are destroyed *before* those variables (since the former rely on the latter
       for their functioning). */
    condition_variable_any ModelTree::mex_compilation_cv;
    mutex ModelTree::mex_compilation_mut;
    vector<tuple<filesystem::path, set<filesystem::path>, string>> ModelTree::mex_compilation_queue;
    set<filesystem::path> ModelTree::mex_compilation_ongoing, ModelTree::mex_compilation_done, ModelTree::mex_compilation_failed;
    vector<jthread> ModelTree::mex_compilation_workers;
    
    void
    ModelTree::copyHelper(const ModelTree &m)
    {
      auto f = [this](expr_t e) { return e->clone(*this); };
    
      // Equations
      for (const auto &it : m.equations)
        equations.push_back(dynamic_cast<BinaryOpNode *>(f(it)));
      for (const auto &it : m.aux_equations)
        aux_equations.push_back(dynamic_cast<BinaryOpNode *>(f(it)));
    
      auto convert_deriv_map = [f](const map<vector<int>, expr_t> &dm)
                               {
                                 map<vector<int>, expr_t> dm2;
                                 for (const auto &it : dm)
                                   dm2.emplace(it.first, f(it.second));
                                 return dm2;
                               };
    
      // Derivatives
      for (const auto &it : m.derivatives)