Skip to content

Instantly share code, notes, and snippets.

View carsonRadtke's full-sized avatar

Carson Radtke carsonRadtke

View GitHub Profile
class TC:
def __init__(self, *types):
self.types = types
def __call__(self, func):
def f(*args):
match [*args]:
case self.types: return func(*args)
case _: raise TypeError("type mismatch")
return f
"""
$ python3 fxn_logger.py
foo(4)...16
foo(3, blah=None)...foo() got an unexpected keyword argument 'blah'
foo()...foo() missing 1 required positional argument: 'x'
Traceback (most recent call last):
File "fxn_logger.py", line 33, in <module>
foo()
File "fxn_logger.py", line 19, in __call__
raise e
@carsonRadtke
carsonRadtke / lobf_net.py
Created January 19, 2024 16:23
line of best fit learning model + automatic differentiation
#!/usr/bin/env python3
from random import random, randint
import operator
class Expr:
__slots__ = ["op", "x1", "x2"]
def __init__(self, x1, op=None, x2=None):