summaryrefslogtreecommitdiff
path: root/candle-core/src/variable.rs
diff options
context:
space:
mode:
authorLaurent Mazare <laurent.mazare@gmail.com>2023-07-14 09:31:25 +0100
committerGitHub <noreply@github.com>2023-07-14 09:31:25 +0100
commitd88b6cdca938aa820641ffd08ee4de2104002569 (patch)
tree4cb4397d54aea82a881c7aeb8b14062af65e07d5 /candle-core/src/variable.rs
parenta2f72edc0de31709f9489922f93bb52b50035ebd (diff)
downloadcandle-d88b6cdca938aa820641ffd08ee4de2104002569.tar.gz
candle-d88b6cdca938aa820641ffd08ee4de2104002569.tar.bz2
candle-d88b6cdca938aa820641ffd08ee4de2104002569.zip
Add backtrace information to errors where relevant. (#166)
* Add backtrace information to errors where relevant. * More backtrace information. * Add to the FAQ.
Diffstat (limited to 'candle-core/src/variable.rs')
-rw-r--r--candle-core/src/variable.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/candle-core/src/variable.rs b/candle-core/src/variable.rs
index 0ae16c64..e26f1420 100644
--- a/candle-core/src/variable.rs
+++ b/candle-core/src/variable.rs
@@ -9,6 +9,12 @@ use crate::{DType, Device, Error, Result, Shape, Tensor};
#[derive(Clone, Debug)]
pub struct Var(Tensor);
+impl std::fmt::Display for Var {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ std::fmt::Display::fmt(&self.0, f)
+ }
+}
+
impl std::ops::Deref for Var {
type Target = Tensor;
@@ -90,12 +96,12 @@ impl Var {
pub fn set(&self, src: &Tensor) -> Result<()> {
if self.same_storage(src) {
let msg = "cannot set a variable to a tensor that is derived from its value";
- Err(Error::CannotSetVar { msg })?
+ Err(Error::CannotSetVar { msg }.bt())?
}
let (mut dst, layout) = self.storage_mut_and_layout();
if !layout.is_contiguous() {
let msg = "cannot set a non-contiguous variable";
- Err(Error::CannotSetVar { msg })?
+ Err(Error::CannotSetVar { msg }.bt())?
}
let (src, src_l) = src.storage_and_layout();
if layout.shape() != src_l.shape() {
@@ -103,7 +109,8 @@ impl Var {
lhs: layout.shape().clone(),
rhs: src_l.shape().clone(),
op: "set",
- })?
+ }
+ .bt())?
}
src.copy_strided_src(&mut dst, layout.start_offset(), src_l)?;
Ok(())