mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-20 05:43:42 +08:00
0b2c431d3a
version: sunnypilot v2026.003.000 (dev)
date: 2026-09-14T15:43:39
master commit: a5f44653d7
20 lines
661 B
Python
20 lines
661 B
Python
# opt opinionatedly transforms an ast into an optimized ast using either heuristics or beam search
|
|
from __future__ import annotations
|
|
from enum import Enum, auto
|
|
from dataclasses import dataclass
|
|
|
|
class OptOps(Enum):
|
|
TC = auto(); SPLIT = auto(); PADTO = auto(); SWAP = auto() # noqa: E702
|
|
def __lt__(self, x:OptOps): return self.value < x.value
|
|
|
|
@dataclass(frozen=True, order=True)
|
|
class Opt:
|
|
op: OptOps
|
|
axis: int|None = None
|
|
arg: int|tuple|None = None
|
|
def __repr__(self): return f"Opt(op={self.op}, axis={self.axis}, arg={self.arg})"
|
|
|
|
class KernelOptError(Exception): pass
|
|
def check(cond:bool, msg:str=""):
|
|
if not cond: raise KernelOptError(msg)
|