Skip to content

Commit 5752d8f

Browse files
committed
Prepare to return Device instead of String
1 parent dde07b9 commit 5752d8f

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

ext/torch/device.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@ void init_device(Rice::Module& m) {
2323
std::stringstream s;
2424
s << self.type();
2525
return s.str();
26+
})
27+
.define_method(
28+
"_str",
29+
[](torch::Device& self) {
30+
return self.str();
2631
});
2732
}

ext/torch/ext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void Init_ext()
3131

3232
// keep this order
3333
init_torch(m);
34+
init_device(m);
3435
init_tensor(m, rb_cTensor, rb_cTensorOptions);
3536
init_nn(m);
3637
init_fft(m);
@@ -39,7 +40,6 @@ void Init_ext()
3940

4041
init_backends(m);
4142
init_cuda(m);
42-
init_device(m);
4343
init_generator(m, rb_cGenerator);
4444
init_ivalue(m, rb_cIValue);
4545
init_random(m);

ext/torch/tensor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,9 @@ void init_tensor(Rice::Module& m, Rice::Class& c, Rice::Class& rb_cTensorOptions
212212
return s.str();
213213
})
214214
.define_method(
215-
"device",
215+
"_device",
216216
[](Tensor& self) {
217-
std::stringstream s;
218-
s << self.device();
219-
return s.str();
217+
return self.device();
220218
})
221219
.define_method(
222220
"_data_str",

lib/torch/tensor.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,10 @@ def coerce(other)
209209
raise TypeError, "#{self.class} can't be coerced into #{other.class}"
210210
end
211211
end
212+
213+
# TODO return Device instead of String in 0.19.0
214+
def device
215+
_device._str
216+
end
212217
end
213218
end

0 commit comments

Comments
 (0)