| 9 | array create_or_kernel(array&& a, array&& b); |
| 10 | |
| 11 | class not_kernel_expression |
| 12 | { |
| 13 | public: |
| 14 | not_kernel_expression(array&& a) |
| 15 | : a_(std::move(a)) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | not_kernel_expression(const not_kernel_expression&) = default; |
| 20 | not_kernel_expression& operator=(const not_kernel_expression&) = delete; |
| 21 | not_kernel_expression(not_kernel_expression&&) noexcept = default; |
| 22 | not_kernel_expression& operator=(not_kernel_expression&&) noexcept = default; |
| 23 | |
| 24 | ~not_kernel_expression() = default; |
| 25 | |
| 26 | enum dtype dtype() const |
| 27 | { |
| 28 | return dtype::boolean; |
| 29 | } |
| 30 | |
| 31 | icm::shape shape() const |
| 32 | { |
| 33 | return a_.shape(); |
| 34 | } |
| 35 | |
| 36 | bool value(int64_t index) const |
| 37 | { |
| 38 | return !a_.value<bool>(index); |
| 39 | } |
| 40 | |
| 41 | using iterator = chained_iterator<nd::array (*)(nd::array&&), nd::iterator>; |
| 42 | |
| 43 | iterator begin() const |
| 44 | { |
| 45 | return iterator(create_not_kernel, a_.begin()); |
| 46 | } |
| 47 | |
| 48 | iterator end() const |
| 49 | { |
| 50 | return iterator(create_not_kernel, a_.end()); |
| 51 | } |
| 52 | |
| 53 | array get(int64_t index) const |
| 54 | { |
| 55 | return create_not_kernel(a_[index]); |
| 56 | } |
| 57 | |
| 58 | array eval() const |
| 59 | { |
| 60 | auto a = ::nd::eval(a_); |
| 61 | return switch_numeric_dtype(a.dtype(), [&a]<typename U>() { |
| 62 | auto sp = a.template data<U>(); |
| 63 | icm::vector<bool> res; |
| 64 | res.reserve(sp.size()); |
| 65 | for (auto v : sp) { |
| 66 | res.push_back(!v); |
| 67 | } |
| 68 | return ::nd::adapt(std::move(res), a.shape()); |