Skip to content

Commit

Permalink
Dim math cache better, use same_base (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz authored Oct 12, 2023
1 parent dcd082b commit a73cace
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions returnn/tensor/_dim_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,7 @@ def __add__(self: Dim, other):
:rtype: Dim
"""
cache_key = ("add", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2011,7 +2011,7 @@ def __radd__(self: Dim, other):
:rtype: Dim
"""
cache_key = ("add_left", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2034,7 +2034,7 @@ def sub_right(self: Dim, other):
:rtype: Dim
"""
cache_key = ("sub", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2050,7 +2050,7 @@ def sub_left(self: Dim, other):
:rtype: Dim
"""
cache_key = ("sub_left", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2065,7 +2065,7 @@ def __mul__(self: Dim, other):
:rtype: Dim
"""
cache_key = ("mul", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2080,7 +2080,7 @@ def __rmul__(self: Dim, other):
:rtype: Dim
"""
cache_key = ("mul_left", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2095,7 +2095,7 @@ def __floordiv__(self: Dim, other):
:rtype: Dim
"""
cache_key = ("floordiv", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2117,7 +2117,7 @@ def div_left(self: Dim, other):
:rtype: Dim
"""
cache_key = ("truediv_left", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2132,7 +2132,7 @@ def div_right(self: Dim, other):
:rtype: Dim
"""
cache_key = ("truediv", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2147,7 +2147,7 @@ def ceildiv_left(self: Dim, other):
:rtype: Dim
"""
cache_key = ("ceildiv_left", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand All @@ -2162,7 +2162,7 @@ def ceildiv_right(self: Dim, other):
:rtype: Dim
"""
cache_key = ("ceildiv", other)
cache = self._make_extra().cache_dim_math
cache = self.get_same_base()._make_extra().cache_dim_math
if cache_key in cache:
return cache[cache_key]
term = _OpLinearTerm.from_dim(self)
Expand Down

0 comments on commit a73cace

Please sign in to comment.