@@ -78,10 +78,11 @@ static pybind11::array_t<double> _get_transform_mesh(const pybind11::object& tra
78
78
auto output_mesh_array =
79
79
pybind11::array_t <double , pybind11::array::c_style | pybind11::array::forcecast>(output_mesh);
80
80
81
- if (output_mesh_array.ndim () != 2 )
81
+ if (output_mesh_array.ndim () != 2 ) {
82
82
throw std::runtime_error (
83
83
" Inverse transformed mesh array should be 2D not " +
84
84
std::to_string (output_mesh_array.ndim ()) + " D" );
85
+ }
85
86
86
87
return output_mesh_array;
87
88
}
@@ -102,38 +103,45 @@ static void image_resample(pybind11::array input_array,
102
103
auto dtype = input_array.dtype (); // Validated when determine resampler below
103
104
auto ndim = input_array.ndim ();
104
105
105
- if (ndim != 2 && ndim != 3 )
106
+ if (ndim != 2 && ndim != 3 ) {
106
107
throw std::invalid_argument (" Input array must be a 2D or 3D array" );
108
+ }
107
109
108
- if (ndim == 3 && input_array.shape (2 ) != 4 )
110
+ if (ndim == 3 && input_array.shape (2 ) != 4 ) {
109
111
throw std::invalid_argument (
110
112
" 3D input array must be RGBA with shape (M, N, 4), has trailing dimension of " +
111
113
std::to_string (ndim));
114
+ }
112
115
113
116
// Ensure input array is contiguous, regardless of dtype
114
117
input_array = pybind11::array::ensure (input_array, pybind11::array::c_style);
115
118
116
119
// Validate output array
117
120
auto out_ndim = output_array.ndim ();
118
121
119
- if (out_ndim != ndim)
122
+ if (out_ndim != ndim) {
120
123
throw std::invalid_argument (
121
124
" Input (" + std::to_string (ndim) + " D) and output (" + std::to_string (out_ndim) +
122
125
" D) arrays have different dimensionalities" );
126
+ }
123
127
124
- if (out_ndim == 3 && output_array.shape (2 ) != 4 )
128
+ if (out_ndim == 3 && output_array.shape (2 ) != 4 ) {
125
129
throw std::invalid_argument (
126
130
" 3D output array must be RGBA with shape (M, N, 4), has trailing dimension of " +
127
131
std::to_string (out_ndim));
132
+ }
128
133
129
- if (!output_array.dtype ().is (dtype))
134
+ if (!output_array.dtype ().is (dtype)) {
130
135
throw std::invalid_argument (" Input and output arrays have mismatched types" );
136
+ }
131
137
132
- if ((output_array.flags () & pybind11::array::c_style) == 0 )
138
+ if ((output_array.flags () & pybind11::array::c_style) == 0 ) {
133
139
throw std::invalid_argument (" Output array must be C-contiguous" );
140
+ }
134
141
135
- if (!output_array.writeable ())
142
+ if (!output_array.writeable ()) {
136
143
throw std::invalid_argument (" Output array must be writeable" );
144
+ }
137
145
138
146
resample_params_t params;
139
147
params.interpolation = interpolation;
@@ -187,8 +195,9 @@ static void image_resample(pybind11::array input_array,
187
195
output_array.mutable_data (), output_array.shape (1 ), output_array.shape (0 ),
188
196
params);
189
197
Py_END_ALLOW_THREADS
190
- } else
198
+ } else {
191
199
throw std::invalid_argument (" arrays must be of dtype byte, short, float32 or float64" );
200
+ }
192
201
}
193
202
194
203
0 commit comments