Skip to content
Snippets Groups Projects
Commit 2ced7e2c authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix few issues wrt R^dxd and add missing affectation tests

- fix tuple affectation for none list rhs
- fix affection for R^1x1
parent 7edf1e0a
No related branches found
No related tags found
1 merge request!71Feature/language tiny matrices
...@@ -153,6 +153,21 @@ class AffectationExecutor final : public IAffectationExecutor ...@@ -153,6 +153,21 @@ class AffectationExecutor final : public IAffectationExecutor
} }
}, },
rhs); rhs);
} else if constexpr (std::is_same_v<TinyMatrix<1>, ValueT>) {
std::visit(
[&](auto&& v) {
using Vi_T = std::decay_t<decltype(v)>;
if constexpr (std::is_convertible_v<Vi_T, double>) {
m_lhs = v;
} else {
// LCOV_EXCL_START
throw UnexpectedError("unexpected rhs type in affectation");
// LCOV_EXCL_STOP
}
},
rhs);
} else {
throw UnexpectedError("invalid value type");
} }
} else { } else {
AffOp<OperatorT>().eval(m_lhs, std::get<DataT>(rhs)); AffOp<OperatorT>().eval(m_lhs, std::get<DataT>(rhs));
...@@ -599,14 +614,12 @@ class AffectationToTupleProcessor final : public INodeProcessor ...@@ -599,14 +614,12 @@ class AffectationToTupleProcessor final : public INodeProcessor
os << v; os << v;
*m_lhs = std::vector<std::string>{os.str()}; *m_lhs = std::vector<std::string>{os.str()};
} }
} else if constexpr (std::is_same_v<ValueT, TinyVector<1>> and std::is_arithmetic_v<T>) { } else if constexpr ((std::is_same_v<ValueT, TinyVector<1>> or
*m_lhs = std::vector<TinyVector<1>>{TinyVector<1>{static_cast<double>(v)}}; std::is_same_v<ValueT, TinyMatrix<1>>)and std::is_arithmetic_v<T>) {
} else if constexpr (std::is_same_v<ValueT, TinyVector<2>> and std::is_same_v<T, int64_t>) { *m_lhs = std::vector<ValueT>{ValueT{static_cast<double>(v)}};
Assert(v == 0); } else if constexpr ((is_tiny_vector_v<ValueT> or is_tiny_matrix_v<ValueT>)and std::is_same_v<T, int64_t>) {
*m_lhs = std::vector<TinyVector<2>>{TinyVector<2>{zero}};
} else if constexpr (std::is_same_v<ValueT, TinyVector<3>> and std::is_same_v<T, int64_t>) {
Assert(v == 0); Assert(v == 0);
*m_lhs = std::vector<TinyVector<3>>{TinyVector<3>{zero}}; *m_lhs = std::vector<ValueT>{ValueT{zero}};
} else { } else {
// LCOV_EXCL_START // LCOV_EXCL_START
throw ParseError("unexpected error: unexpected right hand side type in affectation", m_node.begin()); throw ParseError("unexpected error: unexpected right hand side type in affectation", m_node.begin());
......
...@@ -21,6 +21,11 @@ AffectationRegisterForRnxn<Dimension>::_register_eq_op() ...@@ -21,6 +21,11 @@ AffectationRegisterForRnxn<Dimension>::_register_eq_op()
std::vector<std::shared_ptr<const ASTNodeDataType>>{}), std::vector<std::shared_ptr<const ASTNodeDataType>>{}),
std::make_shared<AffectationToTinyMatrixFromListProcessorBuilder< std::make_shared<AffectationToTinyMatrixFromListProcessorBuilder<
language::eq_op, TinyMatrix<Dimension>>>()); language::eq_op, TinyMatrix<Dimension>>>());
repository
.addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rnxn),
ASTNodeDataType::build<ASTNodeDataType::int_t>(),
std::make_shared<AffectationToTupleProcessorBuilder<TinyMatrix<Dimension>>>());
} }
template <> template <>
...@@ -49,25 +54,25 @@ AffectationRegisterForRnxn<1>::_register_eq_op() ...@@ -49,25 +54,25 @@ AffectationRegisterForRnxn<1>::_register_eq_op()
language::eq_op>(Rnxn, ASTNodeDataType::build<ASTNodeDataType::double_t>(), language::eq_op>(Rnxn, ASTNodeDataType::build<ASTNodeDataType::double_t>(),
std::make_shared<AffectationProcessorBuilder<language::eq_op, TinyMatrix<Dimension>, double>>()); std::make_shared<AffectationProcessorBuilder<language::eq_op, TinyMatrix<Dimension>, double>>());
// repository repository
// .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rn), .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rnxn),
// ASTNodeDataType::build<ASTNodeDataType::bool_t>(), ASTNodeDataType::build<ASTNodeDataType::bool_t>(),
// std::make_shared<AffectationToTupleProcessorBuilder<TinyVector<Dimension>>>()); std::make_shared<AffectationToTupleProcessorBuilder<TinyMatrix<Dimension>>>());
// repository repository
// .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rn), .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rnxn),
// ASTNodeDataType::build<ASTNodeDataType::unsigned_int_t>(), ASTNodeDataType::build<ASTNodeDataType::unsigned_int_t>(),
// std::make_shared<AffectationToTupleProcessorBuilder<TinyVector<Dimension>>>()); std::make_shared<AffectationToTupleProcessorBuilder<TinyMatrix<Dimension>>>());
// repository repository
// .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rn), .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rnxn),
// ASTNodeDataType::build<ASTNodeDataType::int_t>(), ASTNodeDataType::build<ASTNodeDataType::int_t>(),
// std::make_shared<AffectationToTupleProcessorBuilder<TinyVector<Dimension>>>()); std::make_shared<AffectationToTupleProcessorBuilder<TinyMatrix<Dimension>>>());
// repository repository
// .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rn), .addAffectation<language::eq_op>(ASTNodeDataType::build<ASTNodeDataType::tuple_t>(Rnxn),
// ASTNodeDataType::build<ASTNodeDataType::double_t>(), ASTNodeDataType::build<ASTNodeDataType::double_t>(),
// std::make_shared<AffectationToTupleProcessorBuilder<TinyVector<Dimension>>>()); std::make_shared<AffectationToTupleProcessorBuilder<TinyMatrix<Dimension>>>());
} }
template <size_t Dimension> template <size_t Dimension>
......
...@@ -79,6 +79,23 @@ let s :(string); s = x; ...@@ -79,6 +79,23 @@ let s :(string); s = x;
let s :(R^1); s = 1.3; let s :(R^1); s = 1.3;
)", )",
"s", (std::vector<TinyVector<1>>{TinyVector<1>{1.3}})); "s", (std::vector<TinyVector<1>>{TinyVector<1>{1.3}}));
const std::string A_string = []() -> std::string {
std::ostringstream os;
os << TinyMatrix<2, double>{1, 2, 3, 4};
return os.str();
}();
CHECK_AFFECTATION_RESULT(R"(
let A :R^2x2, A = (1,2,3,4);
let s :(string); s = A;
)",
"s", (std::vector<std::string>{A_string}));
CHECK_AFFECTATION_RESULT(R"(
let s :(R^1x1); s = 1.3;
)",
"s", (std::vector<TinyMatrix<1>>{TinyMatrix<1>{1.3}}));
} }
SECTION("Affectations from list") SECTION("Affectations from list")
...@@ -137,6 +154,45 @@ let x : R^1, x = 1; ...@@ -137,6 +154,45 @@ let x : R^1, x = 1;
let t :(R^1); t = (x,2); let t :(R^1); t = (x,2);
)", )",
"t", (std::vector<TinyVector<1>>{TinyVector<1>{1}, TinyVector<1>{2}})); "t", (std::vector<TinyVector<1>>{TinyVector<1>{1}, TinyVector<1>{2}}));
const std::string A_string = []() -> std::string {
std::ostringstream os;
os << TinyMatrix<2, double>{1, 2, 3, 4};
return os.str();
}();
CHECK_AFFECTATION_RESULT(R"(
let A : R^2x2, A = (1,2,3,4);
let s : (string); s = (2.,3, A);
)",
"s", (std::vector<std::string>{std::to_string(2.), std::to_string(3), A_string}));
CHECK_AFFECTATION_RESULT(R"(
let A : R^2x2, A = (1,2,3,4);
let t :(R^2x2); t = (A,0);
)",
"t", (std::vector<TinyMatrix<2>>{TinyMatrix<2>{1, 2, 3, 4}, TinyMatrix<2>{0, 0, 0, 0}}));
CHECK_AFFECTATION_RESULT(R"(
let t :(R^2x2); t = ((1,2,3,4),0);
)",
"t", (std::vector<TinyMatrix<2>>{TinyMatrix<2>{1, 2, 3, 4}, TinyMatrix<2>{0, 0, 0, 0}}));
CHECK_AFFECTATION_RESULT(R"(
let t :(R^2x2); t = (0);
)",
"t", (std::vector<TinyMatrix<2>>{TinyMatrix<2>{0, 0, 0, 0}}));
CHECK_AFFECTATION_RESULT(R"(
let t :(R^3x3); t = 0;
)",
"t", (std::vector<TinyMatrix<3>>{TinyMatrix<3>{0, 0, 0, 0, 0, 0, 0, 0, 0}}));
CHECK_AFFECTATION_RESULT(R"(
let x : R^1x1, x = 1;
let t :(R^1x1); t = (x,2);
)",
"t", (std::vector<TinyMatrix<1>>{TinyMatrix<1>{1}, TinyMatrix<1>{2}}));
} }
SECTION("Affectations from tuple") SECTION("Affectations from tuple")
...@@ -153,6 +209,18 @@ let s :(string); s = x; ...@@ -153,6 +209,18 @@ let s :(string); s = x;
)", )",
"s", (std::vector<std::string>{x_string})); "s", (std::vector<std::string>{x_string}));
const std::string A_string = []() -> std::string {
std::ostringstream os;
os << TinyMatrix<3, double>{1, 2, 3, 4, 5, 6, 7, 8, 9};
return os.str();
}();
CHECK_AFFECTATION_RESULT(R"(
let A :(R^3x3), A = ((1,2,3,4,5,6,7,8,9));
let s :(string); s = A;
)",
"s", (std::vector<std::string>{A_string}));
CHECK_AFFECTATION_RESULT(R"( CHECK_AFFECTATION_RESULT(R"(
let x :(R), x = (1,2,3); let x :(R), x = (1,2,3);
let s :(string); s = x; let s :(string); s = x;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment