5
5
6
6
from pyapprox .util .utilities import cartesian_product , outer_product
7
7
from pyapprox .surrogates .orthopoly .quadrature import gauss_jacobi_pts_wts_1D
8
- from pyapprox .variables .transforms import _map_hypercube_samples
9
8
from pyapprox .surrogates .interp .barycentric_interpolation import (
10
- compute_barycentric_weights_1d , barycentric_interpolation_1d
11
- )
9
+ compute_barycentric_weights_1d , barycentric_interpolation_1d )
12
10
from pyapprox .util .visualization import plt , get_meshgrid_samples
13
11
from pyapprox .pde .autopde .mesh_transforms import ScaleAndTranslationTransform
14
12
@@ -23,16 +21,16 @@ def full_fun_axis_1(fill_val, xx, oned=True):
23
21
24
22
def chebyshev_derivative_matrix (order ):
25
23
if order == 0 :
26
- pts = np .array ([1 ], float )
27
- derivative_matrix = np .array ([0 ], float )
24
+ pts = np .array ([1 ], dtype = float )
25
+ derivative_matrix = np .array ([0 ], dtype = float )
28
26
else :
29
27
# this is reverse order used by matlab cheb function
30
28
pts = - np .cos (np .linspace (0. , np .pi , order + 1 ))
31
- scalars = np .ones ((order + 1 ), float )
29
+ scalars = np .ones ((order + 1 ), dtype = float )
32
30
scalars [0 ] = 2.
33
31
scalars [order ] = 2.
34
32
scalars [1 :order + 1 :2 ] *= - 1
35
- derivative_matrix = np .empty ((order + 1 , order + 1 ), float )
33
+ derivative_matrix = np .empty ((order + 1 , order + 1 ), dtype = float )
36
34
for ii in range (order + 1 ):
37
35
row_sum = 0.
38
36
for jj in range (order + 1 ):
@@ -114,7 +112,7 @@ def fourier_basis(order, samples):
114
112
npts = (order + 1 )
115
113
h = 2 * np .pi / npts
116
114
pts = h * np .arange (1 , npts + 1 )
117
- II = np .where (samples == 2 * np .pi )[0 ]
115
+ II = np .where (samples == 2 * np .pi )[0 ]
118
116
samples [II ] = 0
119
117
xx = samples [:, None ]- pts [None , :]
120
118
vals = np .sin (np .pi * xx / h )/ (2 * np .pi / h * np .tan (xx / 2 ))
@@ -223,7 +221,7 @@ def kronecker_product_2d(matrix1, matrix2):
223
221
assert matrix1 .ndim == 2
224
222
block_num_rows = matrix1 .shape [0 ]
225
223
matrix_num_rows = block_num_rows ** 2
226
- matrix = np .empty ((matrix_num_rows , matrix_num_rows ), float )
224
+ matrix = np .empty ((matrix_num_rows , matrix_num_rows ), dtype = float )
227
225
228
226
# loop through blocks
229
227
start_col = 0
@@ -440,16 +438,33 @@ def _form_derivative_matrices(self):
440
438
compute_barycentric_weights_1d (xx ) for xx in canonical_mesh_pts_1d ]
441
439
442
440
if self .nphys_vars == 1 :
443
- canonical_deriv_mats = [canonical_deriv_mats_1d [0 ]]
441
+ canonical_deriv_mats = [
442
+ torch .as_tensor (
443
+ canonical_deriv_mats_1d [0 ], dtype = torch .double )]
444
444
else :
445
445
# assumes that 2d-mesh_pts varies in x1 faster than x2,
446
446
# e.g. points are
447
447
# [[x11,x21],[x12,x21],[x13,x12],[x11,x22],[x12,x22],...]
448
+
449
+ # The following fails with PyTorch 2.3.0
450
+ # I thought it may have been caused by converting numpy to tensor
451
+ # but this code suggests it is not that explicitly.
452
+ # What is confusing is this works in ipython as standalone code
453
+ # For now setting setup to only use pytorch<=2.2
454
+ # mat1 = torch.eye(31, dtype=torch.double)
455
+ # mat2 = torch.ones((31, 31), dtype=torch.double)
456
+ # C = torch.kron(mat1, mat2)
457
+ # print("A", C.shape)
448
458
canonical_deriv_mats = [
449
- np .kron (np .eye (self ._orders [1 ]+ 1 ), canonical_deriv_mats_1d [0 ]),
450
- np .kron (canonical_deriv_mats_1d [1 ], np .eye (self ._orders [0 ]+ 1 ))]
451
- canonical_deriv_mats = [torch .as_tensor (mat , dtype = torch .double )
452
- for mat in canonical_deriv_mats ]
459
+ torch .kron (
460
+ torch .eye (self ._orders [1 ]+ 1 , dtype = torch .double ),
461
+ torch .as_tensor (canonical_deriv_mats_1d [0 ],
462
+ dtype = torch .double )),
463
+ torch .kron (
464
+ torch .as_tensor (canonical_deriv_mats_1d [1 ],
465
+ dtype = torch .double ),
466
+ torch .eye (self ._orders [0 ]+ 1 , dtype = torch .double ))]
467
+
453
468
canonical_mesh_pts = cartesian_product (canonical_mesh_pts_1d )
454
469
455
470
return (canonical_mesh_pts_1d , canonical_deriv_mats_1d ,
0 commit comments