Skip to content

Commit

Permalink
Merge pull request #140 from oscarbenjamin/pr_update
Browse files Browse the repository at this point in the history
Reformat due to black changes
  • Loading branch information
oscarbenjamin authored Mar 1, 2024
2 parents 74bc621 + 6d9ed4a commit 1db02ae
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 35 deletions.
1 change: 1 addition & 0 deletions benchmarks/test_differentiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SymPy's and SymEngine's symbolic differentiation.
"""

from typing import Callable, TypeVar

import pytest
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sphinx configuration."""

from datetime import datetime

project = "ProtoSym"
Expand Down
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Nox sessions."""

import shutil
import sys
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/protosym/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command-line interface."""

import sys


Expand Down
1 change: 1 addition & 0 deletions src/protosym/core/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module defines the :class:`AtomType` and :class:`Atom` types.
"""

from __future__ import annotations

from typing import TYPE_CHECKING as _TYPE_CHECKING
Expand Down
3 changes: 2 additions & 1 deletion src/protosym/core/differentiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
level code in the sym module wraps this to make a nicer pattern-matching style
interface for specifying differentiation rules.
"""

from __future__ import annotations

from dataclasses import dataclass, field
Expand Down Expand Up @@ -143,4 +144,4 @@ def chain_rule_forward(
rust_protosym = None

if rust_protosym is not None: # pragma: no cover
from rust_protosym import DiffProperties, diff_forward # type:ignore # noqa
from rust_protosym import DiffProperties, diff_forward # type:ignore
1 change: 1 addition & 0 deletions src/protosym/core/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Define the core evaluation code."""

from __future__ import annotations

from typing import TYPE_CHECKING as _TYPE_CHECKING
Expand Down
45 changes: 24 additions & 21 deletions src/protosym/core/sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
build a nicer syntax over the lower-level classes that can be inherited for use
by user-facing classes that derive from :class:`Sym`.
"""

from __future__ import annotations

from typing import Any, Callable, Generic, Sequence, TypeVar, overload
Expand Down Expand Up @@ -489,51 +490,53 @@ def __init__(self, name: str):
def __setitem__(
self,
pattern: T_sym,
call: WildCall[T_sym, PyOp1[T_val]]
| WildCall[T_sym, PyOp2[T_val]]
| WildCall[T_sym, PyOpN[T_val]],
) -> None:
...
call: (
WildCall[T_sym, PyOp1[T_val]]
| WildCall[T_sym, PyOp2[T_val]]
| WildCall[T_sym, PyOpN[T_val]]
),
) -> None: ...

# e.g. eval_f64[Integer[a]] = f64_from_int
@overload
def __setitem__(
self,
pattern: SymAtomValue[T_sym, S_val],
call: WildCall[T_sym, PyFunc1[S_val, T_val]],
) -> None:
...
) -> None: ...

# e.g. eval_repr[AtomRule[a]] = AtomFunc(repr)
@overload
def __setitem__(
self,
pattern: AtomRuleType[T_sym],
call: WildCall[T_sym, AtomFunc[T_val]],
) -> None:
...
) -> None: ...

# e.g. eval_repr[HeadRule(a, b)] = HeadOp(...)
@overload
def __setitem__(
self,
pattern: HeadRuleType[T_sym],
call: WildCall[T_sym, HeadOp[T_val]],
) -> None:
...
) -> None: ...

def __setitem__( # noqa [C901]
self,
pattern: T_sym
| SymAtomValue[T_sym, S_val]
| AtomRuleType[T_sym]
| HeadRuleType[T_sym],
call: WildCall[T_sym, PyOp1[T_val]]
| WildCall[T_sym, PyOp2[T_val]]
| WildCall[T_sym, PyOpN[T_val]]
| WildCall[T_sym, PyFunc1[S_val, T_val]]
| WildCall[T_sym, AtomFunc[T_val]]
| WildCall[T_sym, HeadOp[T_val]],
pattern: (
T_sym
| SymAtomValue[T_sym, S_val]
| AtomRuleType[T_sym]
| HeadRuleType[T_sym]
),
call: (
WildCall[T_sym, PyOp1[T_val]]
| WildCall[T_sym, PyOp2[T_val]]
| WildCall[T_sym, PyOpN[T_val]]
| WildCall[T_sym, PyFunc1[S_val, T_val]]
| WildCall[T_sym, AtomFunc[T_val]]
| WildCall[T_sym, HeadOp[T_val]]
),
) -> None:
"""Add an evaluation rule."""
if not isinstance(call, WildCall):
Expand Down
1 change: 1 addition & 0 deletions src/protosym/core/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module defines classes for representing expressions in top-down tree form.
"""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions src/protosym/simplecas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Demonstration of putting together a simple CAS."""

from __future__ import annotations

import protosym.simplecas.functions # noqa
Expand Down
1 change: 1 addition & 0 deletions src/protosym/simplecas/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exception types raised in simplecas."""

from protosym.core.exceptions import ProtoSymError


Expand Down
1 change: 1 addition & 0 deletions src/protosym/simplecas/expr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Expr class."""

from __future__ import annotations

from functools import reduce, wraps
Expand Down
1 change: 1 addition & 0 deletions src/protosym/simplecas/functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Basic functions and operations."""

import math

from protosym.core.sym import (
Expand Down
1 change: 1 addition & 0 deletions src/protosym/simplecas/lambdification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""lambdification with LLVM."""

from __future__ import annotations

import ctypes
Expand Down
1 change: 1 addition & 0 deletions src/protosym/simplecas/matrix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Simple Matrix class."""

from __future__ import annotations

from typing import TYPE_CHECKING as _TYPE_CHECKING
Expand Down
1 change: 1 addition & 0 deletions src/protosym/simplecas/sympy_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
These are defined in their own module so that SymPy will not imported if it is
not needed.
"""

from __future__ import annotations

from typing import Any
Expand Down
24 changes: 11 additions & 13 deletions tests/core/test_sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,17 @@ def __call__(self, *args: Expr) -> Expr:
return Expr(self.rep(*args_rep))


def _make_atoms() -> (
tuple[
SymAtomType[Expr, int],
SymAtomType[Expr, str],
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
]
):
def _make_atoms() -> tuple[
SymAtomType[Expr, int],
SymAtomType[Expr, str],
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
]:
"""Set up a Sym subclass and create some atoms etc."""
Integer = Expr.new_atom("Integer", int)
Function = Expr.new_atom("Function", str)
Expand Down
1 change: 1 addition & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test cases for the __main__ module."""

from protosym import __main__


Expand Down

0 comments on commit 1db02ae

Please sign in to comment.