mirror of
https://github.com/huggingface/candle.git
synced 2025-06-18 19:47:12 +00:00
Iteration over strided blocks (#175)
* Introduce the strided blocks. * Use the strided blocks to fasten the copy. * Add more testing.
This commit is contained in:
@ -834,10 +834,20 @@ impl Tensor {
|
||||
Ok(from_storage(storage, shape, op, false))
|
||||
}
|
||||
|
||||
pub(crate) fn strided_index(&self) -> crate::StridedIndex {
|
||||
/// Returns an iterator over position of the elements in the storage when ranging over the
|
||||
/// index tuples in lexicographic order.
|
||||
pub fn strided_index(&self) -> crate::StridedIndex {
|
||||
self.layout.strided_index()
|
||||
}
|
||||
|
||||
/// Similar to `strided_index` but returns the position of the start of each contiguous block
|
||||
/// as well as the length of the contiguous blocks. For a contiguous tensor, the index iterator
|
||||
/// will only return the start offset and the size would be the number of elements in the
|
||||
/// tensor.
|
||||
pub fn strided_blocks(&self) -> crate::StridedBlocks {
|
||||
self.layout.strided_blocks()
|
||||
}
|
||||
|
||||
/// Returns the data contained in a 1D tensor as a vector of scalar values.
|
||||
pub fn to_vec1<S: crate::WithDType>(&self) -> Result<Vec<S>> {
|
||||
if self.rank() != 1 {
|
||||
|
Reference in New Issue
Block a user