.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Missing values
==============
*xtensor* handles missing values and provides specialized container types for an optimized support of missing values.
Optional expressions
--------------------
Support of missing values in xtensor is primarily provided through the :cpp:type:`xtl::xoptional`
value type and the :cpp:type:`xt::xtensor_optional` and :cpp:type:`xt::xarray_optional` containers.
In the following example, we instantiate a 2-D tensor with a missing value:
.. code:: cpp
xt::xtensor_optional m
{{ 1.0 , 2.0 },
{ 3.0 , missing() }};
This code is semantically equivalent to
.. code:: cpp
xt::xtensor m
{{ 1.0 , 2.0 },
{ 3.0 , missing() }};
The :cpp:type:`xt::xtensor_optional` container is optimized to handle missing values.
Internally, instead of holding a single container of optional values, it holds an array of ``double``
and a boolean container where each value occupies a single bit instead of ``sizeof(bool)`` bytes.
The :cpp:type:`xt::xtensor_optional::reference` typedef, which is the return type of
:cpp:func:`~xt::xexpression::operator()` is a reference proxy which can be used as an
lvalue for assigning new values in the array.
It happens to be an instance of :cpp:type:`xtl::xoptional\ ` where ``T`` and
``B`` are actually the reference types of the underlying storage for values and boolean flags.
This technique enables performance improvements in mathematical operations over boolean arrays including SIMD optimizations, and
reduces the memory footprint of optional arrays. It should be transparent to the user.
Operating on missing values
---------------------------
Arithmetic operators and mathematical universal functions are overloaded for optional values so that they can be operated upon in the
same way as regular scalars.
.. code:: cpp
xt::xtensor_optional a
{{ 1.0 , 2.0 },
{ 3.0 , missing() }};
xt::xtensor b
{ 1.0, 2.0 };
// ``b`` is broadcasted to match the shape of ``a``
std::cout