Skip to content

Commit 6cc87b5

Browse files
authored
Merge pull request #145 from ngoldbaum/fix-exp2
Replace usages of math.exp2 on python older than 3.11
2 parents d276ede + ebfde8d commit 6cc87b5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

csp/math.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import numpy as np
3+
import sys
34
import typing
45
from functools import lru_cache
56

@@ -363,7 +364,10 @@ def comp(x: ts["T"]):
363364
log2 = define_unary_op("log2", lambda x: math.log2(x))
364365
log10 = define_unary_op("log10", lambda x: math.log10(x))
365366
exp = define_unary_op("exp", lambda x: math.exp(x))
366-
exp2 = define_unary_op("exp2", lambda x: math.exp2(x))
367+
if sys.version_info < (3, 11):
368+
exp2 = define_unary_op("exp2", lambda x: 2**x)
369+
else:
370+
exp2 = define_unary_op("exp2", lambda x: math.exp2)
367371
sqrt = define_unary_op("sqrt", lambda x: math.sqrt(x))
368372
erf = define_unary_op("erf", lambda x: math.erf(x))
369373
sin = define_unary_op("sin", lambda x: math.sin(x))

csp/tests/test_math.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_math_unary_ops(self):
122122
csp.log2: lambda x: math.log2(x),
123123
csp.log10: lambda x: math.log10(x),
124124
csp.exp: lambda x: math.exp(x),
125-
csp.exp2: lambda x: math.exp2(x),
125+
csp.exp2: lambda x: 2**x,
126126
csp.sin: lambda x: math.sin(x),
127127
csp.cos: lambda x: math.cos(x),
128128
csp.tan: lambda x: math.tan(x),

0 commit comments

Comments
 (0)