mirror of
https://github.com/huggingface/candle.git
synced 2025-06-18 11:37:11 +00:00
Explicit error when slice-set is called with the same src and dst. (#2733)
This commit is contained in:
@ -248,6 +248,9 @@ impl Tensor {
|
|||||||
if !self.is_contiguous() || !src.is_contiguous() {
|
if !self.is_contiguous() || !src.is_contiguous() {
|
||||||
Err(Error::RequiresContiguous { op: "slice-set" }.bt())?
|
Err(Error::RequiresContiguous { op: "slice-set" }.bt())?
|
||||||
}
|
}
|
||||||
|
if self.same_storage(src) {
|
||||||
|
crate::bail!("cannot use slice_set when self and src share their storage")
|
||||||
|
}
|
||||||
if self.dtype() != src.dtype() {
|
if self.dtype() != src.dtype() {
|
||||||
Err(Error::DTypeMismatchBinaryOp {
|
Err(Error::DTypeMismatchBinaryOp {
|
||||||
lhs: self.dtype(),
|
lhs: self.dtype(),
|
||||||
|
@ -729,6 +729,8 @@ fn slice_set(device: &Device) -> Result<()> {
|
|||||||
.sum_all()?
|
.sum_all()?
|
||||||
.to_vec0::<f32>()?;
|
.to_vec0::<f32>()?;
|
||||||
assert_eq!(diff, 0.);
|
assert_eq!(diff, 0.);
|
||||||
|
// This used to create a deadlock rather than returning an actual error.
|
||||||
|
assert!(cache.slice_set(&cache, 0, 0).is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user