| 62 | // Return a tensor element at a specified coordinate with different border modes |
| 63 | template <typename T> |
| 64 | T tensor_elem_at(const SimpleTensor<T> &src, Coordinates coord, BorderMode border_mode, T constant_border_value) |
| 65 | { |
| 66 | const int x = coord.x(); |
| 67 | const int y = coord.y(); |
| 68 | const int z = coord.z(); |
| 69 | const int width = src.shape().x(); |
| 70 | const int height = src.shape().y(); |
| 71 | const int depth = src.shape().z(); |
| 72 | |
| 73 | // If coordinates beyond range of tensor's width or height |
| 74 | if (x < 0 || y < 0 || z < 0 || x >= width || y >= height || z >= depth) |
| 75 | { |
| 76 | if (border_mode == BorderMode::REPLICATE) |
| 77 | { |
| 78 | coord.set(0, std::max(0, std::min(x, width - 1))); |
| 79 | coord.set(1, std::max(0, std::min(y, height - 1))); |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | return constant_border_value; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return src[coord2index(src.shape(), coord)]; |
| 88 | } |
| 89 | |
| 90 | #pragma GCC diagnostic pop |
| 91 |
no test coverage detected