Slicing with signed 32-bit and (un-)signed 64-bit indices
jurihock opened this issue · comments
Jürgen Hock commented
Describe the bug
Unable to perform slicing with index arrays of type:
nc::NdArray<uint64_t>
nc::NdArray<int64_t>
nc::NdArray<int32_t>
due to errors at compile time, e.g.:
- NdArrayCore.hpp: note: candidate function not viable: no known conversion from 'const NdArray<...>' to 'const NdArray<...>' for 1st argument
- NdArrayCore.hpp: note: candidate template ignored: requirement 'is_same_v<nc::NdArray<..., std::allocator<...>>, nc::NdArray<unsigned int, std::allocator>>' was not satisfied [with Indices = nc::NdArray<...>]
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
David Pilger commented
Fixed in Release Version 2.10.0.