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