14#include <lagrange/Logger.h>
15#include <lagrange/utils/span.h>
17#include <lagrange/Attribute.h>
18#include <lagrange/IndexedAttribute.h>
19#include <lagrange/python/binding.h>
20#include <lagrange/utils/SmallVector.h>
25namespace lagrange::python {
26namespace nb = nanobind;
27using namespace nb::literals;
29template <
typename ValueType>
30using Tensor = nb::ndarray<ValueType, nb::numpy, nb::c_contig, nb::device::cpu>;
31using GenericTensor = nb::ndarray<nb::c_contig, nb::numpy, nb::device::cpu>;
32using Shape = SmallVector<size_t, 2>;
33using Stride = SmallVector<int64_t, 2>;
42bool is_vector(
const Shape& shape);
52bool check_shape(
const Shape& shape,
size_t expected_size);
66bool check_shape(
const Shape& shape,
size_t expected_rows,
size_t expected_cols);
77bool is_dense(
const Shape& shape,
const Stride& stride);
85template <
typename ValueType>
86Tensor<ValueType> create_empty_tensor();
88template <
typename ValueType>
89std::tuple<span<ValueType>, Shape, Stride> tensor_to_span(Tensor<ValueType> tensor);
91template <
typename ValueType>
92Tensor<std::decay_t<ValueType>> span_to_tensor(
span<ValueType> values, nb::handle base);
94template <
typename ValueType>
95Tensor<std::decay_t<ValueType>>
98template <
typename ValueType>
99Tensor<std::decay_t<ValueType>> span_to_tensor(
105template <
typename ValueType>
106Tensor<std::decay_t<ValueType>> attribute_to_tensor(
107 const Attribute<ValueType>& attr,
110template <
typename ValueType>
111Tensor<std::decay_t<ValueType>>
112attribute_to_tensor(
const Attribute<ValueType>& attr,
span<const size_t> shape, nb::handle base);
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27