dpilger26 / NumCpp

C++ implementation of the Python Numpy library
https://dpilger26.github.io/NumCpp
MIT License
3.55k stars 550 forks source link

Slicing with signed 32-bit and (un-)signed 64-bit indices #177

Closed jurihock closed 1 year ago

jurihock commented 1 year ago

Describe the bug

Unable to perform slicing with index arrays of type:

due to errors at compile time, e.g.:

Slicing just with scalars of mentioned data types and nc::NdArray<uint32_t> arrays works as expected.

To Reproduce

#include <iostream>
#include <NumCpp.hpp>

int main()
{
  nc::NdArray<double> lut = { 1, 2, 3 };

  const uint64_t a = 0;
  const int64_t b = -3;

  const nc::NdArray<uint64_t> c = { 2, 1, 0 };
  const nc::NdArray<int64_t> d = { -1, -2, -3 };

  const nc::NdArray<uint32_t> e = { 2, 1, 0 };
  const nc::NdArray<int32_t> f = { -1, -2, -3 };

  std::cout << lut[a] << std::endl; // 1
  std::cout << lut[b] << std::endl; // 1

  std::cout << lut[c] << std::endl; // error
  std::cout << lut[d] << std::endl; // error

  std::cout << lut[e] << std::endl; // [[3, 2, 1, ]]
  std::cout << lut[f] << std::endl; // error

  return 0;
}

Expected behavior

At least no compile time errors, even with signed and 64-bit indices.

References

https://github.com/dpilger26/NumCpp/issues/103

dpilger26 commented 1 year ago

Fixed in Release Version 2.10.0.