10

It doesn't appear to be 'bitness' (32 vs. 64) of the processor, see comments on this post, in particular:

Good answer. As I mentioned in my comments above, I'm able to duplicate @suzep136's issue on a Raspberry Pi 3, which uses a 64-bit ARM processor. Any idea why the overflow issue would occur on a 64-bit architecture? The only thing I can think of is that lapack/blas were compiled for a 32-bit core; I think I installed numpy through apt-get. – nrlakin

Nor is it the size of int in C, for example on my machine:

>>> import numpy, ctypes
>>> 
>>> ctypes.sizeof(ctypes.c_int)
4
>>> numpy.array([1]).dtype
dtype('int64')

So, what does it depend on?

Edit: There goes another candidate, thanks ev-br:

LAPACK uses 32-bit integers on all architectures – ev-br

Edit: A partial answer is here. Thanks Goyo. I've copied this and made it CW so you can add the finer points such as what happens in PyPy or Jython. I'd also be interested in whether there are any deeper reasons for this choice.

Community
  • 1
  • 1
Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
  • You can check the datatype that `int` corresponds to using `numpy.dtype(int)`. – Eli Sadoff Jan 21 '17 at 18:21
  • @EliSadoff thanks, but that only gives me the what, not the why. – Paul Panzer Jan 21 '17 at 19:04
  • LAPACK uses 32-bit integers on all architectures – ev-br Jan 21 '17 at 19:13
  • @ev-br interesting. Perhaps you could copy your comment to the linked post, so nrlakin will see it? – Paul Panzer Jan 21 '17 at 19:18
  • 3
    Possible duplicate of [numpy array dtype is coming as int32 by default in a windows 10 64 bit machine](http://stackoverflow.com/questions/36278590/numpy-array-dtype-is-coming-as-int32-by-default-in-a-windows-10-64-bit-machine) – Stop harming Monica Jan 21 '17 at 19:52
  • @Goyo Oops! Thanks, the answer to the question you link does indeed answer my question. However, I would argue that having the same answer doesn't necnessarily mean it's the same question. As a matter of fact, I was looking for an answer and did not find the other question. Therefore I'd say my question is still useful. So what should I do? Please advise. – Paul Panzer Jan 21 '17 at 20:49
  • @PaulPanzer You made a good point. I remember some questions about cases like this in Meta but I don't feel like searching at this moment (it's past 2:00 PM here and I have had some beers in the last hours and I've been awaken for 20 hours). So I will just retract my close vote because I can't really make my mind up. – Stop harming Monica Jan 22 '17 at 01:11
  • @PaulPanzer you could add an answer yourself and CW it if you feel so inclined I think. – miradulo Jan 22 '17 at 01:20
  • @Mitch CW, CW? Ah, ok, [CW](http://meta.stackexchange.com/questions/40353/stack-exchange-glossary-dictionary-of-commonly-used-terms) -- all that jargon so early in the morning... Anyway, thank you for your guidance; but could you clarify? I mean, the answer is straightforward, really, no need for broad discussion. Also, it is Goyo (argh! what's this only-one-user-can-be-notified rule for?) who found it and made the link, so shouldn't the credit be theirs to take or waive if they feel that's more appropriate? Doing it myself would feel a bit "high-handed" given how new to SO I still am. – Paul Panzer Jan 22 '17 at 10:22
  • @Goyo Btw. I think I'd be ok with also having the Q CW'ed. Or is that very bad? (I couldn't help noticing having their posts CW'ed tends to upset people) – Paul Panzer Jan 22 '17 at 10:40
  • @PaulPanzer I'd be glad to waive any credit I could deserve. Whatever you or anybody does I will be fine with it. If you are unsure but you still feel that you should do something I suggest you to search or ask in [meta](http://meta.stackoverflow.com/) (more jargon). – Stop harming Monica Jan 22 '17 at 21:37
  • @Mitch ok, I did as you suggested, since I had second thoughts about the answer being totally straightforward. Thanks again for your help. – Paul Panzer Jan 23 '17 at 04:10

2 Answers2

2

Thanks to Goyo who is too modest to take the credit. See their answer to a related but different question.

The default integer type in numpy is numpy.int_, be sure to notice the trailing underline. It defaults to C long 1.

Community
  • 1
  • 1
Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
0

Ok, so I may be misunderstanding your question but if you take a look at the Numpy Documentation my guess would be that numpy assigns bit values based on what the max bit size could go up or down to given the system architecture. Basically, because you did not specify that the integer "container" only need be 8 or 16 bits in length it defaulted to the largest container possible on a 64 bit machine.

If you want to find the number of bits python has a builtin "bit_length()" function. Check it out here: https://docs.python.org/3.6/library/stdtypes.html#int.bit_length

Hope this answers your question.

Community
  • 1
  • 1
Dan Temkin
  • 1,565
  • 1
  • 14
  • 18
  • 1
    No, that is precisely not what happens. In a sense the whole point of the question is that what you and I and others naively assume is not correct. – Paul Panzer Jan 23 '17 at 11:27