mirror of
https://github.com/wassname/pytorch-for-numpy-users.git
synced 2026-06-27 16:10:21 +08:00
52 lines
1.3 KiB
Python
Executable File
52 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import collections
|
|
import os.path as osp
|
|
|
|
import tabulate
|
|
import yaml
|
|
|
|
|
|
TEMPLATE = '''\
|
|
# PyTorch for Numpy users.
|
|
|
|
[](https://travis-ci.com/wkentaro/pytorch-for-numpy-users)
|
|
|
|
[PyTorch](https://github.com/pytorch/pytorch.git) version of [_Torch for Numpy users_](https://github.com/torch/torch7/wiki/Torch-for-Numpy-users).
|
|
|
|
{contents}
|
|
'''
|
|
|
|
|
|
here = osp.dirname(osp.abspath(__file__))
|
|
|
|
|
|
def get_contents():
|
|
# keep order in yaml file
|
|
yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
|
|
lambda loader, node: \
|
|
collections.OrderedDict(loader.construct_pairs(node)))
|
|
|
|
yaml_file = osp.join(here, 'conversions.yaml')
|
|
data = yaml.load(open(yaml_file))
|
|
contents = ''
|
|
for section, data in data.items():
|
|
headers = ['Numpy', 'PyTorch']
|
|
rows = []
|
|
for d in data:
|
|
rows.append([
|
|
'`' + d['numpy'] + '`',
|
|
'`' + d['pytorch'] + '`',
|
|
])
|
|
contents += '''
|
|
## {title}
|
|
|
|
{table}\n'''.format(
|
|
title=section.capitalize(),
|
|
table=tabulate.tabulate(rows, headers=headers, tablefmt='pipe'),
|
|
)
|
|
return contents
|
|
|
|
|
|
print(TEMPLATE.format(contents=get_contents()))
|