mirror of
https://github.com/huggingface/candle.git
synced 2025-06-19 11:56:45 +00:00
Add two methods.
This commit is contained in:
@ -25,9 +25,23 @@ impl PyTensor {
|
||||
Ok(Self(Tensor::new(f, &Cpu).map_err(wrap_err)?))
|
||||
}
|
||||
|
||||
#[getter]
|
||||
fn shape(&self) -> Vec<usize> {
|
||||
self.0.dims().to_vec()
|
||||
}
|
||||
|
||||
#[getter]
|
||||
fn rank(&self) -> usize {
|
||||
self.0.rank()
|
||||
}
|
||||
|
||||
fn __repr__(&self) -> String {
|
||||
format!("{}", self.0)
|
||||
}
|
||||
|
||||
fn __str__(&self) -> String {
|
||||
self.__repr__()
|
||||
}
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
|
@ -2,4 +2,5 @@ import candle
|
||||
|
||||
t = candle.Tensor(42.0)
|
||||
print(t)
|
||||
print("shape", t.shape, t.rank)
|
||||
print(candle.add(t, 3.14))
|
||||
|
Reference in New Issue
Block a user