EinsumsPy/Tensor/PyTensor.hpp#
Defined in header EinsumsPy/Tensor/PyTensor.hpp.
See Overview for a list of names and headers that are part of the public Einsums API.
Defines
-
COPY_CAST_OP(OP, NAME)#
-
OPERATOR(OP, NAME, OPNAME)#
-
COPY_CAST_OP(OP, NAME)
-
OPERATOR(OP, NAME, OPNAME)
-
OPERATOR(OP, TYPE)
-
namespace einsums
-
namespace python
Typedefs
Shared pointer to a RuntimeTensor.
Shared pointer to a RuntimeTensorView.
Functions
-
template<typename T>
void export_tensor(pybind11::module &mod)# Expose runtime tensors to Python.
- Template Parameters:
T – The stored type of the tensors to export.
- Parameters:
mod – The module which will contain the definitions.
-
void export_tensor_typeless(pybind11::module_ &mod)#
Exposes extra symbols to Python that are not typed.
- Parameters:
mod – The module to export to.
-
template<typename T>
class PyTensor : public RuntimeTensor<T># - #include <PyTensor.hpp>
A Python wrapper for RuntimeTensor.
- Template Parameters:
The – type stored by the tensor.
Public Functions
Copy constructor from shared pointer.
-
inline PyTensor(pybind11::buffer const &buffer)#
Create a tensor from a Python buffer object.
-
virtual ~PyTensor() = default#
-
inline void zero() override#
Clear the tensor.
-
inline void set_all(T val) override#
Set the tensor to the given values.
- Parameters:
val – The value to set the tensor to.
-
inline pybind11::object subscript(pybind11::tuple const &args)#
Subscript into the tensor. Can contain slices.
- Parameters:
args – The indices to use to subscript.
- Returns:
A Python object containing a reference to a single value or a RuntimeTensorView.
-
inline pybind11::object assign_values(pybind11::buffer const &value, pybind11::tuple const &index)#
Copy multiple values into a section of the tensor.
- Parameters:
value – The values to copy.
index – The indices to use to subscript.
- Returns:
A Python object containing a reference to a single value or a RuntimeTensorView.
-
inline pybind11::object assign_values(T value, pybind11::tuple const &index)#
Copy a single value over a section of the tensor.
- Parameters:
value – The value to copy.
index – The indices to use to subscript.
- Returns:
A Python object containing a reference to a single value or a RuntimeTensorView.
-
inline RuntimeTensorView<T> subscript(pybind11::slice const &arg)#
Subscript into the tensor using a single slice.
- Parameters:
arg – The slice to use for the tensor.
- Returns:
The view containing the slice.
-
inline RuntimeTensorView<T> assign_values(pybind11::buffer const &value, pybind11::slice const &index)#
Assign multiple values from a buffer into a slice of the tensor.
- Parameters:
value – The values to copy.
index – The slice to use for the tensor.
- Returns:
The view containing the slice.
-
inline RuntimeTensorView<T> assign_values(T value, pybind11::slice const &index)#
Assign a single value over a slice of the tensor.
- Parameters:
value – The value to copy.
index – The slice to use for the tensor.
- Returns:
The view containing the slice.
-
inline pybind11::object subscript(ptrdiff_t index)#
Get the value at a certain index.
- Parameters:
index – The index to use.
- Returns:
A Python object containing either a single value if the tensor is rank-1 or a RuntimeTensorView otherwise.
-
inline RuntimeTensorView<T> assign_values(pybind11::buffer const &value, ptrdiff_t index)#
Copy values into a view of the tensor whose first index is set.
- Parameters:
value – The buffer to copy.
index – The index to use.
- Returns:
The view containing the the modified indices.
-
inline pybind11::object assign_values(T value, ptrdiff_t index)#
Copy a value over a section of a tensor.
- Parameters:
value – The value to copy.
index – The index to use.
- Returns:
A Python object containing either a single value if the tensor is rank-1 or a RuntimeTensorView otherwise.
-
inline RuntimeTensor<T> &operator=(pybind11::buffer const &buffer)#
Assign a buffer to this tensor, reshaping if necessary.
- Parameters:
buffer – The buffer to assign.
- Returns:
A reference to this.
-
inline size_t dim(int d) const override#
Get the length of the tensor along a given direction.
- Parameters:
d – The dimension to query.
-
inline RuntimeTensor<T>::Vector const &vector_data() const noexcept override#
Get the vector holding the tensor’s data.
-
inline RuntimeTensor<T>::Vector &vector_data() noexcept override#
Get the vector holding the tensor’s data.
-
inline size_t stride(int d) const override#
Get the stride of the tensor along a given axis.
- Parameters:
d – The axis to query.
-
inline RuntimeTensorView<T> to_rank_1_view() const override#
Create a rank-1 view of the tensor.
-
inline bool full_view_of_underlying() const noexcept override#
Check whether the tensor can see all of the data it stores.
This function should return true for this kind of tensor.
-
inline void set_name(std::string const &new_name) override#
Set the tensor’s name.
- Parameters:
new_name – The new name for the tensor.
-
inline size_t rank() const noexcept override#
Get the rank of the tensor.
Private Functions
-
inline T &subscript_to_val(pybind11::tuple const &args)#
Subscript the tensor to get a value.
- Parameters:
args – The index of the value.
-
inline T const &subscript_to_val(pybind11::tuple const &args) const#
Subscript the tensor to get a value.
- Parameters:
args – The index of the value.
-
inline RuntimeTensorView<T> subscript_to_view(pybind11::tuple const &args)#
Subscript the tensor to get a view.
- Parameters:
args – The index of the view. Can contain slices.
-
inline RuntimeTensorView<T> subscript_to_view(pybind11::tuple const &args) const#
Subscript the tensor to get a view.
- Parameters:
args – The index of the view. Can contain slices.
-
inline void set_value_at(T value, std::vector<ptrdiff_t> const &index)#
Set the value of a certain position.
- Parameters:
value – The value to set.
index – The index of the position.
-
inline void assign_to_view(pybind11::buffer const &view, pybind11::tuple const &args)#
Copy multiple values to multiple positions.
- Parameters:
view – The values to copy.
args – The indices to copy to. Can contain slices.
-
template<typename T>
class PyTensorIterator# - #include <PyTensor.hpp>
Walks through the elements of a tensor.
- Template Parameters:
T – The type stored in the tensor.
Public Functions
-
inline PyTensorIterator(PyTensorIterator const ©, bool reverse = false)#
Copy constructor with optional direction modification.
- Parameters:
copy – The iterator to copy.
reverse – Whether the new iterator is the reverse of the other iterator.
-
inline PyTensorIterator(RuntimeTensor<T> const &other, bool reverse = false)#
Create an iterator around a tensor. Can be reversed.
- Parameters:
other – The tensor to walk through.
reverse – Whether to go forward or backward.
-
inline PyTensorIterator(RuntimeTensorView<T> const &other, bool reverse = false)#
Create an iterator around a tensor view. Can be reversed.
- Parameters:
other – The tensor view to walk through.
reverse – Whether to go forward or backward.
-
inline bool reversed() const noexcept#
Returns whether the iterator is stepping forward or backward.
Private Members
-
mutable std::mutex _lock#
Enhances thread safety so that multiple threads can iterate over a tensor all at once.
-
size_t _curr_index#
Holds where the iterator is currently pointing.
-
size_t _elements#
Holds the number of elements this iterator will need to cycle through.
-
std::vector<size_t> _index_strides#
Holds information to be able to turn _curr_index into a list of indices that can be passed to the underlying tensor.
-
RuntimeTensorView<T> _tensor#
The tensor this iterator will iterate over.
-
bool _stop = {false}#
Whether the iterator is finished or should keep going.
-
bool _reverse = {false}#
Indicates whether the iterator is a forward iterator or a reverse iterator.
-
template<typename T>
class PyTensorView : public RuntimeTensorView<T># - #include <PyTensor.hpp>
Views a runtime tensor and makes it available to Python.
See also
PyTensor for information on methods.
Public Functions
-
PyTensorView(PyTensorView<T> const&) = default#
Default copy constructor.
This creates a new view that points to the same tensor as the input.
-
inline PyTensorView(RuntimeTensorView<T> const ©)#
Create a view of the given tensor.
- Parameters:
copy – The tensor to view.
-
inline PyTensorView(pybind11::buffer &buffer)#
Create a view of the given buffer.
- Parameters:
buffer – The buffer to view.
-
virtual ~PyTensorView() = default#
-
inline void zero() override#
Set all values in the view to zero.
-
inline void set_all(T val) override#
Fill the view with the given value.
- Parameters:
val – The value to fill the tensor with.
-
inline pybind11::object subscript(pybind11::tuple const &args)#
Subscript into the tensor.
This method handles view creation when necessary.
- Parameters:
args – The indices and slices to use for the view creation.
-
inline pybind11::object assign_values(pybind11::buffer const &value, pybind11::tuple const &index)#
Assign a buffer to part of the view.
- Parameters:
value – The buffer to assign from.
index – The indices and slices determining where to assign to.
-
inline pybind11::object assign_values(T value, pybind11::tuple const &index)#
Fill part of the view with a value.
- Parameters:
value – The value to fill the view with
index – The indices and slices determining where to assign to.
-
inline RuntimeTensorView<T> subscript(pybind11::slice const &arg)#
Subscript into the tensor using a slice.
- Parameters:
arg – The slice to use to subscript.
-
inline RuntimeTensorView<T> assign_values(pybind11::buffer const &value, pybind11::slice const &index)#
Assign a buffer to part of the view.
- Parameters:
value – The buffer to assign from.
index – The slice determining where to assign to.
-
inline RuntimeTensorView<T> assign_values(T value, pybind11::slice const &index)#
Fill part of the view with a value.
- Parameters:
value – The value to fill the view with
index – The slice determining where to assign to.
-
inline pybind11::object subscript(ptrdiff_t index)#
Subscript into the tensor using a single value.
Creates a view if the rank is greater than 1.
- Parameters:
index – The index for the tensor.
-
inline RuntimeTensorView<T> assign_values(pybind11::buffer const &value, ptrdiff_t index)#
Assign a buffer to the position specified by the index.
- Parameters:
value – The buffer to assign from.
index – The index to use to determine the view to assign to.
-
inline pybind11::object assign_values(T value, ptrdiff_t index)#
Fill part of the view with a value.
- Parameters:
value – The value to fill the view.
index – The index to use to determine the view to assign to.
-
inline PyTensorView<T> &operator=(pybind11::buffer const &buffer)#
Copy the data from a buffer into the view.
- Parameters:
buffer – The buffer to copy.
-
inline size_t dim(int d) const override#
Get the dimension along a given axis.
- Parameters:
d – The axis to query.
-
inline size_t stride(int d) const override#
Get the stride along a given axis.
- Parameters:
d – The axis to query.
-
inline bool full_view_of_underlying() const noexcept override#
Check whether the view sees all of the data of the tensor it views.
-
inline void set_name(std::string const &new_name) override#
Set the name of the tensor.
- Parameters:
new_name – The new name for the tensor.
-
inline size_t rank() const noexcept override#
Gets the rank of the tensor view.
Private Functions
-
inline T &subscript_to_val(pybind11::tuple const &args)#
Worker method that subscripts into the view and returns a reference to the requested element.
- Parameters:
args – The indices to use for the subscript.
-
inline T const &subscript_to_val(pybind11::tuple const &args) const#
Worker method that subscripts into the view and returns a reference to the requested element.
- Parameters:
args – The indices to use for the subscript.
-
inline RuntimeTensorView<T> subscript_to_view(pybind11::tuple const &args)#
Worker method that creates a view based on the indices and slices passed in.
- Parameters:
args – The indices and slices to use for view creation.
-
inline RuntimeTensorView<T> subscript_to_view(pybind11::tuple const &args) const#
Worker method that creates a view based on the indices and slices passed in.
- Parameters:
args – The indices and slices to use for view creation.
-
inline void set_value_at(T value, std::vector<size_t> const &index)#
Set the value at the given point in the tensor to the given value.
- Parameters:
value – The new value.
index – Where to set the value.
-
inline void assign_to_view(pybind11::buffer const &view, pybind11::tuple const &args)#
Copy the data from a buffer into this view.
Creates a view of part of the tensor using the subscript arguments, then assigns the buffer to that view.
- Parameters:
view – The buffer to copy.
args – The position to copy to.
-
PyTensorView(PyTensorView<T> const&) = default#
-
namespace python