diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py index 94f3477290ecf79fcd8a095389a752d1505d67e2..3aac0168406c8e100b79e075243b8f56e81a069e 100644 --- a/pystencils/backends/cbackend.py +++ b/pystencils/backends/cbackend.py @@ -196,7 +196,7 @@ class CBackend: method_name = "_print_" + cls.__name__ if hasattr(self, method_name): return getattr(self, method_name)(node) - raise NotImplementedError(self.__class__.__name__ + " does not support node of type " + node.__class__.__name__) + raise NotImplementedError(f"{self.__class__.__name__} does not support node of type {node.__class__.__name__}") def _print_Type(self, node): return str(node) @@ -651,7 +651,7 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): return self.instruction_set['/'].format(one, self._print(sp.Mul(*[expr.base] * (-expr.exp), evaluate=False))) else: - raise ValueError("Generic exponential not supported: " + str(expr)) + raise ValueError(f"Generic exponential not supported: {str(expr)}") def _print_Mul(self, expr, inside_add=False): # noinspection PyProtectedMember diff --git a/pystencils/datahandling/serial_datahandling.py b/pystencils/datahandling/serial_datahandling.py index 7352951d22393d58ca6f6bef52522e5760ba71cb..1d397c51bca4f0540911bb1aeaf6a1c2233c7400 100644 --- a/pystencils/datahandling/serial_datahandling.py +++ b/pystencils/datahandling/serial_datahandling.py @@ -431,8 +431,7 @@ class SerialDataHandling(DataHandling): print(f"Skipping read data {arr_name} because there is no data with this name in data handling") continue if file_contents[arr_name].shape != arr_contents.shape: - print("Skipping read data {} because shapes don't match. " - "Read array shape {}, existing array shape {}".format(arr_name, file_contents[arr_name].shape, - arr_contents.shape)) + print(f"Skipping read data {arr_name} because shapes don't match. " + f"Read array shape {file_contents[arr_name].shape}, existing array shape {arr_contents.shape}") continue np.copyto(arr_contents, file_contents[arr_name]) diff --git a/pystencils/gpucuda/cudajit.py b/pystencils/gpucuda/cudajit.py index 86f251c97b95f04c52aaa803398ddb78ba42a2c1..9290f8ab1428b289fecb5ec004c04b93eede6b1b 100644 --- a/pystencils/gpucuda/cudajit.py +++ b/pystencils/gpucuda/cudajit.py @@ -123,8 +123,8 @@ def _build_numpy_argument_list(parameters, argument_dict): actual_type = array.dtype expected_type = param.fields[0].dtype.numpy_dtype if expected_type != actual_type: - raise ValueError("Data type mismatch for field '%s'. Expected '%s' got '%s'." % - (param.field_name, expected_type, actual_type)) + raise ValueError(f"Data type mismatch for field '{param.field_name}'. " + f"Expected '{expected_type}' got '{actual_type}'.") result.append(array) elif param.is_field_stride: cast_to_dtype = param.symbol.dtype.numpy_dtype.type @@ -159,22 +159,22 @@ def _check_arguments(parameter_specification, argument_dict): try: field_arr = argument_dict[symbolic_field.name] except KeyError: - raise KeyError("Missing field parameter for kernel call " + str(symbolic_field)) + raise KeyError(f"Missing field parameter for kernel call {str(symbolic_field)}") if symbolic_field.has_fixed_shape: symbolic_field_shape = tuple(int(i) for i in symbolic_field.shape) if isinstance(symbolic_field.dtype, StructType): symbolic_field_shape = symbolic_field_shape[:-1] if symbolic_field_shape != field_arr.shape: - raise ValueError("Passed array '%s' has shape %s which does not match expected shape %s" % - (symbolic_field.name, str(field_arr.shape), str(symbolic_field.shape))) + raise ValueError(f"Passed array '{symbolic_field.name}' has shape {str(field_arr.shape)} " + f"which does not match expected shape {str(symbolic_field.shape)}") if symbolic_field.has_fixed_shape: symbolic_field_strides = tuple(int(i) * field_arr.dtype.itemsize for i in symbolic_field.strides) if isinstance(symbolic_field.dtype, StructType): symbolic_field_strides = symbolic_field_strides[:-1] if symbolic_field_strides != field_arr.strides: - raise ValueError("Passed array '%s' has strides %s which does not match expected strides %s" % - (symbolic_field.name, str(field_arr.strides), str(symbolic_field_strides))) + raise ValueError(f"Passed array '{symbolic_field.name}' has strides {str(field_arr.strides)} " + f"which does not match expected strides {str(symbolic_field_strides)}") if FieldType.is_indexed(symbolic_field): index_arr_shapes.add(field_arr.shape[:symbolic_field.spatial_dimensions]) @@ -182,9 +182,9 @@ def _check_arguments(parameter_specification, argument_dict): array_shapes.add(field_arr.shape[:symbolic_field.spatial_dimensions]) if len(array_shapes) > 1: - raise ValueError("All passed arrays have to have the same size " + str(array_shapes)) + raise ValueError(f"All passed arrays have to have the same size {str(array_shapes)}") if len(index_arr_shapes) > 1: - raise ValueError("All passed index arrays have to have the same size " + str(array_shapes)) + raise ValueError(f"All passed index arrays have to have the same size {str(array_shapes)}") if len(index_arr_shapes) > 0: return list(index_arr_shapes)[0] diff --git a/pystencils/gpucuda/indexing.py b/pystencils/gpucuda/indexing.py index 23c4f34908d09f871713e0ef9ae52e4ee41f8ba1..0de55ec42c8132390a8bd497add2bf1666fd4fd7 100644 --- a/pystencils/gpucuda/indexing.py +++ b/pystencils/gpucuda/indexing.py @@ -312,7 +312,7 @@ def indexing_creator_from_params(gpu_indexing, gpu_indexing_params): elif gpu_indexing == 'line': indexing_creator = LineIndexing else: - raise ValueError("Unknown GPU indexing %s. Valid values are 'block' and 'line'" % (gpu_indexing,)) + raise ValueError(f"Unknown GPU indexing {gpu_indexing}. Valid values are 'block' and 'line'") if gpu_indexing_params: indexing_creator = partial(indexing_creator, **gpu_indexing_params) return indexing_creator