Skip to content

Commit 02c48fe

Browse files
authored
Merge pull request #791 from mkstoyanov/update_diff
Updated the documentation for the new python method and added some testing.
2 parents fb282c9 + 06c0386 commit 02c48fe

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

InterfacePython/TasmanianSG.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
pLibTSG.tsgGetPointsStatic.argtypes = [c_void_p, POINTER(c_double)]
111111
pLibTSG.tsgGetQuadratureWeightsStatic.argtypes = [c_void_p, POINTER(c_double)]
112112
pLibTSG.tsgGetInterpolationWeightsStatic.argtypes = [c_void_p, POINTER(c_double), POINTER(c_double)]
113+
pLibTSG.tsgGetDifferentiationWeightsStatic.argtypes = [c_void_p, POINTER(c_double), POINTER(c_double)]
113114
pLibTSG.tsgLoadNeededValues.argtypes = [c_void_p, POINTER(c_double)]
114115
pLibTSG.tsgGetLoadedValuesStatic.argtypes = [c_void_p, POINTER(c_double)]
115116
pLibTSG.tsgEvaluate.argtypes = [c_void_p, POINTER(c_double), POINTER(c_double)]
@@ -1091,11 +1092,11 @@ def getDifferentiationWeights(self, lfX):
10911092
lfX: a 1-D numpy.ndarray with length iDimensions
10921093
the entries indicate the points for evaluating the weights
10931094
1094-
output: a 1-D numpy.ndarray of length getNumPoints()
1095+
output: a 2-D numpy.ndarray of size (getNumPoints(), iDimensions)
10951096
the order of the weights matches the order in getPoints()
10961097
1097-
TODO: This, and the C++ call, would probably benefit from using a
1098-
sparse matrix data structure.
1098+
Similar to the other Weights methods, those are generally slower than
1099+
the internal alternatives, e.g., differentiate() or evaluate().
10991100
'''
11001101
iNumX = len(lfX)
11011102
if (iNumX != self.getNumDimensions()):

InterfacePython/testExceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def getSparseGridTests(self):
209209
["grid1 = Tasmanian.SparseGrid(); grid1.setGPUID(grid1.getNumGPUs());", "iGPUID"],
210210
["grid.makeLocalPolynomialGrid(1, 1, 1, 1, 'localp'); Tasmanian.loadNeededPoints(lambda x, tid : x, grid, 1);", "notError"],
211211
["grid.makeLocalPolynomialGrid(1, 1, 1, 1, 'localp'); Tasmanian.loadNeededPoints(lambda x, tid : np.ones((2,)) * x, grid, 1);", "loadNeededValues"],
212+
["grid.makeLocalPolynomialGrid(1, 1, 1, 1, 'localp'); grid.getDifferentiationWeights((1, 2));", "lfX"],
213+
["grid.makeLocalPolynomialGrid(2, 0, 2, 1, 'localp'); grid.getDifferentiationWeights(np.array((1.0, 2.0)));", "notError"],
212214
]
213215

214216
def getCustomTabulatedTests(self):

InterfacePython/testMakeUpdate.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def checkMakeAgainstKnown(self):
9494
aW1 = grid.getInterpolationWeights(aX1)
9595
aW2 = grid.getInterpolationWeights(aX2)
9696
aW3 = grid.getInterpolationWeights(aX3)
97-
aWW = np.row_stack([aW1, aW2, aW3])
97+
aWW = np.vstack([aW1, aW2, aW3])
9898
np.testing.assert_equal(aW, aWW, "Batch weights", True)
9999

100100
grid.makeGlobalGrid(3, 0, 1, 'level', 'chebyshev')
@@ -116,6 +116,11 @@ def checkMakeAgainstKnown(self):
116116
aA = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, -0.707106781186548], [0.0, 0.0, 0.707106781186548], [0.0, -0.707106781186548, 0.0], [0.0, 0.707106781186548, 0.0], [-0.707106781186548, 0.0, 0.0], [0.707106781186548, 0.0, 0.0]])
117117
np.testing.assert_almost_equal(aA, grid.getPoints(), 14, "Original equal", True)
118118

119+
grid = Tasmanian.makeLocalPolynomialGrid(2, 1, 1, 2, "localp")
120+
aW = grid.getDifferentiationWeights(np.array((0.5, 0.5)))
121+
aA = np.array(((-1.0, -1.0), (0.0, 0.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)))
122+
np.testing.assert_almost_equal(aA, aW, 14, "Differentiation weights", True)
123+
119124
# number of points
120125
grid = Tasmanian.makeLocalPolynomialGrid(2, 1, 2, 2, "localp")
121126
iNN = grid.getNumNeeded()

0 commit comments

Comments
 (0)