Commit 76d04d6f authored by rusty1s's avatar rusty1s
Browse files

no f strings

parent 5a006f71
......@@ -11,7 +11,7 @@ from torch.utils.cpp_extension import CppExtension, CUDAExtension, CUDA_HOME
WITH_CUDA = torch.cuda.is_available() and CUDA_HOME is not None
if os.getenv('FORCE_CUDA', '0') == '1':
WITH_CUDA = True
if os.getenv('FORCE_NON_CUDA', '0') == '1':
if os.getenv('FORCE_CPU', '0') == '1':
WITH_CUDA = False
BUILD_DOCS = os.getenv('BUILD_DOCS', '0') == '1'
......@@ -23,39 +23,37 @@ def get_extensions():
extra_compile_args = {'cxx': [], 'nvcc': []}
extra_link_args = []
# Windows users: Edit both of these to contain your VS include path, i.e.:
# extra_compile_args['cxx'] += ['-I{VISUAL_STUDIO_DIR}\\include']
# extra_compile_args['nvcc'] += ['-I{VISUAL_STUDIO_DIR}\\include']
if WITH_CUDA:
Extension = CUDAExtension
define_macros += [('WITH_CUDA', None)]
nvcc_flags = os.getenv('NVCC_FLAGS', '')
nvcc_flags = [] if nvcc_flags == '' else nvcc_flags.split(' ')
nvcc_flags += ['-arch=sm_35', '--expt-relaxed-constexpr']
extra_compile_args['cxx'] += ['-O0']
extra_compile_args['nvcc'] += nvcc_flags
if sys.platform == 'win32':
if sys.platform == 'win32':
extra_link_args = ['cusparse.lib']
else:
extra_link_args = ['-lcusparse', '-l', 'cusparse']
if sys.platform == 'win32':
extra_compile_args['cxx'] += ['/MP']
extensions_dir = osp.join(osp.dirname(osp.abspath(__file__)), 'csrc')
main_files = glob.glob(osp.join(extensions_dir, '*.cpp'))
extensions = []
for main in main_files:
name = main.split(os.sep)[-1][:-4]
sources = [main, osp.join(extensions_dir, 'cpu', f'{name}_cpu.cpp')]
if WITH_CUDA:
sources += [osp.join(extensions_dir, 'cuda', f'{name}_cuda.cu')]
sources = [main]
path = osp.join(extensions_dir, 'cpu', name + '_cpu.cpp')
if osp.exists(path):
sources += [path]
path = osp.join(extensions_dir, 'cuda', name + '_cuda.cu')
if WITH_CUDA and osp.exists(path):
sources += [path]
extension = Extension(
f'torch_sparse._{name}',
'torch_sparse._' + name,
sources,
include_dirs=[extensions_dir],
define_macros=define_macros,
......@@ -73,7 +71,7 @@ tests_require = ['pytest', 'pytest-cov']
setup(
name='torch_sparse',
version='0.5.0',
version='0.5.1',
author='Matthias Fey',
author_email='matthias.fey@tu-dortmund.de',
url='https://github.com/rusty1s/pytorch_sparse',
......@@ -81,6 +79,7 @@ setup(
'Matrix Operations'),
keywords=['pytorch', 'sparse', 'sparse-matrices', 'autograd'],
license='MIT',
python_requires='>=3.5',
install_requires=install_requires,
setup_requires=setup_requires,
tests_require=tests_require,
......
......@@ -14,9 +14,9 @@ def add(src: SparseTensor, other: torch.Tensor) -> SparseTensor:
elif other.size(0) == 1 and other.size(1) == src.size(1): # Col-wise...
other = other.squeeze(0)[col]
else:
raise ValueError(f'Size mismatch: Expected size ({src.size(0)}, 1,'
f' ...) or (1, {src.size(1)}, ...), but got size '
f'{other.size()}.')
raise ValueError(
'Size mismatch: Expected size ({}, 1, ...) or (1, {}, ...), but '
'got size {}.'.format(src.size(0), src.size(1), other.size()))
if value is not None:
value = other.to(value.dtype).add_(value)
......@@ -34,9 +34,9 @@ def add_(src: SparseTensor, other: torch.Tensor) -> SparseTensor:
elif other.size(0) == 1 and other.size(1) == src.size(1): # Col-wise...
other = other.squeeze(0)[col]
else:
raise ValueError(f'Size mismatch: Expected size ({src.size(0)}, 1,'
f' ...) or (1, {src.size(1)}, ...), but got size '
f'{other.size()}.')
raise ValueError(
'Size mismatch: Expected size ({}, 1, ...) or (1, {}, ...), but '
'got size {}.'.format(src.size(0), src.size(1), other.size()))
if value is not None:
value = value.add_(other.to(value.dtype))
......
......@@ -138,8 +138,8 @@ def cat(tensors: List[SparseTensor], dim: int) -> SparseTensor:
return tensors[0].set_value(value, layout='coo')
else:
raise IndexError(
(f'Dimension out of range: Expected to be in range of '
f'[{-tensors[0].dim()}, {tensors[0].dim() - 1}, but got {dim}]'))
'Dimension out of range: Expected to be in range of [{}, {}], but '
'got {}.'.format(-tensors[0].dim(), tensors[0].dim() - 1, dim))
@torch.jit.script
......
......@@ -14,9 +14,9 @@ def mul(src: SparseTensor, other: torch.Tensor) -> SparseTensor:
elif other.size(0) == 1 and other.size(1) == src.size(1): # Col-wise...
other = other.squeeze(0)[col]
else:
raise ValueError(f'Size mismatch: Expected size ({src.size(0)}, 1,'
f' ...) or (1, {src.size(1)}, ...), but got size '
f'{other.size()}.')
raise ValueError(
'Size mismatch: Expected size ({}, 1, ...) or (1, {}, ...), but '
'got size {}.'.format(src.size(0), src.size(1), other.size()))
if value is not None:
value = other.to(value.dtype).mul_(value)
......@@ -34,9 +34,9 @@ def mul_(src: SparseTensor, other: torch.Tensor) -> SparseTensor:
elif other.size(0) == 1 and other.size(1) == src.size(1): # Col-wise...
other = other.squeeze(0)[col]
else:
raise ValueError(f'Size mismatch: Expected size ({src.size(0)}, 1,'
f' ...) or (1, {src.size(1)}, ...), but got size '
f'{other.size()}.')
raise ValueError(
'Size mismatch: Expected size ({}, 1, ...) or (1, {}, ...), but '
'got size {}.'.format(src.size(0), src.size(1), other.size()))
if value is not None:
value = value.mul_(other.to(value.dtype))
......
......@@ -487,21 +487,22 @@ def __repr__(self: SparseTensor) -> str:
i = ' ' * 6
row, col, value = self.coo()
infos = []
infos += [f'row={indent(row.__repr__(), i)[len(i):]}']
infos += [f'col={indent(col.__repr__(), i)[len(i):]}']
infos += ['row={}'.format(indent(row.__repr__(), i)[len(i):])]
infos += ['col={}'.format(indent(col.__repr__(), i)[len(i):])]
if value is not None:
infos += [f'val={indent(value.__repr__(), i)[len(i):]}']
infos += ['val={}'.format(indent(value.__repr__(), i)[len(i):])]
infos += [
f'size={tuple(self.sizes())}, '
f'nnz={self.nnz()}, '
f'density={100 * self.density():.02f}%'
'size={}, '.format(tuple(self.sizes())) +
'nnz={}, '.format(self.nnz()) +
'density={:.02f}%'.format(100 * self.density())
]
infos = ',\n'.join(infos)
i = ' ' * (len(self.__class__.__name__) + 1)
return f'{self.__class__.__name__}({indent(infos, i)[len(i):]})'
return '{}({})'.format(self.__class__.__name__, indent(infos, i)[len(i):])
SparseTensor.share_memory_ = share_memory_
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment