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

Refactor variable name of random variables. #1546

Merged
merged 2 commits into from
Oct 30, 2024
Merged
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
10 changes: 8 additions & 2 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,13 @@ std::string CodegenCoreneuronCppVisitor::get_variable_name(const std::string& na
auto i =
std::find_if(codegen_int_variables.begin(), codegen_int_variables.end(), index_comparator);
if (i != codegen_int_variables.end()) {
return int_variable_name(*i, varname, use_instance);
auto full_name = int_variable_name(*i, varname, use_instance);
auto pos = position_of_int_var(varname);

if (info.semantics[pos].name == naming::RANDOM_SEMANTIC) {
return "(nrnran123_State*) " + full_name;
}
return full_name;
}

// global variable
Expand Down Expand Up @@ -1638,7 +1644,7 @@ void CodegenCoreneuronCppVisitor::print_instance_variable_setup() {
printer->push_block("for (int id = 0; id < nodecount; id++)");
for (const auto& var: info.random_variables) {
const auto& name = get_variable_name(var->get_name());
printer->fmt_line("nrnran123_deletestream((nrnran123_State*){});", name);
printer->fmt_line("nrnran123_deletestream({});", name);
}
printer->pop_block();
}
Expand Down
6 changes: 0 additions & 6 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,6 @@ void CodegenCppVisitor::print_function_call(const FunctionCall& node) {
}
}

// first argument to random functions need to be type casted
// from void* to nrnran123_State*.
if (is_random_function && !arguments.empty()) {
printer->add_text("(nrnran123_State*)");
}

print_vector_elements(arguments, ", ");
printer->add_text(')');
}
Expand Down
7 changes: 4 additions & 3 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ std::string CodegenNeuronCppVisitor::int_variable_name(const IndexVariableInfo&
auto position = position_of_int_var(name);

if (info.semantics[position].name == naming::RANDOM_SEMANTIC) {
return fmt::format("_ppvar[{}].literal_value<void*>()", position);
return fmt::format("(nrnran123_State*) _ppvar[{}].literal_value<void*>()", position);
}

if (info.semantics[position].name == naming::FOR_NETCON_SEMANTIC) {
Expand Down Expand Up @@ -2034,8 +2034,9 @@ void CodegenNeuronCppVisitor::print_nrn_alloc() {

if (!info.random_variables.empty()) {
for (const auto& rv: info.random_variables) {
printer->fmt_line("{} = nrnran123_newstream();",
get_variable_name(get_name(rv), false));
auto position = position_of_int_var(get_name(rv));
printer->fmt_line("_ppvar[{}].literal_value<void*>() = nrnran123_newstream();",
position);
}
printer->fmt_line("nrn_mech_inst_destruct[mech_type] = neuron::{};",
method_name(naming::NRN_DESTRUCTOR_METHOD));
Expand Down
Loading