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 Jul 22, 2024
1 parent b91c0ea commit e76b886
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 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 @@ -932,7 +932,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 @@ -1747,7 +1753,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 @@ -494,12 +494,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
3 changes: 3 additions & 0 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ std::string CodegenNeuronCppVisitor::int_variable_name(const IndexVariableInfo&
const std::string& name,
bool use_instance) const {
auto position = position_of_int_var(name);
if (info.semantics[position].name == naming::RANDOM_SEMANTIC) {
return fmt::format("(nrnran123_State*) _ppvar[{}].get<void*>()", position);
}
if (symbol.is_index) {
if (use_instance) {
throw std::runtime_error("Not implemented. [wiejo]");
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 @@ -124,7 +124,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 e76b886

Please sign in to comment.