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

int vs. np.int #38

Closed
davlars opened this issue Oct 19, 2016 · 6 comments
Closed

int vs. np.int #38

davlars opened this issue Oct 19, 2016 · 6 comments

Comments

@davlars
Copy link

davlars commented Oct 19, 2016

Some methods requiring (python-native) int-inputs (e.g. AtomicNumberToSymbol) seem to be crashing in the case that a non-native int (e.g. numpy.int) is provided. Is perhaps good to know (perhaps the issue could be solved by envoking np.asscalar for numpy inputs, but I'm not sure if that covers all potential input-problems)

@tschoonj
Copy link
Owner

I cannot seem to reproduce this (or maybe I am not understanding your issue 😄 ) on a RHEL6 Linux box running python 2.7.12 (Anaconda):

>>> import xraylib as xrl
>>> xrl.AtomicNumberToSymbol(26)
'Fe'
>>> import numpy as np
>>> a = np.array([26])
>>> xrl.AtomicNumberToSymbol(a[0])
'Fe'
>>> a = np.array([26], dtype=np.int)
>>> xrl.AtomicNumberToSymbol(a[0])
'Fe'

What versions of xraylib and python are you using, and on which platform are you running it?

@davlars
Copy link
Author

davlars commented Oct 19, 2016

Hmm, what you're running does not work for me. I'm running Python 3.5.2 on a Ubuntu 16.04 LTS system, using xraylib from the conda repo (https://anaconda.org/tacaswell/xraylib). It works fine for:

import xraylib as xrl
xrl.AtomicNumberToSymbol(1)

'H'

However not for:

import xraylib as xrl
a = np.array([1])
xrl.AtomicNumberToSymbol(a)

File "<ipython-input-12-10c1439dda30>", line 1, in <module>
   xrl.AtomicNumberToSymbol(a)
TypeError: in method 'AtomicNumberToSymbol', argument 1 of type 'int'

For that I have to define it as:

import xraylib as xrl
a = np.asscalar(np.array([1]))
xrl.AtomicNumberToSymbol(a)

'H'

Could it be a python2 vs python3 thing? Posted it as an xraylib-issue since I thought it was due to some native-int definition, but it could be my system doing strange stuff...

@davlars davlars closed this as completed Oct 19, 2016
@davlars davlars reopened this Oct 19, 2016
@tschoonj
Copy link
Owner

It's indeed a python3 feature which appears to be related to all integers being 64-bit in python3.

I am looking into it.

@tschoonj
Copy link
Owner

Think I fixed it in #39. From what I understand numpy scalars were actually never supposed to work with the SWIG generated bindings according to the numpy docs.

My latest changes appears to work fine with both built-in Python types as well numpy scalars. Feel free to give it a try,

@davlars
Copy link
Author

davlars commented Oct 19, 2016

Very nice! Thanks for the effort!

@tschoonj
Copy link
Owner

You're welcome, thanks for reporting this issue

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

No branches or pull requests

2 participants