<commit_before># coding: utf-8
import numpy as np
from numpy import ndarray
from numpy import asarray

from ast import literal_eval

from sympy.core.expr import Expr
from sympy.core.containers import Tuple
from sympy import Symbol, Integer, Float, Add, Mul
from sympy import true, false, pi
from sympy.tensor import Idx, Indexed, IndexedBase
from sympy.core.basic import Basic
from sympy.core.relational import Eq, Ne, Lt, Le, Gt, Ge
from sympy.core.power import Pow
from sympy.core.function import Function
from sympy import preorder_traversal
from sympy import (Abs, sqrt, sin,  cos,  exp,  log, \
                   csc,  cos,  sec,  tan,  cot,  asin, \
                   acsc, acos, asec, atan, acot, atan2)


from sympy.core.basic import Basic
from sympy.core.expr import Expr
from sympy.core.compatibility import string_types
from sympy.core.operations import LatticeOp
from sympy.core.function import Derivative
from sympy.core.function import _coeff_isneg
from sympy.core.singleton import S
from sympy.utilities.iterables import iterable
from sympy import Integral, Symbol
from sympy.simplify.radsimp import fraction
from sympy.logic.boolalg import BooleanFunction

from pyccel.types.ast import allocatable_like
from pyccel.types.ast import FunctionCall
from pyccel.types.ast import DataType, DataTypeFactory
from pyccel.types.ast import (For, Assign, Declare, Variable, \
                              FunctionHeader, ClassHeader, MethodHeader, \
                              datatype, While, NativeFloat, \
                              EqualityStmt, NotequalStmt, \
                              MultiAssign, \
                              FunctionDef, ClassDef, Del, Print, \
                              Comment, AnnotatedComment, \
                              IndexedVariable, Slice, If, \
                              ThreadID, ThreadsNumber, \
                              Stencil, Ceil, Break, \
                              Zeros, Ones, Array, ZerosLike, Shape, Len, \
                              Dot, Sign, IndexedElement,\
                              Min, Max)

from pyccel.core.syntax     import BasicStmt
from pyccel.imports.syntax import ImportFromStmt
from pyccel.openmp.syntax   import OpenmpStmt


DEBUG = False
#DEBUG = True

# TODO set to None
DEFAULT_TYPE = 'double'

known_functions = {
    "abs": "Abs",
#    "asin": "asin",
#    "acsc": "acsc",
#    "acot": "acot",
#    "acos": "acos",
#    "asec": "asec",
    "atan": "atan",
    "atan2": "atan2",
    "ceil": "Ceil",
    "cos": "cos",
    "cosh": "cosh",
    "cot": "cot",
    "csc": "csc",
    "dot": "dot",
    "exp": "exp",
    "len": "Len",
    "log": "log",
    "min": "Min",
    "max": "Max",
    "pow": "pow",
    "sec": "sec",
    "sign": "Sign",
    "sin": "sin",
    "sinh": "sinh",
    "sqrt": "sqrt",
    "tan": "tan",
    "tanh": "tanh"
}

# TODO: treat the inout case
# TODO: 1. check that every stmt is well implementing
#          the local_vars and stmt_vars properties.

# ...
def append_mpi(namespace):
    """Adds MPI functions and constants to the namespace

    namespace: dict
        dictorionary containing all declared variables/functions/classes.
    """
    body        = []
    local_vars  = []
    global_vars = []
    hide        = True
    kind        = 'procedure'

    args        = []
    datatype    = 'int'
    allocatable = False
    shape       = None
    rank        = 0

    var_name = 'result_%d' % abs(hash(datatype))

    for f_name in ['mpi_init', 'mpi_finalize']:
        var = Variable(datatype, var_name, \
                       rank=rank, \
                       allocatable=allocatable, \
                       shape=shape)
        results = [var]

        stmt = FunctionDef(f_name, args, results, \
                           body, local_vars, global_vars, \
                           hide=hide, kind=kind)

        namespace[f_name] = stmt

    var_name = 'mpi_comm_world'
    datatype    = 'int'
    allocatable = False
    shape       = None
    rank        = 0
    var = Variable(datatype, var_name, \
                   rank=rank, \
                   allocatable=allocatable, \
                   shape=shape)
    namespace[var_name] = var

    return namespace
# ...

# Global variable namespace
namespace    = {}
headers      = {}
declarations = {}

namespace["True"]  = true
namespace["False"] = false
namespace["pi"]    = pi
namespace = append_mpi(namespace)

# ... builtin types
builtin_types  = ['int', 'float', 'double', 'complex']
# ...<commit_msg>append_mpi mpi_comm_size<commit_after># coding: utf-8
import numpy as np
from numpy import ndarray
from numpy import asarray

from ast import literal_eval

from sympy.core.expr import Expr
from sympy.core.containers import Tuple
from sympy import Symbol, Integer, Float, Add, Mul
from sympy import true, false, pi
from sympy.tensor import Idx, Indexed, IndexedBase
from sympy.core.basic import Basic
from sympy.core.relational import Eq, Ne, Lt, Le, Gt, Ge
from sympy.core.power import Pow
from sympy.core.function import Function
from sympy import preorder_traversal
from sympy import (Abs, sqrt, sin,  cos,  exp,  log, \
                   csc,  cos,  sec,  tan,  cot,  asin, \
                   acsc, acos, asec, atan, acot, atan2)


from sympy.core.basic import Basic
from sympy.core.expr import Expr
from sympy.core.compatibility import string_types
from sympy.core.operations import LatticeOp
from sympy.core.function import Derivative
from sympy.core.function import _coeff_isneg
from sympy.core.singleton import S
from sympy.utilities.iterables import iterable
from sympy import Integral, Symbol
from sympy.simplify.radsimp import fraction
from sympy.logic.boolalg import BooleanFunction

from pyccel.types.ast import allocatable_like
from pyccel.types.ast import FunctionCall
from pyccel.types.ast import DataType, DataTypeFactory
from pyccel.types.ast import (For, Assign, Declare, Variable, \
                              FunctionHeader, ClassHeader, MethodHeader, \
                              datatype, While, NativeFloat, \
                              EqualityStmt, NotequalStmt, \
                              MultiAssign, \
                              FunctionDef, ClassDef, Del, Print, \
                              Comment, AnnotatedComment, \
                              IndexedVariable, Slice, If, \
                              ThreadID, ThreadsNumber, \
                              Stencil, Ceil, Break, \
                              Zeros, Ones, Array, ZerosLike, Shape, Len, \
                              Dot, Sign, IndexedElement,\
                              Min, Max)

from pyccel.core.syntax     import BasicStmt
from pyccel.imports.syntax import ImportFromStmt
from pyccel.openmp.syntax   import OpenmpStmt


DEBUG = False
#DEBUG = True

# TODO set to None
DEFAULT_TYPE = 'double'

known_functions = {
    "abs": "Abs",
#    "asin": "asin",
#    "acsc": "acsc",
#    "acot": "acot",
#    "acos": "acos",
#    "asec": "asec",
    "atan": "atan",
    "atan2": "atan2",
    "ceil": "Ceil",
    "cos": "cos",
    "cosh": "cosh",
    "cot": "cot",
    "csc": "csc",
    "dot": "dot",
    "exp": "exp",
    "len": "Len",
    "log": "log",
    "min": "Min",
    "max": "Max",
    "pow": "pow",
    "sec": "sec",
    "sign": "Sign",
    "sin": "sin",
    "sinh": "sinh",
    "sqrt": "sqrt",
    "tan": "tan",
    "tanh": "tanh"
}

# TODO: treat the inout case
# TODO: 1. check that every stmt is well implementing
#          the local_vars and stmt_vars properties.

# ...
def append_mpi(namespace):
    """Adds MPI functions and constants to the namespace

    namespace: dict
        dictorionary containing all declared variables/functions/classes.
    """
    # ...
    var_name = 'mpi_comm_world'
    var = Variable('int', var_name)
    namespace[var_name] = var
    # ...

    # ...
    body        = []
    local_vars  = []
    global_vars = []
    hide        = True
    kind        = 'procedure'
    # ...

    # ...
    args        = []
    datatype    = 'int'
    allocatable = False
    shape       = None
    rank        = 0

    var_name = 'result_%d' % abs(hash(datatype))

    for f_name in ['mpi_init', 'mpi_finalize']:
        var = Variable(datatype, var_name)
        results = [var]

        stmt = FunctionDef(f_name, args, results, \
                           body, local_vars, global_vars, \
                           hide=hide, kind=kind)

        namespace[f_name] = stmt
    # ...

    # ...
    i = np.random.randint(10)
    var_name = 'result_%d' % abs(hash(i))
    err_name = 'error_%d' % abs(hash(i))

    for f_name in ['mpi_comm_size']:
        var = Variable(datatype, var_name)
        err = Variable(datatype, err_name)
        results = [var, err]

        args = [namespace['mpi_comm_world']]
        stmt = FunctionDef(f_name, args, results, \
                           body, local_vars, global_vars, \
                           hide=hide, kind=kind)

        namespace[f_name] = stmt
    # ...

    return namespace
# ...

# Global variable namespace
namespace    = {}
headers      = {}
declarations = {}

namespace["True"]  = true
namespace["False"] = false
namespace["pi"]    = pi
namespace = append_mpi(namespace)

# ... builtin types
builtin_types  = ['int', 'float', 'double', 'complex']
# ...
{'fraction_non_alphanumeric': 0.11353617890549403, 'fraction_numerical': 0.0016127298139984947, 'mean_word_length': 2.056851790995728, 'pattern_counts': {'":': 54, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1727321', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2869, 'n_words': 799}