Skip to content
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

Implemented bessel function of second kind of order 0 #3706

Merged
merged 3 commits into from
Mar 25, 2024

Conversation

parth121101
Copy link
Contributor

fixes: #3705

@parth121101 parth121101 marked this pull request as ready for review March 25, 2024 17:42
@certik certik merged commit 71447c2 into lfortran:main Mar 25, 2024
21 checks passed
Comment on lines +6 to +14
x = 1036.462826483388272_dp
y = 1.7197292882018389_dp
z = 10.2368267382872828_dp
w = 0.17197292882018389_dp

i = 152.67283628_sp
j = 632.92729728_sp
k = 1.2728272919_sp
l = 5.1727272919_sp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add more tests, these implementations are very prone to mistakes. Please look at https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/bessely0/test and add around 5-10 values from each .json file present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in the PR : #3712

Comment on lines +2940 to +2981
std::string c_func_name;
if (ASRUtils::extract_kind_from_ttype_t(arg_types[0]) == 4) {
c_func_name = "_lfortran_sbessely0";
} else {
c_func_name = "_lfortran_dbessely0";
}
std::string new_name = "_lcompilers_bessel_y0_"+ type_to_str_python(arg_types[0]);

declare_basic_variables(new_name);
if (scope->get_symbol(new_name)) {
ASR::symbol_t *s = scope->get_symbol(new_name);
ASR::Function_t *f = ASR::down_cast<ASR::Function_t>(s);
return b.Call(s, new_args, expr_type(f->m_return_var));
}
fill_func_arg("x", arg_types[0]);
auto result = declare(new_name, return_type, ReturnVar);
{
SymbolTable *fn_symtab_1 = al.make_new<SymbolTable>(fn_symtab);
Vec<ASR::expr_t*> args_1;
{
args_1.reserve(al, 1);
ASR::expr_t *arg = b.Variable(fn_symtab_1, "x", arg_types[0],
ASR::intentType::In, ASR::abiType::BindC, true);
args_1.push_back(al, arg);
}

ASR::expr_t *return_var_1 = b.Variable(fn_symtab_1, c_func_name,
return_type, ASRUtils::intent_return_var, ASR::abiType::BindC, false);

SetChar dep_1; dep_1.reserve(al, 1);
Vec<ASR::stmt_t*> body_1; body_1.reserve(al, 1);
ASR::symbol_t *s = make_ASR_Function_t(c_func_name, fn_symtab_1, dep_1, args_1,
body_1, return_var_1, ASR::abiType::BindC, ASR::deftypeType::Interface, s2c(al, c_func_name));
fn_symtab->add_symbol(c_func_name, s);
dep.push_back(al, s2c(al, c_func_name));
body.push_back(al, b.Assignment(result, b.Call(s, args, return_type)));
}

ASR::symbol_t *new_symbol = make_ASR_Function_t(fn_name, fn_symtab, dep, args,
body, result, ASR::abiType::Source, ASR::deftypeType::Implementation, nullptr);
scope->add_symbol(fn_name, new_symbol);
return b.Call(new_symbol, new_args, return_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create a helper function that facilitates these implementation, register it in ASRBuilder and use that here. This code is repetitive.

Note: Not relevant to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement intrinsic bessel_y0 function
3 participants