Fastor icon indicating copy to clipboard operation
Fastor copied to clipboard

Investigate overloading operator() with std::initializer_list

Open romeric opened this issue 7 years ago • 2 comments

The operator() for tensors could be overloaded to provide a similar functionality to seq, fseq and iseq, like so

operator()(std::initializer_list<int> _s1, std::initializer_list<int> _s2);

The tensor could then be indexed like

Tensor<double,4,4> A;
A({0,3},{1,3,2}) = 42.;

This would be pretty easy to achieve by just providing a std::initializer_list constructor to seq. Note that std::initializer_list constructors themselves are constexpr.

This should however, be investigated, as at the moment Tensor class also has std::initializer_list constructor and the above syntax already works but gives incorrect results and also this syntax seems more appropriate for TensorRandomViews than TensorViews. In the sense, that it alludes to slicing a tensor with two vectors rather than with sequentially ascending ranges.

romeric avatar Apr 18 '17 01:04 romeric

901f471 fixes the bug part of this issue.

romeric avatar May 15 '17 15:05 romeric

This would also allow for code like this:

  Tensor<int,9> v{0, 1, 2, 3, 4, 5, 6, 7, 8};
  v({6, 3, 0}) = v({1, 2, 3});

which is possible with Eigen3. Right now I have to define intermediate tensors to accomplish this:

  Tensor<int,9> v{0, 1, 2, 3, 4, 5, 6, 7, 8};
  Tensor<int,3> i{6, 3, 0};
  Tensor<int,3> j{1, 2, 3};
  v(i) = v(j);

pauljurczak avatar Nov 07 '20 04:11 pauljurczak