Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implementing query method for exp class #2386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libasr/pass/intrinsic_function_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum class IntrinsicScalarFunctions : int64_t {
SymbolicMulQ,
SymbolicPowQ,
SymbolicLogQ,
SymbolicExpQ,
// ...
};

Expand Down Expand Up @@ -148,6 +149,7 @@ inline std::string get_intrinsic_name(int x) {
INTRINSIC_NAME_CASE(SymbolicMulQ)
INTRINSIC_NAME_CASE(SymbolicPowQ)
INTRINSIC_NAME_CASE(SymbolicLogQ)
INTRINSIC_NAME_CASE(SymbolicExpQ)
default : {
throw LCompilersException("pickle: intrinsic_id not implemented");
}
Expand Down Expand Up @@ -3149,6 +3151,7 @@ create_symbolic_query_macro(SymbolicAddQ)
create_symbolic_query_macro(SymbolicMulQ)
create_symbolic_query_macro(SymbolicPowQ)
create_symbolic_query_macro(SymbolicLogQ)
create_symbolic_query_macro(SymbolicExpQ)


#define create_symbolic_unary_macro(X) \
Expand Down Expand Up @@ -3312,6 +3315,8 @@ namespace IntrinsicScalarFunctionRegistry {
{nullptr, &SymbolicPowQ::verify_args}},
{static_cast<int64_t>(IntrinsicScalarFunctions::SymbolicLogQ),
{nullptr, &SymbolicLogQ::verify_args}},
{static_cast<int64_t>(IntrinsicScalarFunctions::SymbolicExpQ),
{nullptr, &SymbolicExpQ::verify_args}},
};

static const std::map<int64_t, std::string>& intrinsic_function_id_to_name = {
Expand Down Expand Up @@ -3424,6 +3429,8 @@ namespace IntrinsicScalarFunctionRegistry {
"SymbolicPowQ"},
{static_cast<int64_t>(IntrinsicScalarFunctions::SymbolicLogQ),
"SymbolicLogQ"},
{static_cast<int64_t>(IntrinsicScalarFunctions::SymbolicExpQ),
"SymbolicExpQ"},
};


Expand Down Expand Up @@ -3483,6 +3490,7 @@ namespace IntrinsicScalarFunctionRegistry {
{"MulQ", {&SymbolicMulQ::create_SymbolicMulQ, &SymbolicMulQ::eval_SymbolicMulQ}},
{"PowQ", {&SymbolicPowQ::create_SymbolicPowQ, &SymbolicPowQ::eval_SymbolicPowQ}},
{"LogQ", {&SymbolicLogQ::create_SymbolicLogQ, &SymbolicLogQ::eval_SymbolicLogQ}},
{"ExpQ", {&SymbolicExpQ::create_SymbolicExpQ, &SymbolicExpQ::eval_SymbolicExpQ}},
};

static inline bool is_intrinsic_function(const std::string& name) {
Expand Down
3 changes: 3 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6043,6 +6043,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
} else if (symbolic_type == "log") {
tmp = attr_handler.eval_symbolic_is_log(se, al, x.base.base.loc, args, diag);
return;
} else if (symbolic_type == "exp") {
tmp = attr_handler.eval_symbolic_is_exp(se, al, x.base.base.loc, args, diag);
return;
} else {
throw SemanticError(symbolic_type + " symbolic type not supported yet", x.base.base.loc);
}
Expand Down
14 changes: 14 additions & 0 deletions src/lpython/semantics/python_attribute_eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,20 @@ struct AttributeHandler {
{ throw SemanticError(msg, loc); });
}

static ASR::asr_t* eval_symbolic_is_exp(ASR::expr_t *s, Allocator &al, const Location &loc,
Vec<ASR::expr_t*> &args, diag::Diagnostics &/*diag*/) {
Vec<ASR::expr_t*> args_with_list;
args_with_list.reserve(al, args.size() + 1);
args_with_list.push_back(al, s);
for(size_t i = 0; i < args.size(); i++) {
args_with_list.push_back(al, args[i]);
}
ASRUtils::create_intrinsic_function create_function =
ASRUtils::IntrinsicScalarFunctionRegistry::get_create_function("ExpQ");
return create_function(al, loc, args_with_list, [&](const std::string &msg, const Location &loc)
{ throw SemanticError(msg, loc); });
}

}; // AttributeHandler

} // namespace LCompilers::LPython
Expand Down