Skip to content

Commit

Permalink
Merge pull request #712 from nerai/sympy_log2
Browse files Browse the repository at this point in the history
Let sympy use log2(x) instead of log(x)/log(2)
  • Loading branch information
MilesCranmer authored Dec 6, 2024
2 parents 5569ef0 + 450e674 commit 4ed3570
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pysr/export_jax.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np # noqa: F401
import sympy # type: ignore
from sympy.codegen.cfunctions import log2, log10 # type: ignore

# Special since need to reduce arguments.
MUL = 0
Expand All @@ -15,6 +16,8 @@
sympy.ceiling: "jnp.ceil",
sympy.floor: "jnp.floor",
sympy.log: "jnp.log",
log2: "jnp.log2",
log10: "jnp.log10",
sympy.exp: "jnp.exp",
sympy.sqrt: "jnp.sqrt",
sympy.cos: "jnp.cos",
Expand Down
5 changes: 3 additions & 2 deletions pysr/export_sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sympy # type: ignore
from sympy import sympify
from sympy.codegen.cfunctions import log2, log10 # type: ignore

from .utils import ArrayLike

Expand Down Expand Up @@ -39,8 +40,8 @@
"erf": sympy.erf,
"erfc": sympy.erfc,
"log": lambda x: sympy.log(x),
"log10": lambda x: sympy.log(x, 10),
"log2": lambda x: sympy.log(x, 2),
"log10": lambda x: log10(x),
"log2": lambda x: log2(x),
"log1p": lambda x: sympy.log(x + 1),
"log_abs": lambda x: sympy.log(abs(x)),
"log10_abs": lambda x: sympy.log(abs(x), 10),
Expand Down
3 changes: 3 additions & 0 deletions pysr/export_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np # noqa: F401
import sympy # type: ignore
from sympy.codegen.cfunctions import log2, log10 # type: ignore


def _reduce(fn):
Expand Down Expand Up @@ -41,6 +42,8 @@ def _initialize_torch():
sympy.ceiling: torch.ceil,
sympy.floor: torch.floor,
sympy.log: torch.log,
log2: torch.log2,
log10: torch.log10,
sympy.exp: torch.exp,
sympy.sqrt: torch.sqrt,
sympy.cos: torch.cos,
Expand Down

0 comments on commit 4ed3570

Please sign in to comment.