Skip to content

Commit

Permalink
Refactor variable name of random variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Oct 30, 2024
1 parent 41f0815 commit 991d55f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
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
1 change: 0 additions & 1 deletion src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
/* Common helper routines accross codegen functions */
/****************************************************************************************/


/**
* Determine the position in the data array for a given float variable
* \param name The name of a float variable
Expand Down

0 comments on commit 991d55f

Please sign in to comment.