Skip to content

Conversation

@sammymax
Copy link

Even though "int" by default is signed, "signed int" has a different typeid. Although most developers probably won't use "signed int" directly, a lot of compilers define int8_t, int16_t, etc. with these signed types. For example, the following code gives an invalid .npy file (compiled with GCC 7.4.0 on Ubuntu 20.04):

#include <cstdint>
#include <vector>
using namespace std;

#include "cnpy.h"

int main() {
  vector<int8_t> vec(20);
  for (int i = 0; i < 20; i++) vec[i] = 2 * i;
  cnpy::npy_save("hi.npy", vec.data(), {20});
}

When I try to load hi.npy in Python, I get the following error: ValueError: descr is not a valid dtype descriptor: '<?1' because cnpy couldn't decide if int8_t was signed or not.

Even though "int" by default is signed, "signed int" has a different typeid.
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

Successfully merging this pull request may close these issues.

1 participant