Skip to content

Commit

Permalink
Prepare to return Device instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Nov 3, 2024
1 parent dde07b9 commit 5752d8f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ext/torch/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ void init_device(Rice::Module& m) {
std::stringstream s;
s << self.type();
return s.str();
})
.define_method(
"_str",
[](torch::Device& self) {
return self.str();
});
}
2 changes: 1 addition & 1 deletion ext/torch/ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void Init_ext()

// keep this order
init_torch(m);
init_device(m);
init_tensor(m, rb_cTensor, rb_cTensorOptions);
init_nn(m);
init_fft(m);
Expand All @@ -39,7 +40,6 @@ void Init_ext()

init_backends(m);
init_cuda(m);
init_device(m);
init_generator(m, rb_cGenerator);
init_ivalue(m, rb_cIValue);
init_random(m);
Expand Down
6 changes: 2 additions & 4 deletions ext/torch/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,9 @@ void init_tensor(Rice::Module& m, Rice::Class& c, Rice::Class& rb_cTensorOptions
return s.str();
})
.define_method(
"device",
"_device",
[](Tensor& self) {
std::stringstream s;
s << self.device();
return s.str();
return self.device();
})
.define_method(
"_data_str",
Expand Down
5 changes: 5 additions & 0 deletions lib/torch/tensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,10 @@ def coerce(other)
raise TypeError, "#{self.class} can't be coerced into #{other.class}"
end
end

# TODO return Device instead of String in 0.19.0
def device
_device._str
end
end
end

0 comments on commit 5752d8f

Please sign in to comment.