mirror of
https://github.com/huggingface/candle.git
synced 2025-06-18 03:28:50 +00:00
Adding size checking when creating a tensor from buffer + shape.
This commit is contained in:
@ -151,7 +151,11 @@ impl Tensor {
|
||||
device: &Device,
|
||||
is_variable: bool,
|
||||
) -> Result<Self> {
|
||||
// let shape = array.shape()?;
|
||||
let n: usize = shape.0.iter().product();
|
||||
let buffer_size: usize = array.shape()?.0.iter().product();
|
||||
if buffer_size != n {
|
||||
return Err(Error::ShapeMismatch { buffer_size, shape });
|
||||
}
|
||||
let storage = device.storage(array)?;
|
||||
let stride = shape.stride_contiguous();
|
||||
let tensor_ = Tensor_ {
|
||||
|
Reference in New Issue
Block a user