@@ -537,7 +537,7 @@ def getDerivationMatrix(self, *args, **kwargs):
537537 return self .getDerivativeMatrix (* args , ** kwargs )
538538
539539
540- def getSparseInterpolationMatrix (inPoints , outPoints , order ):
540+ def getSparseInterpolationMatrix (inPoints , outPoints , order , gridPeriod = - 1 ):
541541 """
542542 Get a sparse interpolation matrix from `inPoints` to `outPoints` of order
543543 `order` using barycentric Lagrange interpolation.
@@ -553,6 +553,8 @@ def getSparseInterpolationMatrix(inPoints, outPoints, order):
553553 The points you want to interpolate to
554554 order : int
555555 Order of the interpolation
556+ grid_period : float
557+ Period of the grid. Negative values indicate non-periodic grids
556558
557559 Returns
558560 -------
@@ -568,10 +570,21 @@ def getSparseInterpolationMatrix(inPoints, outPoints, order):
568570 lastClosestPoints = None
569571
570572 for i in range (len (outPoints )):
571- closestPointsIdx = np .sort (np .argsort (np .abs (inPoints - outPoints [i ]))[:order ])
572- closestPoints = inPoints [closestPointsIdx ] - outPoints [i ]
573+ if gridPeriod > 0 :
574+ pathL = (inPoints - gridPeriod - outPoints [i ] % gridPeriod )
575+ pathR = (inPoints + gridPeriod - outPoints [i ] % gridPeriod )
576+ pathC = (inPoints - outPoints [i ] % gridPeriod )
577+ path = np .append (np .append (pathR , pathL ), pathC )
578+ dist = np .abs (path )
579+ _closestPointsIdx = np .sort (np .argsort (dist )[:order ])
580+ closestPointsIdx = _closestPointsIdx % len (inPoints )
581+ closestPoints , sorting = np .unique (path [_closestPointsIdx ], return_index = True )
582+ closestPointsIdx = closestPointsIdx [sorting ]
583+ else :
584+ closestPointsIdx = np .sort (np .argsort (np .abs (inPoints - outPoints [i ]))[:order ])
585+ closestPoints = inPoints [closestPointsIdx ] - outPoints [i ]
573586
574- if lastClosestPoints is not None and np .allclose (closestPoints , lastClosestPoints ):
587+ if lastClosestPoints is not None and len ( closestPoints ) == len ( lastClosestPoints ) and np .allclose (closestPoints , lastClosestPoints ):
575588 interpolationLine = lastInterpolationLine
576589 else :
577590 interpolator = LagrangeApproximation (points = closestPoints )
0 commit comments