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

Add support for signed types #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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