Skip to content

Commit

Permalink
Formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
whart222 committed Feb 7, 2023
1 parent 771d851 commit ac8f206
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 50 deletions.
5 changes: 2 additions & 3 deletions lib/coek/coek/api/parameter_assoc_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace coek {


//
// ParameterAssocArrayRepn
//
Expand Down Expand Up @@ -56,9 +55,9 @@ void ParameterAssocArrayRepn::name(const std::string& name)
// If the string is empty, then we reset the names of all variables
if (name.size() == 0) {
for (auto& var : values) var.name(name);
}
}
// Otherwise, we re-generate the names
else
else
generate_names();
}
}
Expand Down
23 changes: 13 additions & 10 deletions lib/coek/coek/api/variable_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class VariableArrayRepn : public VariableAssocArrayRepn {
cache.resize((size() + 1) * (dim() + 1));
}

/*
VariableArrayRepn(const std::vector<int>& _shape) : _size(1)
{
shape.resize(_shape.size());
for (size_t i = 0; i < shape.size(); ++i) shape[i] = static_cast<size_t>(_shape[i]);
for (auto n : shape) _size *= n;
cache.resize((size() + 1) * (dim() + 1));
}
*/
/*
VariableArrayRepn(const std::vector<int>& _shape) : _size(1)
{
shape.resize(_shape.size());
for (size_t i = 0; i < shape.size(); ++i) shape[i] = static_cast<size_t>(_shape[i]);
for (auto n : shape) _size *= n;
cache.resize((size() + 1) * (dim() + 1));
}
*/

VariableArrayRepn(const std::initializer_list<size_t>& _shape) : shape(_shape), _size(1)
{
Expand Down Expand Up @@ -152,7 +152,10 @@ void VariableArray::index_error(size_t i)
throw std::runtime_error(err);
}

VariableArray::const_iterator VariableArray::cbegin() const noexcept { return repn->values.begin(); }
VariableArray::const_iterator VariableArray::cbegin() const noexcept
{
return repn->values.begin();
}

VariableArray::const_iterator VariableArray::cend() const noexcept { return repn->values.end(); }

Expand Down
4 changes: 2 additions & 2 deletions lib/coek/coek/api/variable_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class VariableArray : public VariableAssocArray {

void collect_args(size_t i, int arg)
{
assert(arg >= 0); // TODO - Resolve coverage for this assertion
assert(arg >= 0); // TODO - Resolve coverage for this assertion
tmp[i] = arg;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ class VariableArray : public VariableAssocArray {
public:
VariableArray(size_t n);
VariableArray(const std::vector<size_t>& shape);
//VariableArray(const std::vector<int>& shape);
// VariableArray(const std::vector<int>& shape);
VariableArray(const std::initializer_list<size_t>& shape);
~VariableArray() {}

Expand Down
4 changes: 2 additions & 2 deletions lib/coek/coek/api/variable_assoc_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ void VariableAssocArrayRepn::fixed(bool value)

void VariableAssocArrayRepn::name(const std::string& name)
{
variable_template.name(name);
variable_template.name(name);
if (values.size() > 0) {
// If the string is empty, then we reset the names of all variables
if (name.size() == 0) {
for (auto& var : values) var.name(name);
for (auto& var : values) var.name(name);
}
// Otherwise, we re-generate the names
else
Expand Down
8 changes: 4 additions & 4 deletions lib/coek/test/test_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ TEST_CASE("1D_param_array", "[smoke]")
WHEN("value - 1")
{
auto params = coek::parameter(4);

// Set value using template
params.value(1);
for (size_t i = 0; i < 4; i++) REQUIRE(params(i).value() == 1);

// Set value for all indices
params.value(2);
for (size_t i = 0; i < 4; i++) REQUIRE(params(i).value() == 2);
Expand Down Expand Up @@ -348,8 +348,8 @@ TEST_CASE("1D_param_array", "[smoke]")
params.generate_names();
for (int i = 0; i < 4; i++) REQUIRE(params(i).name() == "v[" + std::to_string(i) + "]");

// We don't need to call generate_names() again. Names are automatically generated after
// the first time.
// We don't need to call generate_names() again. Names are automatically generated
// after the first time.
params.name("w");
for (int i = 0; i < 4; i++) REQUIRE(params(i).name() == "w[" + std::to_string(i) + "]");

Expand Down
21 changes: 9 additions & 12 deletions lib/coek/test/test_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,16 @@ TEST_CASE("1D_var_array", "[smoke]")
{
auto vars = coek::variable(4);
auto q = coek::parameter().value(2);

// Set value using template
vars.value(q + (int)2); // TODO - generalize API to include unsigned ints
for (size_t i = 0; i < 4; i++) REQUIRE(vars(i).value() == 4);

// Set value for all indices
vars.value(q + (int)3);
for (size_t i = 0; i < 4; i++) REQUIRE(vars(i).value() == 5);
}

WHEN("name")
{
auto vars = coek::variable(4);
Expand All @@ -397,17 +397,17 @@ TEST_CASE("1D_var_array", "[smoke]")
vars.generate_names();
for (int i = 0; i < 4; i++) REQUIRE(vars(i).name() == "v[" + std::to_string(i) + "]");

// We don't need to call generate_names() again. Names are automatically generated after
// the first time.
// We don't need to call generate_names() again. Names are automatically generated
// after the first time.
vars.name("w");
REQUIRE(vars.name() == "w");
for (int i = 0; i < 4; i++) REQUIRE(vars(i).name() == "w[" + std::to_string(i) + "]");

vars.name("");
REQUIRE(vars.name() == "");
for (int i = 0; i < 4; i++) REQUIRE(vars(i).name()[0] == 'X');
}

WHEN("name")
{
auto vars = coek::variable(4).name("v").generate_names();
Expand All @@ -417,12 +417,10 @@ TEST_CASE("1D_var_array", "[smoke]")
WHEN("iter")
{
auto vars = coek::variable(4).value(1);
for (auto& v : vars)
REQUIRE(v.value() == 1);
for (auto& v : vars) REQUIRE(v.value() == 1);

decltype(vars)::const_iterator it;
for (it = vars.cbegin(); it < vars.cend(); ++it)
REQUIRE(it->value() == 1);
for (it = vars.cbegin(); it < vars.cend(); ++it) REQUIRE(it->value() == 1);
}

WHEN("fixed")
Expand Down Expand Up @@ -1094,7 +1092,6 @@ TEST_CASE("var_array_api", "[smoke]")
}
#endif


#if __cpp_lib_variant
TEST_CASE("ND_var_array_errors", "[smoke]")
{
Expand Down
34 changes: 17 additions & 17 deletions lib/coek/test/test_visitor_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
#include "coek/coek.hpp"
#include "coek/util/io_utils.hpp"

#define INTRINSIC_TEST1(FN) \
WHEN(#FN) \
{ \
{ \
#define INTRINSIC_TEST1(FN) \
WHEN(#FN) \
{ \
{ \
auto v = coek::variable("v").lower(0).upper(1).value(0); \
coek::Expression e = FN(v + 1); \
double tmp = 1.0 * FN(1.0); \
REQUIRE(evaluate_expr(e.repn) == tmp); \
} \
coek::Expression e = FN(v + 1); \
double tmp = 1.0 * FN(1.0); \
REQUIRE(evaluate_expr(e.repn) == tmp); \
} \
}

#define INTRINSIC_TEST2(FN) \
WHEN(#FN " 2") \
{ \
{ \
#define INTRINSIC_TEST2(FN) \
WHEN(#FN " 2") \
{ \
{ \
auto v = coek::variable("v").lower(0).upper(1).value(0); \
coek::Expression e = FN(v + 1, v); \
double tmp = 1.0 * FN(1.0, 0.0); \
REQUIRE(evaluate_expr(e.repn) == tmp); \
} \
coek::Expression e = FN(v + 1, v); \
double tmp = 1.0 * FN(1.0, 0.0); \
REQUIRE(evaluate_expr(e.repn) == tmp); \
} \
}

TEST_CASE("evaluate_expr", "[smoke]")
Expand Down Expand Up @@ -381,7 +381,7 @@ TEST_CASE("evaluate_expr", "[smoke]")
{
{
auto w = coek::variable("w").lower(0).upper(1).value(3);
auto e = coek::pow(w, w-1);
auto e = coek::pow(w, w - 1);

REQUIRE(evaluate_expr(e.repn) == 9.0);
}
Expand Down

0 comments on commit ac8f206

Please sign in to comment.