Program Listing for File tensors.hpp

Return to documentation for file (src/navtk/tensors.hpp)

#pragma once

#include <initializer_list>
#include <string>
#include <utility>


#ifndef NAVTK_SCALAR
#   define NAVTK_SCALAR double
#endif
namespace navtk {
typedef NAVTK_SCALAR Scalar;
}  // namespace navtk

#ifdef NAVTK_PYTHON_TENSOR
#   include <xtensor-python/pytensor.hpp>
namespace navtk {
template <std::size_t Dims, typename T = Scalar>
using Tensor = xt::pytensor<T, Dims>;
// xtensor-python doesn't have a `_fixed` equivalent
template <int R, int C, typename T = Scalar>
using MatrixN = xt::pytensor<T, 2>;
template <int N, typename T = Scalar>
using VectorN = xt::pytensor<T, 1>;
}  // namespace navtk
#else
#   include <xtensor/containers/xfixed.hpp>
#   include <xtensor/containers/xtensor.hpp>
namespace navtk {
template <std::size_t Dims, typename T = Scalar>
using Tensor = xt::xtensor<T, Dims>;
template <int R, int C, typename T = Scalar>
using MatrixN = xt::xtensor_fixed<T, xt::xshape<R, C> >;
template <int N, typename T = Scalar>
using VectorN = xt::xtensor_fixed<T, xt::xshape<N> >;
}  // namespace navtk
#endif

#include <xtensor/views/xview.hpp>

namespace navtk {

typedef Tensor<2> Matrix;
template <typename T>
using MatrixT = Tensor<2, T>;
typedef Tensor<1> Vector;
typedef MatrixN<3, 3> Matrix3;
typedef VectorN<3> Vector3;
typedef VectorN<4> Vector4;

template <typename T>
using VectorT = Tensor<1, T>;

using namespace xt::placeholders;  // required for `_` to work
using Size = Matrix::size_type;

}  // namespace navtk