<div dir="ltr"><p style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px;margin-top:0px">Hi all,</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">We are pleased to announce the release of the <a href="https://github.com/QuantStack/xtensor" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code></a> library and its python bindings <a href="https://github.com/QuantStack/xtensor-python" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor-python</code></a>, by Johan Mabille (@JohanMabille) and Sylvain Corlay (@SylvainCorlay).</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-1-xtensor" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#1-xtensor" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>1. <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code></h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><a href="https://github.com/QuantStack/xtensor" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code></a> is a C++ template library for manipulating multi-dimensional array expressions.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">It provides</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box">an API following the idioms of the <b>C++ standard library</b>.</li><li style="box-sizing:border-box;margin-top:0.25em">an extensible expression system enabling <span style="box-sizing:border-box;font-weight:600">lazy broadcasting</span> and <span style="box-sizing:border-box;font-weight:600">universal functions</span>.</li><li style="box-sizing:border-box;margin-top:0.25em"><span style="box-sizing:border-box;font-weight:600">python bindings</span> for operating inplace on <span style="box-sizing:border-box;font-weight:600">numpy</span> arrays in your C++ thanks to Python's buffer protocol and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">pybind</code>.</li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">More details on lazy computing with <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> are available below.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-2-xtensor-cookiecutter" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#2-xtensor-cookiecutter" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>2. <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor-cookiecutter</code></h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Besides, <a href="https://github.com/QuantStack/xtensor" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code></a> and <a href="https://github.com/QuantStack/xtensor-python" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor-python</code></a>, we provide a cookiecutter template project to help extension authors get started. The <a href="https://github.com/QuantStack/xtensor-python" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor-cookiecutter</code></a> generates a simple project for a Python C++ extension with</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box">a working <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">setup.py</code> compiling the extension module</li><li style="box-sizing:border-box;margin-top:0.25em">a few example of functions making use of <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> exposed to python, and the example of a vectorized function exposed to python.</li><li style="box-sizing:border-box;margin-top:0.25em">all the boilerplate for the setup of the unit testing and generation of the HTML documentation for these examples.</li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-3-you-can-try-it-now" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#3-you-can-try-it-now" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>3. You can try it now!</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">You can try the <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> live on the <a href="http://quantstack.net/xtensor" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none">project website</a>. The <span style="box-sizing:border-box;font-weight:600">Try it Now</span> button is powered by</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box">The <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">Cling</code> C++ interpreter.</li><li style="box-sizing:border-box;margin-top:0.25em">The <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">Jupyter</code> notebook.</li><li style="box-sizing:border-box;margin-top:0.25em">The <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">Binder</code> project.</li></ul><hr style="box-sizing:content-box;height:0.25em;overflow:hidden;margin:24px 0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(231,231,231);border:0px;padding:0px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><hr style="box-sizing:content-box;height:0.25em;overflow:hidden;margin:24px 0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(231,231,231);border:0px;padding:0px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-getting-started" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#getting-started" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Getting started</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> requires a modern C++ compiler supporting C++14. The following C+ compilers are supported:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box">On Windows platforms, Visual C++ 2015 Update 2, or more recent</li><li style="box-sizing:border-box;margin-top:0.25em">On Unix platforms, gcc 4.9 or a recent version of Clang</li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-installation" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#installation" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Installation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor-python</code> are header-only libraries. We provide packages for the conda package manager.</p><div class="gmail-highlight gmail-highlight-source-shell" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal">conda install -c conda-forge xtensor         <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"># installs xtensor</span>
conda install -c conda-forge xtensor-python  <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"># installs xtensor and xtensor-python</span></pre></div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-usage" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#usage" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Usage</h2><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-basic-usage" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#basic-usage" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Basic Usage</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">Initialize a 2-D array and compute the sum of one of its rows and a 1-D array.</span></p><div class="gmail-highlight gmail-highlight-source-c++" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box"><</span>iostream<span class="gmail-pl-pds" style="box-sizing:border-box">></span></span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor/xarray.hpp<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor/xio.hpp<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>

xt::xarray<<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span>> arr1
  {{<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">2.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">3.0</span>},
   {<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">2.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">7.0</span>},
   {<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">2.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">7.0</span>}};

xt::xarray<<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span>> arr2
  {<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">6.0</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">7.0</span>};

xt::xarray<<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span>> res = xt::make_xview(arr1, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>) + arr2;

std::cout << res;</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Outputs:</p><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0px;margin:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">{7, 11, 14}
</code></pre><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">Initialize a 1-D array and reshape it inplace.</span></p><div class="gmail-highlight gmail-highlight-source-c++" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box"><</span>iostream<span class="gmail-pl-pds" style="box-sizing:border-box">></span></span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor/xarray.hpp<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor/xio.hpp<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>

xt::xarray<<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">int</span>> arr
  {<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">2</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">3</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">4</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">6</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">7</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">8</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">9</span>};

arr.reshape({<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">3</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">3</span>});

std::cout << arr;</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Outputs:</p><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0px;margin:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">{{1, 2, 3},
 {4, 5, 6},
 {7, 8, 9}}
</code></pre><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-lazy-broadcasting-with-xtensor" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#lazy-broadcasting-with-xtensor" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Lazy Broadcasting with <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code></h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">We can operate on arrays of different shapes of dimensions in an elementwise fashion. Broadcasting rules of xtensor are similar to those of <a href="http://www.numpy.org/" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none">numpy</a> and <a href="http://libdynd.org/" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none">libdynd</a>.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-broadcasting-rules" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#broadcasting-rules" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Broadcasting rules</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">In an operation involving two arrays of different dimensions, the array with the lesser dimensions is broadcast across the leading dimensions of the other.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">For example, if <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">A</code> has shape <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">(2, 3)</code>, and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">B</code> has shape <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">(4, 2, 3)</code>, the result of a broadcasted operation with <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">A</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">B </code>has shape <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">(4, 2, 3)</code>.</p><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0px;margin:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">   (2, 3) # A
(4, 2, 3) # B
---------
(4, 2, 3) # Result
</code></pre><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">The same rule holds for scalars, which are handled as 0-D expressions. If matched up dimensions of two input arrays are different, and one of them has size <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">1</code>, it is broadcast to match the size of the other. Let's say B has the shape <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">(4, 2, 1)</code> in the previous example, so the broadcasting happens as follows:</p><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0px;margin:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">   (2, 3) # A
(4, 2, 1) # B
---------
(4, 2, 3) # Result
</code></pre><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-universal-functions-laziness-and-vectorization" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#universal-functions-laziness-and-vectorization" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Universal functions, Laziness and Vectorization</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">With <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code>, if <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">x</code>, <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">y</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">z</code> are arrays of <em style="box-sizing:border-box">broadcastable shapes</em>, the return type of an expression such as <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">x + y * sin(z)</code> is <span style="box-sizing:border-box;font-weight:600">not an array</span>. It is an <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xexpression</code> object offering the same interface as an N-dimensional array, which does not hold the result. <span style="box-sizing:border-box;font-weight:600">Values are only computed upon access or when the expression is assigned to an xarray object</span>. This allows to operate symbolically on very large arrays and only compute the result for the indices of interest.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">We provide utilities to <span style="box-sizing:border-box;font-weight:600">vectorize any scalar function</span> (taking multiple scalar arguments) into a function that will perform on <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xexpression</code>s, applying the lazy broadcasting rules which we just described. These functions are called <em style="box-sizing:border-box">xfunction</em>s. They are <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code>'s counterpart to numpy's universal functions.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">In <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code>, arithmetic operations (<code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">+</code>, <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">-</code>, <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">*</code>, <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">/</code>) and all special functions are <em style="box-sizing:border-box">xfunction</em>s.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-iterating-over-xexpressions-and-broadcasting-iterators" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#iterating-over-xexpressions-and-broadcasting-iterators" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Iterating over <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xexpression</code>s and Broadcasting Iterators</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">All <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xexpression</code>s offer two sets of functions to retrieve iterator pairs (and their <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">const</code> counterpart).</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">begin()</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">end()</code> provide instances of <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xiterator</code>s which can be used to iterate over all the elements of the expression. The order in which elements are listed is <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">row-major</code> in that the index of last dimension is incremented first.</li><li style="box-sizing:border-box;margin-top:0.25em"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xbegin(shape)</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xend(shape)</code> are similar but take a <em style="box-sizing:border-box">broadcasting shape</em> as an argument. Elements are iterated upon in a row-major way, but certain dimensions are repeated to match the provided shape as per the rules described above. For an expression <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">e</code>, <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">e.xbegin(e.shape())</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">e.begin()</code> are equivalent.</li></ul><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-fixed-dimension-and-dynamic-dimension" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#fixed-dimension-and-dynamic-dimension" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Fixed-dimension <em style="box-sizing:border-box">and</em> Dynamic dimension</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Two container classes implementing multi-dimensional arrays are provided: <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xarray</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code>.</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xarray</code> can be reshaped dynamically to any number of dimensions. It is the container that is the most similar to numpy arrays.</li><li style="box-sizing:border-box;margin-top:0.25em"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> has a dimension set at compilation time, which enables many optimizations. For example, shapes and strides of <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> instances are allocated on the stack instead of the heap.</li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xarray</code> and <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xtensor</code> container are both <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">xexpression</code>s and can be involved and mixed in universal functions, assigned to each other etc...</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Besides, two access operators are provided:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box">The variadic template <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">operator()</code> which can take multiple integral arguments or none.</li><li style="box-sizing:border-box;margin-top:0.25em">And the <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">operator[]</code> which takes a single multi-index argument, which can be of size determined at runtime. <code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px">operator[]</code> also supports access with braced initializers.</li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-python-bindings" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#python-bindings" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Python bindings</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">The python bindings are built upon the <a href="https://github.com/pybind/pybind11" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none">pybind11</a> library, a lightweight header-only for creating bindings between the Python and C++ programming languages.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-example-1-use-an-algorithm-of-the-c-library-on-a-numpy-array-inplace" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#example-1-use-an-algorithm-of-the-c-library-on-a-numpy-array-inplace" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Example 1: Use an algorithm of the C++ library on a numpy array inplace.</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">C++ code</span></p><div class="gmail-highlight gmail-highlight-source-c++" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box"><</span>numeric<span class="gmail-pl-pds" style="box-sizing:border-box">></span></span>                    <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// std::accumulate</span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>pybind11/pybind11.h<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>        <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// pybind11</span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor/xmath.hpp<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>          <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// C++ universal functions</span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor-python/pyarray.hpp<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span> <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// numpy bindings</span>

<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">sum_of_sines</span>(xt::pyarray<<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span>> &m)
{
    <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">auto</span> sines = <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">xt::sin</span>(m); <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// sines does not hold any value</span>
    <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">std::accumulate</span>(sines.<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">begin</span>(), sines.<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">end</span>(), <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">0.0</span>);
}

<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">PYBIND11_PLUGIN</span>(xtensor_python_test)
{
    pybind11::module <span class="gmail-pl-smi" style="box-sizing:border-box">m</span>(<span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor_python_test<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>,
                       <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>Test module for xtensor python bindings<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>);

    m.<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">def</span>(<span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>sum_of_sines<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>,
          sum_of_sines,
          <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>Return the sum of the sines<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>);

    <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> m.<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">ptr</span>();
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">Python Code</span></p><div class="gmail-highlight gmail-highlight-source-python" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">import</span> numpy <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">as</span> np
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">import</span> xtensor_python_test <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">as</span> xt

a <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> np.arange(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">15</span>).reshape(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">3</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5</span>)
s <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> xt.sum_of_sines(v)
s</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">Outputs</span></p><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0px;margin:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">1.2853996391883833
</code></pre><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="gmail-user-content-example-2-create-a-universal-function-from-a-c-scalar-function" class="gmail-anchor" href="https://gist.github.com/SylvainCorlay/acbb515a5f421897b9254bcb2a65b2b8#example-2-create-a-universal-function-from-a-c-scalar-function" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Example 2: Create a universal function from a C++ scalar function</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">C++ code</span></p><div class="gmail-highlight gmail-highlight-source-c++" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal">#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>pybind11/pybind11.h<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor-python/pyvectorize.hpp<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box"><</span>numeric<span class="gmail-pl-pds" style="box-sizing:border-box">></span></span>
#<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">include</span> <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box"><</span>cmath<span class="gmail-pl-pds" style="box-sizing:border-box">></span></span>

<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">namespace</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">py</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> pybind11;

<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">scalar_func</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span> i, <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">double</span> j)
{
    <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">std::sin</span>(i) - <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">std::cos</span>(j);
}

<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">PYBIND11_PLUGIN</span>(xtensor_python_test)
{
    py::module <span class="gmail-pl-smi" style="box-sizing:border-box">m</span>(<span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>xtensor_python_test<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>,
                 <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>Test module for xtensor python bindings<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>);

    m.<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">def</span>(<span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span>vectorized_func<span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">xt::pyvectorize</span>(scalar_func), <span class="gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="gmail-pl-pds" style="box-sizing:border-box">"</span><span class="gmail-pl-pds" style="box-sizing:border-box">"</span></span>);

    <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> m.<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">ptr</span>();
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">Python Code</span></p><div class="gmail-highlight gmail-highlight-source-python" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">import</span> numpy <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">as</span> np
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">import</span> xtensor_python_test <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">as</span> xt

x <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> np.arange(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">15</span>).reshape(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">3</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">5</span>)
y <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> [<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">2</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">3</span>]
z <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> xt.vectorized_func(x, y)
z</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><span style="box-sizing:border-box;font-weight:600">Outputs</span></p><pre style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51);margin-bottom:0px"><code style="box-sizing:border-box;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0px;margin:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">[[-1.     ,  0.30116,  1.32544,  1.13111, -0.10315],
 [-1.95892, -0.81971,  1.07313,  1.97935,  1.06576],
 [-1.54402, -1.54029, -0.12042,  1.41016,  1.64425]]</code></pre></div>