Skip to content

Commit e354f6a

Browse files
author
“thucydides”
committed
fix: Resolve orphan rules and trait bounds in rustorch-pytorch
1 parent fbff6b6 commit e354f6a

2 files changed

Lines changed: 5 additions & 21 deletions

File tree

rustorch-pytorch/src/lib.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use rustorch_core::{Tensor, Storage};
1+
use rustorch_core::Tensor;
22
use tch::{self, Kind, Device as TchDevice};
3-
use anyhow::{Result, Context};
3+
use anyhow::Result;
44
use std::path::Path;
5-
use std::borrow::Borrow;
65

76
pub struct PyTorchAdapter;
87

@@ -31,10 +30,10 @@ impl PyTorchAdapter {
3130
// Cast to float if not
3231
// For now, we only support f32 in RusTorch
3332
let float_tensor = cpu_tensor.to_kind(Kind::Float);
34-
let data: Vec<f32> = Vec::<f32>::from(&float_tensor);
33+
let data: Vec<f32> = float_tensor.into();
3534
Ok(Tensor::new(&data, &size))
3635
} else {
37-
let data: Vec<f32> = Vec::<f32>::from(&cpu_tensor);
36+
let data: Vec<f32> = cpu_tensor.into();
3837
Ok(Tensor::new(&data, &size))
3938
}
4039
}
@@ -104,21 +103,6 @@ pub mod ops {
104103
}
105104
}
106105

107-
// Implement From traits for convenience
108-
impl From<&Tensor> for tch::Tensor {
109-
fn from(tensor: &Tensor) -> Self {
110-
PyTorchAdapter::to_torch(tensor)
111-
}
112-
}
113-
114-
impl TryFrom<&tch::Tensor> for Tensor {
115-
type Error = anyhow::Error;
116-
117-
fn try_from(tensor: &tch::Tensor) -> Result<Self> {
118-
PyTorchAdapter::from_torch(tensor)
119-
}
120-
}
121-
122106
#[cfg(test)]
123107
mod tests {
124108
use super::*;

target/.rustc_info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"rustc_fingerprint":18217616115906611278,"outputs":{"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\nlib___.a\n___.dll\nC:\\Users\\25919\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\noff\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.94.0 (4a4ef493e 2026-03-02)\nbinary: rustc\ncommit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db\ncommit-date: 2026-03-02\nhost: x86_64-pc-windows-gnu\nrelease: 1.94.0\nLLVM version: 21.1.8\n","stderr":""}},"successes":{}}
1+
{"rustc_fingerprint":5931207633046374884,"outputs":{"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\25919\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.94.0 (4a4ef493e 2026-03-02)\nbinary: rustc\ncommit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db\ncommit-date: 2026-03-02\nhost: x86_64-pc-windows-msvc\nrelease: 1.94.0\nLLVM version: 21.1.8\n","stderr":""}},"successes":{}}

0 commit comments

Comments
 (0)