
PyTorch – Internal Architecture Tour - perone
http://blog.christianperone.com/2018/03/pytorch-internal-architecture-tour/
======
adamnemecek
“For that reason, the statement a = 200; b = 200; a is b will be True, while
the statement a = 300; b = 300; a is b will be False.”

This is kinda funny.

~~~
pedrosorio
Same thing happens in Java - Integer objects are the same between -128 and
127.

~~~
detaro
Another common trick along those lines is _pointer tagging_ , where you use
some of the bits in a pointer/reference to store flags and if those are set,
put data in there directly.

E.g. you could on a 32-bit machine reserve the least significant bit to mark
an integer, and if it is set the high 31 bits are treated as a 31-bit integer
instead of a pointer. Since your objects are likely bigger than a byte, you
don't actually need all 32 bits for addresses and thus don't even loose
addressable memory space. On 64bit machines you can do it even more, since
they are far from being able to use all bits for actual memory, and you might
even fit a short string or other more complex type in there.

~~~
saagarjha
Here's an interesting case study by Mike Ash on how the Objective-C runtime
does tagged pointers for strings: [https://mikeash.com/pyblog/friday-
qa-2015-07-31-tagged-point...](https://mikeash.com/pyblog/friday-
qa-2015-07-31-tagged-pointer-strings.html)

------
kbumsik
Great. I am wondering which tools he used to draw object diagrams. It looks
neat.

~~~
perone
I used Sketch ([https://www.sketchapp.com/](https://www.sketchapp.com/)), the
graphs of the objects are actually from a built-in template for iOS
notifications lol, but it worked well for that purpose.

~~~
danieldk
Awesome. Off-topic: this reminds me of Stardock's Galactic Civilizations:

 _I bought a book “Teach Yourself C in 21 days” and “OS /2 2.0 PM programming”
Because I couldn’t afford anything more, everything in the game I created,
Galactic Civilizations, could be found in those 2 books. [...] Let me give you
an example – in GalCiv on OS/2, each star ship is actually a full blown window
that is of style SS_ICON. So when you move a ship in the game, I’m just using
WinSetWindowPos to move the ship X,Y coordinates. There’s no “graphics” in the
game per se, just all icons being moved around. That’s because I couldn’t
afford any more books than those two and they didn’t cover graphics
programming, just icons and window movement._

Source:
[https://www.stardock.com/stardock/articles/article_sdos2.htm...](https://www.stardock.com/stardock/articles/article_sdos2.html)

By the way, OmniGraffle is also great for drawing graphs on the Mac.

~~~
perone
haha nice, in the end, we squeeze what we know. Didn't know about OmniGraffle,
will take a look.

------
saagarjha
> auto array = (PyArrayObject* )obj;

Why not reinterpret_cast<PyArrayObject * > here?

(extra spaces are so Hacker News doesn't make this italics)

