Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix creating tensors with np.longlong array#4367

Merged
soumith merged 1 commit into
pytorch:masterfrom
zou3519:np-longlong
Dec 28, 2017
Merged

Fix creating tensors with np.longlong array#4367
soumith merged 1 commit into
pytorch:masterfrom
zou3519:np-longlong

Conversation

@zou3519
Copy link
Copy Markdown
Contributor

@zou3519 zou3519 commented Dec 27, 2017

Fixes #4363.
Fixes #4364.

When one creates an ndarray with np.longlong type, calling .dtype on the ndarray prints np.int64. As far as I can tell, the np.longlong type is equivalent to np.int64.

However, in C code, the NPY_LONGLONG macro has a different value from the NPY_INT64 macro.

This makes it so that we treat NPY_LONGLONG the same way as NPY_INT64. Alternatively, to fix these issues, I could reject NPY_LONGLONG and include better error messages but as far as I can tell np.longlong and np.int64 are the same.

Test Plan

Added a unit test case for creating tensors with np.longlong

Run the following (each script is from a separate issue) on python 2.7 and assert output is correct:

import torch
import numpy as np
any_number = long(2)
a = np.arange(0, any_number)
print(a)
b = torch.Tensor(a)
print(b)
import torch
import numpy as np
any_number = long(2)
a = np.arange(0, any_number)
print(a, a.dtype)
b = torch.from_numpy(a)
print(b)

@soumith soumith merged commit d859c3c into pytorch:master Dec 28, 2017
@zou3519 zou3519 deleted the np-longlong branch January 3, 2018 19:50
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.

Initializing tensor from numpy array results in unexpected values of tensor. Error when initializing tensor from numpy array with correct dtype.

2 participants