Skip to content

Commit

Permalink
Adding x[0] as a no-op when x is a scalar -- required by IMAS mappings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloc committed Oct 10, 2023
1 parent fd108ce commit e91b099
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 0 additions & 2 deletions source/clientserver/nameValueSubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass)
int* placeholderIndex = nullptr;
int* tpassIndex = nullptr;
int tpassPosition = 0;
unsigned short usedCount = 0;

if (nameValueList->pairCount > 0) { // Identify and Count Placeholders
do {
Expand Down Expand Up @@ -135,7 +134,6 @@ int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass)
free(nameValueList->nameValue[placeholderIndex[i]].value);
nameValueList->nameValue[placeholderIndex[i]].value = newNameValueList.nameValue[tpassIndex[i]].value;
newNameValueList.nameValue[tpassIndex[i]].value = nullptr;
usedCount++;

UDA_LOG(UDA_LOG_DEBUG, "Placeholder: [%d][%d] %s, Substitution Value [%d] %s\n", i, placeholderIndex[i],
nameValueList->nameValue[placeholderIndex[i]].name,
Expand Down
2 changes: 0 additions & 2 deletions source/clientserver/parseOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ int parseOperation(SUBSET* sub)

std::string operation = sub->operation[i];

boost::starts_with(operation, "[");

boost::trim_left_if(operation, [](char c){ return c == '['; });
boost::trim_right_if(operation, [](char c){ return c == ']'; });

Expand Down
8 changes: 8 additions & 0 deletions source/server/serverSubsetData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM
{
int n_bound = subset.nbound; // the Number of operations in the set

// treat x[0] as a no-op when x is a scalar
if (n_bound == 1
&& (subset.lbindex[0].init && subset.lbindex[0].value == 0)
&& (subset.ubindex[0].init && subset.ubindex[0].value == 1)
&& data_block->rank == 0) {
return 0;
}

for (int j = 0; j < n_bound; j++) { // Process each operation separately

double value = subset.bound[j];
Expand Down
26 changes: 25 additions & 1 deletion test/plugins/test_testplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ TEST_CASE( "Run test3 - pass string list as array of strings", "[plugins][TESTPL

REQUIRE( data != nullptr );
REQUIRE( !data->isNull() );
REQUIRE( data->type().name() == typeid(std::string).name() );
REQUIRE( std::string(data->type().name()) == typeid(std::string).name() );

auto array = dynamic_cast<uda::Array*>(data);

Expand Down Expand Up @@ -1818,6 +1818,30 @@ TEST_CASE( "Test array subsetting with argument with square brackets", "[plugins
REQUIRE( vec[4] == Approx(4.0) );
}

TEST_CASE( "Test array subsetting - index scalar with [0]", "[plugins][TESTPLUGIN]" )
{
#include "setup.inc"

uda::Client client;

const uda::Result& result = client.get("TESTPLUGIN::test10()[0]", "");

REQUIRE( result.errorCode() == 0 );
REQUIRE( result.errorMessage().empty() );

uda::Data* data = result.data();

REQUIRE( data != nullptr );
REQUIRE( !data->isNull() );
REQUIRE( data->type().name() == typeid(int).name() );

auto* value = dynamic_cast<uda::Scalar*>(data);

REQUIRE( value != nullptr );

REQUIRE( value->as<int>() == 7 );
}

TEST_CASE( "Run call_plugin_test - return the result of calling a plugin", "[plugins][TESTPLUGIN]" )
{
#include "setup.inc"
Expand Down

0 comments on commit e91b099

Please sign in to comment.