GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fasterPython/fasterPython/fasterPython.py at main · tomtyiu/fasterPython

Expand file tree

/

fasterPython.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
84 lines (69 loc) · 1.54 KB
/

fasterPython.py

Copy path

File metadata and controls

84 lines (69 loc) · 1.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# math fast-path bindings
from math import (
sqrt,
ceil,
floor,
factorial,
log,
exp,
sin,
pi,
e,
tau,
inf,
nan,
)
# ------------------
# Scalar math funcs
# ------------------
def fast_sqrt(x): return sqrt(x)
def fast_ceil(x): return ceil(x)
def fast_floor(x): return floor(x)
def fast_factorial(x): return factorial(x)
def fast_log(x, base=None): return log(x) if base is None else log(x, base)
def fast_exp(x): return exp(x)
def fast_sin(x): return sin(x)
# ------------------
# Math constants
# ------------------
FAST_PI = pi
FAST_E = e
FAST_TAU = tau
FAST_INF = inf
FAST_NAN = nan
# ------------------
# Cached recursion
# ------------------
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n: int) -> int:
if n < 2:
return n
return fib(n - 1) + fib(n - 2)
# ------------------
# Fast pure-Python sum
# ------------------
def sum_fast(iterable):
total = 0
for v in iterable:
total += v
return total
# ------------------
# Avoid repeated lookups
# ------------------
def compute_squares(nums):
result = []
append = result.append # local binding
for n in nums:
append(n * n)
return result
# ------------------
# NumPy fast path (optional)
# ------------------
try:
import numpy as _np
def sum_numpy(nums):
return _np.sum(_np.asarray(nums))
except ImportError:
def sum_numpy(nums):
raise RuntimeError("NumPy is not installed")
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.