<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Numpy on Shai Asher</title><link>https://slow-is-smooth.io/tags/numpy/</link><description>Recent content in Numpy on Shai Asher</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Sun, 20 Oct 2019 09:00:00 +0300</lastBuildDate><atom:link href="https://slow-is-smooth.io/tags/numpy/index.xml" rel="self" type="application/rss+xml"/><item><title>Sharing Memory with C</title><link>https://slow-is-smooth.io/blog/sharing-memory-with-c/</link><pubDate>Sun, 20 Oct 2019 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/sharing-memory-with-c/</guid><description>&lt;p&gt;Python 3.8, released last week, adds a pickle protocol that can serialise a 100 MB NumPy array into&#10;122 bytes. The other 100,000,000 bytes aren&amp;rsquo;t copied into the pickle at all. They&amp;rsquo;re handed to the&#10;caller as a buffer, the array&amp;rsquo;s own memory, to send however it likes. That works because of an&#10;interface that has been in Python 3 from the start and that most Python programmers never see: the&#10;buffer protocol, through which one object lends the raw memory behind it to another, with no copy, as&#10;long as the lender agrees to keep it still.&lt;/p&gt;</description></item><item><title>Numbers Are C Numbers Until They Aren't</title><link>https://slow-is-smooth.io/blog/numbers-are-c-numbers-until-they-arent/</link><pubDate>Sun, 16 Jun 2019 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/numbers-are-c-numbers-until-they-arent/</guid><description>&lt;p&gt;In Python, &lt;code&gt;2**62 * 4&lt;/code&gt; is 18446744073709551616. In a NumPy array of 64-bit integers it is 0, and&#10;NumPy 1.16 doesn&amp;rsquo;t say a word. Multiply the same value as a single NumPy scalar and you get a&#10;warning and the same 0. Python&amp;rsquo;s integers have no fixed size, but almost every library that makes&#10;Python fast stores numbers as C integers and C doubles, and at that boundary Python&amp;rsquo;s arithmetic&#10;quietly becomes C&amp;rsquo;s. CPython itself sits on both sides: its integers are arbitrary-precision, and its&#10;fastest paths are the ones that can do the work in a C &lt;code&gt;long&lt;/code&gt; or &lt;code&gt;double&lt;/code&gt; and never build a Python&#10;object at all.&lt;/p&gt;</description></item></channel></rss>