|
| 1 | +// Copyright (c) 2020 Bita Hasheminezhad |
| 2 | +// Copyright (c) 2020 Hartmut Kaiser |
| 3 | +// |
| 4 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | + |
| 7 | +#if !defined(PHYLANX_UTIL_DETAIL_RANGE_DIMENSION) |
| 8 | +#define PHYLANX_UTIL_DETAIL_RANGE_DIMENSION |
| 9 | + |
| 10 | +#include <array> |
| 11 | +#include <cstddef> |
| 12 | +#include <string> |
| 13 | + |
| 14 | +namespace phylanx { namespace util { namespace detail { |
| 15 | + |
| 16 | + inline std::size_t extract_range_num_dimensions( |
| 17 | + phylanx::ir::range const& shape) |
| 18 | + { |
| 19 | + return shape.size(); |
| 20 | + } |
| 21 | + |
| 22 | + inline std::array<std::size_t, PHYLANX_MAX_DIMENSIONS> |
| 23 | + extract_positive_range_dimensions(phylanx::ir::range const& shape, |
| 24 | + std::string const& name, std::string const& codename) |
| 25 | + { |
| 26 | + std::array<std::size_t, PHYLANX_MAX_DIMENSIONS> result = {0}; |
| 27 | + if (!shape.empty()) |
| 28 | + { |
| 29 | + if (shape.size() == 1) |
| 30 | + { |
| 31 | + result[0] = extract_scalar_positive_integer_value_strict( |
| 32 | + *shape.begin(), name, codename); |
| 33 | + } |
| 34 | + else if (shape.size() == 2) |
| 35 | + { |
| 36 | + auto elem_1 = shape.begin(); |
| 37 | + result[0] = extract_scalar_positive_integer_value_strict( |
| 38 | + *elem_1, name, codename); |
| 39 | + result[1] = extract_scalar_positive_integer_value_strict( |
| 40 | + *++elem_1, name, codename); |
| 41 | + } |
| 42 | + else if (shape.size() == 3) |
| 43 | + { |
| 44 | + auto elem_1 = shape.begin(); |
| 45 | + result[0] = extract_scalar_positive_integer_value_strict( |
| 46 | + *elem_1, name, codename); |
| 47 | + result[1] = extract_scalar_positive_integer_value_strict( |
| 48 | + *++elem_1, name, codename); |
| 49 | + result[2] = extract_scalar_positive_integer_value_strict( |
| 50 | + *++elem_1, name, codename); |
| 51 | + } |
| 52 | + else if (shape.size() == 4) |
| 53 | + { |
| 54 | + auto elem_1 = shape.begin(); |
| 55 | + result[0] = extract_scalar_positive_integer_value_strict( |
| 56 | + *elem_1, name, codename); |
| 57 | + result[1] = extract_scalar_positive_integer_value_strict( |
| 58 | + *++elem_1, name, codename); |
| 59 | + result[2] = extract_scalar_positive_integer_value_strict( |
| 60 | + *++elem_1, name, codename); |
| 61 | + result[3] = extract_scalar_positive_integer_value_strict( |
| 62 | + *++elem_1, name, codename); |
| 63 | + } |
| 64 | + } |
| 65 | + return result; |
| 66 | + } |
| 67 | + |
| 68 | + inline std::array<std::size_t, PHYLANX_MAX_DIMENSIONS> |
| 69 | + extract_nonneg_range_dimensions(phylanx::ir::range const& shape, |
| 70 | + std::string const& name, std::string const& codename) |
| 71 | + { |
| 72 | + std::array<std::size_t, PHYLANX_MAX_DIMENSIONS> result = {0}; |
| 73 | + if (!shape.empty()) |
| 74 | + { |
| 75 | + if (shape.size() == 1) |
| 76 | + { |
| 77 | + result[0] = extract_scalar_nonneg_integer_value_strict( |
| 78 | + *shape.begin(), name, codename); |
| 79 | + } |
| 80 | + else if (shape.size() == 2) |
| 81 | + { |
| 82 | + auto elem_1 = shape.begin(); |
| 83 | + result[0] = extract_scalar_nonneg_integer_value_strict( |
| 84 | + *elem_1, name, codename); |
| 85 | + result[1] = extract_scalar_nonneg_integer_value_strict( |
| 86 | + *++elem_1, name, codename); |
| 87 | + } |
| 88 | + else if (shape.size() == 3) |
| 89 | + { |
| 90 | + auto elem_1 = shape.begin(); |
| 91 | + result[0] = extract_scalar_nonneg_integer_value_strict( |
| 92 | + *elem_1, name, codename); |
| 93 | + result[1] = extract_scalar_nonneg_integer_value_strict( |
| 94 | + *++elem_1, name, codename); |
| 95 | + result[2] = extract_scalar_nonneg_integer_value_strict( |
| 96 | + *++elem_1, name, codename); |
| 97 | + } |
| 98 | + else if (shape.size() == 4) |
| 99 | + { |
| 100 | + auto elem_1 = shape.begin(); |
| 101 | + result[0] = extract_scalar_nonneg_integer_value_strict( |
| 102 | + *elem_1, name, codename); |
| 103 | + result[1] = extract_scalar_nonneg_integer_value_strict( |
| 104 | + *++elem_1, name, codename); |
| 105 | + result[2] = extract_scalar_nonneg_integer_value_strict( |
| 106 | + *++elem_1, name, codename); |
| 107 | + result[3] = extract_scalar_nonneg_integer_value_strict( |
| 108 | + *++elem_1, name, codename); |
| 109 | + } |
| 110 | + } |
| 111 | + return result; |
| 112 | + } |
| 113 | +}}} |
| 114 | +#endif |
0 commit comments