Skip to content

Commit

Permalink
Explicit error when slice-set is called with the same src and dst.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMazare committed Jan 22, 2025
1 parent 85f0aae commit 5baaa88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions candle-core/src/tensor_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ impl Tensor {
if !self.is_contiguous() || !src.is_contiguous() {
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() {
Err(Error::DTypeMismatchBinaryOp {
lhs: self.dtype(),
Expand Down
2 changes: 2 additions & 0 deletions candle-core/tests/tensor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ fn slice_set(device: &Device) -> Result<()> {
.sum_all()?
.to_vec0::<f32>()?;
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(())
}

Expand Down

0 comments on commit 5baaa88

Please sign in to comment.