@@ -185,129 +185,11 @@ void coo_matvec(PyObject *yy_py, PyObject *xx_py, bool ignore_nan,
185
185
}
186
186
187
187
188
- extern CythonWeightedSparse *RegridMatrices_matrix (RegridMatrices *cself, std::string const &spec_name, bool scale, bool correctA, double sigma_x, double sigma_y, double sigma_z, bool conserve )
188
+ extern linear::Weighted *RegridMatrices_matrix (RegridMatrices *cself, std::string const &spec_name)
189
189
{
190
- std::unique_ptr<CythonWeightedSparse> CRM (new CythonWeightedSparse ());
191
-
192
- CRM->RM = cself->matrix_d (spec_name,
193
- {&CRM->dims [0 ], &CRM->dims [1 ]},
194
- RegridParams (scale, correctA, {sigma_x, sigma_y, sigma_z}));
195
-
196
- CythonWeightedSparse *ret = CRM.release ();
197
- return ret;
190
+ return cself->matrix (spec_name).release ();
198
191
}
199
192
200
- extern PyObject *CythonWeightedSparse_apply (
201
- CythonWeightedSparse *BvA,
202
- PyObject *A_s_py, // A_b{nj_s} One row per variable
203
- double fill, bool force_conservation)
204
- {
205
- // |j_s| = size of sparse input vector space (A_s)
206
- // |j_d] = size of dense input vector space (A_d)
207
- // |n| = number of variables being processed together
208
-
209
- // Allocate dense A matrix
210
- auto &bdim (BvA->dims [0 ]);
211
- auto &adim (BvA->dims [1 ]);
212
- auto A_s (np_to_blitz<double ,2 >(A_s_py, " A" , {-1 ,-1 })); // Sparse indexed dense vector
213
- int n_n = A_s.extent (0 );
214
-
215
- // Densify the A matrix
216
- blitz::Array<double ,2 > A_d (n_n, adim.dense_extent ());
217
- for (int j_d=0 ; j_d < adim.dense_extent (); ++j_d) {
218
- int j_s = adim.to_sparse (j_d);
219
- for (int n=0 ; n < n_n; ++n) {
220
- A_d (n,j_d) = A_s (n,j_s);
221
- }
222
- }
223
-
224
- // Apply...
225
- auto B_d_eigen (BvA->RM ->apply_e (A_d, fill, force_conservation)); // Column major indexing
226
-
227
- // Allocate output vector and get a Blitz view
228
- // We will copy from the Eigen data structure to the Python
229
- PyObject *B_s_py = ibmisc::cython::new_pyarray<double ,2 >(
230
- std::array<int ,2 >{n_n, bdim.sparse_extent ()});
231
- auto B_s (np_to_blitz<double ,2 >(B_s_py, " B_s_py" , {-1 ,-1 }));
232
-
233
- // Sparsify the output B
234
- for (int n=0 ; n < n_n; ++n)
235
- for (int j_s=0 ; j_s < bdim.sparse_extent (); ++j_s) {
236
- B_s (n,j_s) = fill;
237
- }
238
-
239
- for (int j_d=0 ; j_d < bdim.dense_extent (); ++j_d) {
240
- int j_s = bdim.to_sparse (j_d);
241
- for (int n=0 ; n < n_n; ++n) {
242
- B_s (n,j_s) = B_d_eigen (j_d,n);
243
- }
244
- }
245
-
246
- return B_s_py;
247
- }
248
-
249
- PyObject *CythonWeightedSparse_dense_extent (CythonWeightedSparse const *cself)
250
- {
251
- return Py_BuildValue (" ll" ,
252
- (long )cself->dims [0 ].dense_extent (),
253
- (long )cself->dims [1 ].dense_extent ());
254
- }
255
-
256
- PyObject *CythonWeightedSparse_sparse_extent (CythonWeightedSparse const *cself)
257
- {
258
- return Py_BuildValue (" ll" ,
259
- (long )cself->dims [0 ].sparse_extent (),
260
- (long )cself->dims [1 ].sparse_extent ());
261
- }
262
-
263
-
264
- PyObject *CythonWeightedSparse_to_tuple (CythonWeightedSparse *cself)
265
- {
266
- // ----- Convert a dense vector w/ dense indices to a dense vector with sparse indices
267
- if (cself->dims [0 ].sparse_extent () <= 0 ) (*icebin_error)(-1 ,
268
- " dims[0].sparse_extent() must be > 0" );
269
-
270
- // ---------- wM
271
- // Allocate the output Python vector
272
- PyObject *wM_py = ibmisc::cython::new_pyarray<double ,1 >(
273
- std::array<int ,1 >{cself->dims [0 ].sparse_extent ()});
274
- // Get a Blitz view on it
275
- auto wM_pyb (np_to_blitz<double ,1 >(wM_py, " wM_py" , {-1 }));
276
- // Copy, while translating the dimension
277
- spcopy (
278
- accum::to_sparse (make_array (&cself->dims [0 ]),
279
- accum::blitz_existing (wM_pyb)),
280
- cself->RM ->wM );
281
-
282
- // -------------- M
283
- // Convert a sparse matrix w/ dense indices to a sparse matrix with sparse indices
284
- TupleListT<2 > RM_sp;
285
- printf (" DD1 about to copy: sparse_extent=(%ld, %ld), dense_extent=(%d, %d)\n " ,
286
- cself->dims [0 ].sparse_extent (),
287
- cself->dims [1 ].sparse_extent (),
288
- cself->dims [0 ].dense_extent (),
289
- cself->dims [1 ].dense_extent ());
290
-
291
- spcopy (
292
- accum::to_sparse (make_array (&cself->dims [0 ], &cself->dims [1 ]),
293
- accum::ref (RM_sp)),
294
- *cself->RM ->M );
295
- PyObject *M_py = ibmisc::cython::spsparse_to_tuple (RM_sp);
296
-
297
- // ---------- Mw
298
- // Allocate the output Python vector
299
- PyObject *Mw_py = ibmisc::cython::new_pyarray<double ,1 >(
300
- std::array<int ,1 >{cself->dims [1 ].sparse_extent ()});
301
- // Get a Blitz view on it
302
- auto Mw_pyb (np_to_blitz<double ,1 >(Mw_py, " Mw_py" , {-1 }));
303
- // Copy, while translating the dimension
304
- spcopy (
305
- accum::to_sparse (make_array (&cself->dims [1 ]),
306
- accum::blitz_existing (Mw_pyb)),
307
- cself->RM ->Mw );
308
-
309
- return Py_BuildValue (" OOO" , wM_py, M_py, Mw_py);
310
- }
311
193
312
194
// ------------------------------------------------------------
313
195
PyObject *Hntr_regrid (Hntr const *hntr, PyObject *WTA_py, PyObject *A_py, bool mean_polar)
@@ -323,13 +205,27 @@ PyObject *Hntr_regrid(Hntr const *hntr, PyObject *WTA_py, PyObject *A_py, bool m
323
205
return B_py;
324
206
}
325
207
326
- RegridMatrices *new_regrid_matrices (GCMRegridder const *gcm, std::string const &sheet_name, PyObject *elevmaskI_py)
208
+ RegridMatrices *new_regrid_matrices (
209
+ GCMRegridder const *gcm,
210
+ std::string const &sheet_name,
211
+ PyObject *elevmaskI_py,
212
+ // --------- Params
213
+ bool scale,
214
+ bool correctA,
215
+ double sigma_x,
216
+ double sigma_y,
217
+ double sigma_z,
218
+ bool conserve)
327
219
{
220
+
221
+
328
222
auto sheet_index = gcm->ice_regridders ().index .at (sheet_name);
329
223
IceRegridder *ice_regridder = &*gcm->ice_regridders ()[sheet_index];
330
224
auto elevmaskI (np_to_blitz<double ,1 >(elevmaskI_py, " elevmaskI" , {ice_regridder->nI ()}));
331
225
332
- return new RegridMatrices (gcm->regrid_matrices (sheet_index, elevmaskI));
226
+ return gcm->regrid_matrices (
227
+ sheet_index, elevmaskI,
228
+ RegridParams (scale, correctA, {sigma_x, sigma_y, sigma_z})).release ();
333
229
}
334
230
335
231
std::string to_string (PyObject *str, std::string const &vname)
0 commit comments