Skip to content

Commit

Permalink
Keep backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 30, 2023
1 parent e15876f commit d44b444
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ext/torch/torch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ void init_torch(Rice::Module& m) {
})
.define_singleton_function(
"_load",
[](const std::string filename) {
[](const std::string &filename) {
// https://github.com/pytorch/pytorch/issues/20356#issuecomment-567663701
std::ifstream input(filename, std::ios::binary);
std::vector<char> bytes(
(std::istreambuf_iterator<char>(input)),
(std::istreambuf_iterator<char>()));

input.close();
return torch::pickle_load(bytes);
})
Expand Down
3 changes: 3 additions & 0 deletions lib/torch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ def save(obj, f)
end

def load(f)
# keep backwards compatibility
File.open(f, "rb") { |f2| f2.read(1) }

to_ruby(_load(f))
end

Expand Down

0 comments on commit d44b444

Please sign in to comment.