Skip to content

Commit 02350f9

Browse files
committed
Add: convert-tensors into src/bin
1 parent 1e2fb48 commit 02350f9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/bin/convert-tensor.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2019-present, Laurent Mazare.
2+
// Copyright 2019-present Guillaume Becquin
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
use failure::ensure;
14+
15+
pub fn main() -> failure::Fallible<()> {
16+
let args: Vec<_> = std::env::args().collect();
17+
ensure!(
18+
args.len() == 3,
19+
"usage: {} source.npz destination.ot",
20+
args[0]
21+
);
22+
23+
let source_file = &args[1];
24+
let destination_file = &args[2];
25+
let tensors = tch::Tensor::read_npz(source_file)?;
26+
tch::Tensor::save_multi(&tensors, destination_file)?;
27+
28+
Ok(())
29+
}

0 commit comments

Comments
 (0)