Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make simd and simd_mask ranges #40

Open
someonewithpc opened this issue Aug 13, 2023 · 0 comments
Open

Make simd and simd_mask ranges #40

someonewithpc opened this issue Aug 13, 2023 · 0 comments

Comments

@someonewithpc
Copy link

someonewithpc commented Aug 13, 2023

version / revision Operating System Compiler & Version Compiler Flags CPU
? All All All All

Motivation

The library already provides indexed access. Providing a range interface/iterator access would allow the type to be used with all STL functions. Event though it would degrade to doing it element-wise, it would still vastly increase the ergonomics when some specific utility is not directly available for the simd type. It could also pave the way for specializing some STL functions, like std::min_element, instead of providing hmin, addressing #18

Let me know if you think this is a direction worth taking and I can write a PR

Testcase

#include <experimental/simd>
#include <iostream>

namespace stdx = std::experimental;

int main() {
  stdx::native_simd<int> a{[](int i) { return 2 << (i - 1); }};

  for (auto v : a) {
    std::cout << v << '\n';
  }
}

Actual Results

$ g++ simd-range.cpp && ./a.out 
simd-range.cpp: In function ‘int main()’:
simd-range.cpp:13:17: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
   13 |   for (auto v : a) {
      |                 ^
      |                 std::begin
In file included from /usr/include/c++/13.2.1/string:53,
                 from /usr/include/c++/13.2.1/bitset:52,
                 from /usr/include/c++/13.2.1/experimental/bits/simd.h:33,
                 from /usr/include/c++/13.2.1/experimental/simd:74,
                 from simd-range.cpp:1:
/usr/include/c++/13.2.1/bits/range_access.h:114:37: note: ‘std::begin’ declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
simd-range.cpp:13:17: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
   13 |   for (auto v : a) {
      |                 ^
      |                 std::end
/usr/include/c++/13.2.1/bits/range_access.h:116:37: note: ‘std::end’ declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      | 

Expected Results

0
2
4
8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant