Class PackedSequence#
Defined in File rnn.h
Page Contents
Class Documentation#
-
class PackedSequence#
Holds the data and list of
batch_sizesof a packed sequence.All RNN modules accept packed sequences as inputs.
Note: Instances of this class should never be created manually. They are meant to be instantiated by functions like
pack_padded_sequence.Batch sizes represent the number elements at each sequence step in the batch, not the varying sequence lengths passed to
pack_padded_sequence. For instance, given dataabcandxthe :class:PackedSequencewould contain dataaxbcwithbatch_sizes=[2,1,1].Attributes: data (Tensor): Tensor containing packed sequence batch_sizes (Tensor): Tensor of integers holding information about the batch size at each sequence step sorted_indices (Tensor, optional): Tensor of integers holding how this :class:
PackedSequenceis constructed from sequences. unsorted_indices (Tensor, optional): Tensor of integers holding how this to recover the original sequences with correct order... note::
datacan be on arbitrary device and of arbitrary dtype.sorted_indicesandunsorted_indicesmust betorch::kInt64tensors on the same device asdata.However,
batch_sizesshould always be a CPUtorch::kInt64tensor.This invariant is maintained throughout
PackedSequenceclass, and all functions that construct aPackedSequencein libtorch (i.e., they only pass in tensors conforming to this constraint).Public Functions
-
inline explicit PackedSequence(Tensor data, Tensor batch_sizes, Tensor sorted_indices = {}, Tensor unsorted_indices = {})#
-
inline const Tensor &data() const#
-
inline const Tensor &batch_sizes() const#
-
inline const Tensor &sorted_indices() const#
-
inline const Tensor &unsorted_indices() const#
-
inline PackedSequence pin_memory() const#
-
inline PackedSequence to(TensorOptions options) const#
-
inline PackedSequence cuda() const#
-
inline PackedSequence cpu() const#
-
inline bool is_cuda() const#
Returns true if
data_stored on a gpu.
-
inline bool is_pinned() const#
Returns true if
data_stored on in pinned memory.
-
inline explicit PackedSequence(Tensor data, Tensor batch_sizes, Tensor sorted_indices = {}, Tensor unsorted_indices = {})#