STEllAR-GROUP / phylanx

An Asynchronous Distributed C++ Array Processing Toolkit
Boost Software License 1.0
75 stars 76 forks source link

Restricting annotate_d #1181

Closed taless474 closed 4 years ago

taless474 commented 4 years ago

This PR is an attempt to resolve #1160. It considers having empty arrays and show them with an empty array and invalid (0, 0) spans on each dimension. annotate_d checks annotation to comply with the array in the number of dimensions and size of each dimension. It also considers that the whole span on each dimension starts from 0 and there is no gap between parts of it while it can accept overlaps. These are the annotation samples that will throw exceptions:

// does not start from 0
void test_annotation_4()
{
    if (hpx::get_locality_id() == 0)
    {
        std::string annotation_0 = R"(
            annotate_d([], "test_annotation_4_1",
                list("args",
                    list("locality", 0, 2),
                    list("tile", list("rows", 0, 0))))
        )";

        compile_and_run("test_annotation_4", annotation_0);
    }
    else
    {
        std::string annotation_0 = R"(
            annotate_d([3, 4, 5], "test_annotation_4_1",
                list("args",
                    list("locality", 1, 2),
                    list("tile", list("rows", 1, 4))))
        )";

        compile_and_run("test_annotation_4", annotation_0);
    }
}
// on locality 0 we have a vector while on locality 1 we have a matrix
void test_annotation_4()
{
    if (hpx::get_locality_id() == 0)
    {
        std::string annotation_0 = R"(
            annotate_d([1, 2], "test_annotation_4_1",
                list("args",
                    list("locality", 0, 2),
                    list("tile", list("columns", 0, 2))))
        )";

        compile_and_run("test_annotation_4", annotation_0);
    }
    else
    {
        std::string annotation_0 = R"(
            annotate_d([[3, 4, 5]], "test_annotation_4_1",
                list("args",
                    list("locality", 1, 2),
                    list("tile", list("columns", 2, 5),list("rows", 0, 1))))
        )";

        compile_and_run("test_annotation_4", annotation_0);
    }
}
// a vector cannot be a mix of rows and columns on different localities
void test_annotation_4()
{
    if (hpx::get_locality_id() == 0)
    {
        std::string annotation_0 = R"(
            annotate_d([1, 2], "test_annotation_4_1",
                list("args",
                    list("locality", 0, 2),
                    list("tile", list("columns", 0, 2))))
        )";

        compile_and_run("test_annotation_4", annotation_0);
    }
    else
    {
        std::string annotation_0 = R"(
            annotate_d([3, 4, 5], "test_annotation_4_1",
                list("args",
                    list("locality", 1, 2),
                    list("tile", list("rows", 2, 5))))
        )";

        compile_and_run("test_annotation_4", annotation_0);
    }
}