@@ -321,25 +321,23 @@ def __init__(self, base, linthresh):
321321 self .base = base
322322 self .linthresh = abs (linthresh )
323323 self ._log_base = np .log (base )
324- self ._logb_linthresh = np .log (linthresh ) / self ._log_base
325- self ._logb_minlog = np .floor (self ._logb_linthresh - 1e-10 )
326- self ._linadjust = np .abs ((np .log (linthresh ) - self ._logb_minlog ) /
327- linthresh )
324+ logb_linthresh = np .log (linthresh ) / self ._log_base
325+ self ._linadjust = 1.0 - logb_linthresh
326+ self ._linscale = 1.0 / linthresh
328327
329328 def transform (self , a ):
330329 a = np .asarray (a )
331330 sign = np .sign (a )
332331 masked = ma .masked_inside (a , - self .linthresh , self .linthresh , copy = False )
333- log = sign * (ma .log (np .abs (masked )) / self ._log_base - self ._logb_minlog )
334332 if masked .mask .any ():
335- return np .asarray (ma .where (masked .mask ,
336- a * self ._linadjust ,
337- log ))
333+ log = sign * (ma .log (np .abs (masked )) / self ._log_base + self ._linadjust )
334+ return np .asarray (ma .where (masked .mask , a * self ._linscale , log ))
338335 else :
339- return np .asarray ( log )
336+ return sign * ( np .log ( np . abs ( a )) / self . _log_base + self . _linadjust )
340337
341338 def inverted (self ):
342- return SymmetricalLogScale .InvertedSymmetricalLogTransform (self .base , self .linthresh )
339+ return SymmetricalLogScale .InvertedSymmetricalLogTransform (
340+ self .base , self .linthresh )
343341
344342 class InvertedSymmetricalLogTransform (Transform ):
345343 input_dims = 1
@@ -350,20 +348,22 @@ def __init__(self, base, linthresh):
350348 Transform .__init__ (self )
351349 self .base = base
352350 self .linthresh = linthresh
353- self . _log_base = np .log (base )
354- self . _log_linthresh = np .log (linthresh ) / self . _log_base
355- self ._linadjust = linthresh / ( np . log ( linthresh ) / self . _log_base )
351+ log_base = np .log (base )
352+ logb_linthresh = np .log (linthresh ) / log_base
353+ self ._linadjust = 1.0 - logb_linthresh
356354
357355 def transform (self , a ):
358356 a = np .asarray (a )
359- return np .where (a <= self ._log_linthresh ,
360- np .where (a >= - self ._log_linthresh ,
361- a * self ._linadjust ,
362- - (np .power (self .base , - a ))),
363- np .power (self .base , a ))
357+ sign = np .sign (a )
358+ masked = ma .masked_inside (a , - 1.0 , 1.0 , copy = False )
359+ result = np .where ((a >= - 1.0 ) & (a <= 1.0 ),
360+ a * self .linthresh ,
361+ sign * np .power (self .base , np .abs (a - sign * self ._linadjust )))
362+ return result
364363
365364 def inverted (self ):
366- return SymmetricalLogScale .SymmetricalLogTransform (self .base )
365+ return SymmetricalLogScale .SymmetricalLogTransform (
366+ self .base , self .linthresh )
367367
368368 def __init__ (self , axis , ** kwargs ):
369369 """
@@ -393,6 +393,9 @@ def __init__(self, axis, **kwargs):
393393
394394 self ._transform = self .SymmetricalLogTransform (base , linthresh )
395395
396+ assert base > 0.0
397+ assert linthresh > 0.0
398+
396399 self .base = base
397400 self .linthresh = linthresh
398401 self .subs = subs
0 commit comments