Explicit error when slice-set is called with the same src and dst. (#2733)

This commit is contained in:
Laurent Mazare
2025-01-22 21:31:49 +01:00
committed by GitHub
parent 85f0aaefe5
commit 77db8396d0
2 changed files with 5 additions and 0 deletions

View File

@ -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(),

View File

@ -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(())
} }