Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- parrot/lib/python3.10/site-packages/fontTools/pens/momentsPen.cpython-310-x86_64-linux-gnu.so +3 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_chebyshev.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_hermite.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_hermite_e.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_laguerre.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_legendre.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_polynomial.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_polyutils.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/test_chebyshev.py +619 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/test_hermite.py +555 -0
- parrot/lib/python3.10/site-packages/numpy/polynomial/tests/test_laguerre.py +537 -0
- parrot/lib/python3.10/site-packages/numpy/random/__init__.pxd +14 -0
- parrot/lib/python3.10/site-packages/numpy/random/__init__.pyi +71 -0
- parrot/lib/python3.10/site-packages/numpy/random/_bounded_integers.pxd +29 -0
- parrot/lib/python3.10/site-packages/numpy/random/_generator.pyi +784 -0
- parrot/lib/python3.10/site-packages/numpy/random/bit_generator.pxd +35 -0
- parrot/lib/python3.10/site-packages/numpy/random/bit_generator.pyi +124 -0
- parrot/lib/python3.10/site-packages/numpy/random/mtrand.pyi +681 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/__pycache__/conftest.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/__pycache__/setup.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_promise_list.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_spec.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/utils.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/__init__.py +90 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/cmdline.py +568 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/console.py +74 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/filter.py +74 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/filters/__init__.py +350 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/filters/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatter.py +95 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__init__.py +153 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/_mapping.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/bbcode.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/html.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/img.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/irc.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/latex.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/other.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/rtf.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/svg.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/terminal.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/terminal256.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/_mapping.py +85 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/bbcode.py +109 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/html.py +851 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/img.py +600 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/irc.py +182 -0
.gitattributes
CHANGED
|
@@ -1426,3 +1426,4 @@ vllm/lib/python3.10/site-packages/numpy.libs/libquadmath-96973f99.so.0.0.0 filte
|
|
| 1426 |
vllm/lib/python3.10/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so filter=lfs diff=lfs merge=lfs -text
|
| 1427 |
vllm/lib/python3.10/site-packages/wandb/bin/gpu_stats filter=lfs diff=lfs merge=lfs -text
|
| 1428 |
parrot/lib/python3.10/site-packages/pyparsing/__pycache__/core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 1426 |
vllm/lib/python3.10/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so filter=lfs diff=lfs merge=lfs -text
|
| 1427 |
vllm/lib/python3.10/site-packages/wandb/bin/gpu_stats filter=lfs diff=lfs merge=lfs -text
|
| 1428 |
parrot/lib/python3.10/site-packages/pyparsing/__pycache__/core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 1429 |
+
parrot/lib/python3.10/site-packages/fontTools/pens/momentsPen.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
parrot/lib/python3.10/site-packages/fontTools/pens/momentsPen.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e740cbdcb1df5e62b35e31b0a93dc3b8d9626ad7cbf195d8d2e5c7125c508c61
|
| 3 |
+
size 1077352
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_chebyshev.cpython-310.pyc
ADDED
|
Binary file (20.1 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_hermite.cpython-310.pyc
ADDED
|
Binary file (17.5 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_hermite_e.cpython-310.pyc
ADDED
|
Binary file (17.6 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_laguerre.cpython-310.pyc
ADDED
|
Binary file (16.9 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_legendre.cpython-310.pyc
ADDED
|
Binary file (18.2 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_polynomial.cpython-310.pyc
ADDED
|
Binary file (20.2 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/__pycache__/test_polyutils.cpython-310.pyc
ADDED
|
Binary file (4.12 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/test_chebyshev.py
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for chebyshev module.
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
from functools import reduce
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
import numpy.polynomial.chebyshev as cheb
|
| 8 |
+
from numpy.polynomial.polynomial import polyval
|
| 9 |
+
from numpy.testing import (
|
| 10 |
+
assert_almost_equal, assert_raises, assert_equal, assert_,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def trim(x):
|
| 15 |
+
return cheb.chebtrim(x, tol=1e-6)
|
| 16 |
+
|
| 17 |
+
T0 = [1]
|
| 18 |
+
T1 = [0, 1]
|
| 19 |
+
T2 = [-1, 0, 2]
|
| 20 |
+
T3 = [0, -3, 0, 4]
|
| 21 |
+
T4 = [1, 0, -8, 0, 8]
|
| 22 |
+
T5 = [0, 5, 0, -20, 0, 16]
|
| 23 |
+
T6 = [-1, 0, 18, 0, -48, 0, 32]
|
| 24 |
+
T7 = [0, -7, 0, 56, 0, -112, 0, 64]
|
| 25 |
+
T8 = [1, 0, -32, 0, 160, 0, -256, 0, 128]
|
| 26 |
+
T9 = [0, 9, 0, -120, 0, 432, 0, -576, 0, 256]
|
| 27 |
+
|
| 28 |
+
Tlist = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class TestPrivate:
|
| 32 |
+
|
| 33 |
+
def test__cseries_to_zseries(self):
|
| 34 |
+
for i in range(5):
|
| 35 |
+
inp = np.array([2] + [1]*i, np.double)
|
| 36 |
+
tgt = np.array([.5]*i + [2] + [.5]*i, np.double)
|
| 37 |
+
res = cheb._cseries_to_zseries(inp)
|
| 38 |
+
assert_equal(res, tgt)
|
| 39 |
+
|
| 40 |
+
def test__zseries_to_cseries(self):
|
| 41 |
+
for i in range(5):
|
| 42 |
+
inp = np.array([.5]*i + [2] + [.5]*i, np.double)
|
| 43 |
+
tgt = np.array([2] + [1]*i, np.double)
|
| 44 |
+
res = cheb._zseries_to_cseries(inp)
|
| 45 |
+
assert_equal(res, tgt)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class TestConstants:
|
| 49 |
+
|
| 50 |
+
def test_chebdomain(self):
|
| 51 |
+
assert_equal(cheb.chebdomain, [-1, 1])
|
| 52 |
+
|
| 53 |
+
def test_chebzero(self):
|
| 54 |
+
assert_equal(cheb.chebzero, [0])
|
| 55 |
+
|
| 56 |
+
def test_chebone(self):
|
| 57 |
+
assert_equal(cheb.chebone, [1])
|
| 58 |
+
|
| 59 |
+
def test_chebx(self):
|
| 60 |
+
assert_equal(cheb.chebx, [0, 1])
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class TestArithmetic:
|
| 64 |
+
|
| 65 |
+
def test_chebadd(self):
|
| 66 |
+
for i in range(5):
|
| 67 |
+
for j in range(5):
|
| 68 |
+
msg = f"At i={i}, j={j}"
|
| 69 |
+
tgt = np.zeros(max(i, j) + 1)
|
| 70 |
+
tgt[i] += 1
|
| 71 |
+
tgt[j] += 1
|
| 72 |
+
res = cheb.chebadd([0]*i + [1], [0]*j + [1])
|
| 73 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 74 |
+
|
| 75 |
+
def test_chebsub(self):
|
| 76 |
+
for i in range(5):
|
| 77 |
+
for j in range(5):
|
| 78 |
+
msg = f"At i={i}, j={j}"
|
| 79 |
+
tgt = np.zeros(max(i, j) + 1)
|
| 80 |
+
tgt[i] += 1
|
| 81 |
+
tgt[j] -= 1
|
| 82 |
+
res = cheb.chebsub([0]*i + [1], [0]*j + [1])
|
| 83 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 84 |
+
|
| 85 |
+
def test_chebmulx(self):
|
| 86 |
+
assert_equal(cheb.chebmulx([0]), [0])
|
| 87 |
+
assert_equal(cheb.chebmulx([1]), [0, 1])
|
| 88 |
+
for i in range(1, 5):
|
| 89 |
+
ser = [0]*i + [1]
|
| 90 |
+
tgt = [0]*(i - 1) + [.5, 0, .5]
|
| 91 |
+
assert_equal(cheb.chebmulx(ser), tgt)
|
| 92 |
+
|
| 93 |
+
def test_chebmul(self):
|
| 94 |
+
for i in range(5):
|
| 95 |
+
for j in range(5):
|
| 96 |
+
msg = f"At i={i}, j={j}"
|
| 97 |
+
tgt = np.zeros(i + j + 1)
|
| 98 |
+
tgt[i + j] += .5
|
| 99 |
+
tgt[abs(i - j)] += .5
|
| 100 |
+
res = cheb.chebmul([0]*i + [1], [0]*j + [1])
|
| 101 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 102 |
+
|
| 103 |
+
def test_chebdiv(self):
|
| 104 |
+
for i in range(5):
|
| 105 |
+
for j in range(5):
|
| 106 |
+
msg = f"At i={i}, j={j}"
|
| 107 |
+
ci = [0]*i + [1]
|
| 108 |
+
cj = [0]*j + [1]
|
| 109 |
+
tgt = cheb.chebadd(ci, cj)
|
| 110 |
+
quo, rem = cheb.chebdiv(tgt, ci)
|
| 111 |
+
res = cheb.chebadd(cheb.chebmul(quo, ci), rem)
|
| 112 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 113 |
+
|
| 114 |
+
def test_chebpow(self):
|
| 115 |
+
for i in range(5):
|
| 116 |
+
for j in range(5):
|
| 117 |
+
msg = f"At i={i}, j={j}"
|
| 118 |
+
c = np.arange(i + 1)
|
| 119 |
+
tgt = reduce(cheb.chebmul, [c]*j, np.array([1]))
|
| 120 |
+
res = cheb.chebpow(c, j)
|
| 121 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class TestEvaluation:
|
| 125 |
+
# coefficients of 1 + 2*x + 3*x**2
|
| 126 |
+
c1d = np.array([2.5, 2., 1.5])
|
| 127 |
+
c2d = np.einsum('i,j->ij', c1d, c1d)
|
| 128 |
+
c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)
|
| 129 |
+
|
| 130 |
+
# some random values in [-1, 1)
|
| 131 |
+
x = np.random.random((3, 5))*2 - 1
|
| 132 |
+
y = polyval(x, [1., 2., 3.])
|
| 133 |
+
|
| 134 |
+
def test_chebval(self):
|
| 135 |
+
#check empty input
|
| 136 |
+
assert_equal(cheb.chebval([], [1]).size, 0)
|
| 137 |
+
|
| 138 |
+
#check normal input)
|
| 139 |
+
x = np.linspace(-1, 1)
|
| 140 |
+
y = [polyval(x, c) for c in Tlist]
|
| 141 |
+
for i in range(10):
|
| 142 |
+
msg = f"At i={i}"
|
| 143 |
+
tgt = y[i]
|
| 144 |
+
res = cheb.chebval(x, [0]*i + [1])
|
| 145 |
+
assert_almost_equal(res, tgt, err_msg=msg)
|
| 146 |
+
|
| 147 |
+
#check that shape is preserved
|
| 148 |
+
for i in range(3):
|
| 149 |
+
dims = [2]*i
|
| 150 |
+
x = np.zeros(dims)
|
| 151 |
+
assert_equal(cheb.chebval(x, [1]).shape, dims)
|
| 152 |
+
assert_equal(cheb.chebval(x, [1, 0]).shape, dims)
|
| 153 |
+
assert_equal(cheb.chebval(x, [1, 0, 0]).shape, dims)
|
| 154 |
+
|
| 155 |
+
def test_chebval2d(self):
|
| 156 |
+
x1, x2, x3 = self.x
|
| 157 |
+
y1, y2, y3 = self.y
|
| 158 |
+
|
| 159 |
+
#test exceptions
|
| 160 |
+
assert_raises(ValueError, cheb.chebval2d, x1, x2[:2], self.c2d)
|
| 161 |
+
|
| 162 |
+
#test values
|
| 163 |
+
tgt = y1*y2
|
| 164 |
+
res = cheb.chebval2d(x1, x2, self.c2d)
|
| 165 |
+
assert_almost_equal(res, tgt)
|
| 166 |
+
|
| 167 |
+
#test shape
|
| 168 |
+
z = np.ones((2, 3))
|
| 169 |
+
res = cheb.chebval2d(z, z, self.c2d)
|
| 170 |
+
assert_(res.shape == (2, 3))
|
| 171 |
+
|
| 172 |
+
def test_chebval3d(self):
|
| 173 |
+
x1, x2, x3 = self.x
|
| 174 |
+
y1, y2, y3 = self.y
|
| 175 |
+
|
| 176 |
+
#test exceptions
|
| 177 |
+
assert_raises(ValueError, cheb.chebval3d, x1, x2, x3[:2], self.c3d)
|
| 178 |
+
|
| 179 |
+
#test values
|
| 180 |
+
tgt = y1*y2*y3
|
| 181 |
+
res = cheb.chebval3d(x1, x2, x3, self.c3d)
|
| 182 |
+
assert_almost_equal(res, tgt)
|
| 183 |
+
|
| 184 |
+
#test shape
|
| 185 |
+
z = np.ones((2, 3))
|
| 186 |
+
res = cheb.chebval3d(z, z, z, self.c3d)
|
| 187 |
+
assert_(res.shape == (2, 3))
|
| 188 |
+
|
| 189 |
+
def test_chebgrid2d(self):
|
| 190 |
+
x1, x2, x3 = self.x
|
| 191 |
+
y1, y2, y3 = self.y
|
| 192 |
+
|
| 193 |
+
#test values
|
| 194 |
+
tgt = np.einsum('i,j->ij', y1, y2)
|
| 195 |
+
res = cheb.chebgrid2d(x1, x2, self.c2d)
|
| 196 |
+
assert_almost_equal(res, tgt)
|
| 197 |
+
|
| 198 |
+
#test shape
|
| 199 |
+
z = np.ones((2, 3))
|
| 200 |
+
res = cheb.chebgrid2d(z, z, self.c2d)
|
| 201 |
+
assert_(res.shape == (2, 3)*2)
|
| 202 |
+
|
| 203 |
+
def test_chebgrid3d(self):
|
| 204 |
+
x1, x2, x3 = self.x
|
| 205 |
+
y1, y2, y3 = self.y
|
| 206 |
+
|
| 207 |
+
#test values
|
| 208 |
+
tgt = np.einsum('i,j,k->ijk', y1, y2, y3)
|
| 209 |
+
res = cheb.chebgrid3d(x1, x2, x3, self.c3d)
|
| 210 |
+
assert_almost_equal(res, tgt)
|
| 211 |
+
|
| 212 |
+
#test shape
|
| 213 |
+
z = np.ones((2, 3))
|
| 214 |
+
res = cheb.chebgrid3d(z, z, z, self.c3d)
|
| 215 |
+
assert_(res.shape == (2, 3)*3)
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
class TestIntegral:
|
| 219 |
+
|
| 220 |
+
def test_chebint(self):
|
| 221 |
+
# check exceptions
|
| 222 |
+
assert_raises(TypeError, cheb.chebint, [0], .5)
|
| 223 |
+
assert_raises(ValueError, cheb.chebint, [0], -1)
|
| 224 |
+
assert_raises(ValueError, cheb.chebint, [0], 1, [0, 0])
|
| 225 |
+
assert_raises(ValueError, cheb.chebint, [0], lbnd=[0])
|
| 226 |
+
assert_raises(ValueError, cheb.chebint, [0], scl=[0])
|
| 227 |
+
assert_raises(TypeError, cheb.chebint, [0], axis=.5)
|
| 228 |
+
|
| 229 |
+
# test integration of zero polynomial
|
| 230 |
+
for i in range(2, 5):
|
| 231 |
+
k = [0]*(i - 2) + [1]
|
| 232 |
+
res = cheb.chebint([0], m=i, k=k)
|
| 233 |
+
assert_almost_equal(res, [0, 1])
|
| 234 |
+
|
| 235 |
+
# check single integration with integration constant
|
| 236 |
+
for i in range(5):
|
| 237 |
+
scl = i + 1
|
| 238 |
+
pol = [0]*i + [1]
|
| 239 |
+
tgt = [i] + [0]*i + [1/scl]
|
| 240 |
+
chebpol = cheb.poly2cheb(pol)
|
| 241 |
+
chebint = cheb.chebint(chebpol, m=1, k=[i])
|
| 242 |
+
res = cheb.cheb2poly(chebint)
|
| 243 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 244 |
+
|
| 245 |
+
# check single integration with integration constant and lbnd
|
| 246 |
+
for i in range(5):
|
| 247 |
+
scl = i + 1
|
| 248 |
+
pol = [0]*i + [1]
|
| 249 |
+
chebpol = cheb.poly2cheb(pol)
|
| 250 |
+
chebint = cheb.chebint(chebpol, m=1, k=[i], lbnd=-1)
|
| 251 |
+
assert_almost_equal(cheb.chebval(-1, chebint), i)
|
| 252 |
+
|
| 253 |
+
# check single integration with integration constant and scaling
|
| 254 |
+
for i in range(5):
|
| 255 |
+
scl = i + 1
|
| 256 |
+
pol = [0]*i + [1]
|
| 257 |
+
tgt = [i] + [0]*i + [2/scl]
|
| 258 |
+
chebpol = cheb.poly2cheb(pol)
|
| 259 |
+
chebint = cheb.chebint(chebpol, m=1, k=[i], scl=2)
|
| 260 |
+
res = cheb.cheb2poly(chebint)
|
| 261 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 262 |
+
|
| 263 |
+
# check multiple integrations with default k
|
| 264 |
+
for i in range(5):
|
| 265 |
+
for j in range(2, 5):
|
| 266 |
+
pol = [0]*i + [1]
|
| 267 |
+
tgt = pol[:]
|
| 268 |
+
for k in range(j):
|
| 269 |
+
tgt = cheb.chebint(tgt, m=1)
|
| 270 |
+
res = cheb.chebint(pol, m=j)
|
| 271 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 272 |
+
|
| 273 |
+
# check multiple integrations with defined k
|
| 274 |
+
for i in range(5):
|
| 275 |
+
for j in range(2, 5):
|
| 276 |
+
pol = [0]*i + [1]
|
| 277 |
+
tgt = pol[:]
|
| 278 |
+
for k in range(j):
|
| 279 |
+
tgt = cheb.chebint(tgt, m=1, k=[k])
|
| 280 |
+
res = cheb.chebint(pol, m=j, k=list(range(j)))
|
| 281 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 282 |
+
|
| 283 |
+
# check multiple integrations with lbnd
|
| 284 |
+
for i in range(5):
|
| 285 |
+
for j in range(2, 5):
|
| 286 |
+
pol = [0]*i + [1]
|
| 287 |
+
tgt = pol[:]
|
| 288 |
+
for k in range(j):
|
| 289 |
+
tgt = cheb.chebint(tgt, m=1, k=[k], lbnd=-1)
|
| 290 |
+
res = cheb.chebint(pol, m=j, k=list(range(j)), lbnd=-1)
|
| 291 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 292 |
+
|
| 293 |
+
# check multiple integrations with scaling
|
| 294 |
+
for i in range(5):
|
| 295 |
+
for j in range(2, 5):
|
| 296 |
+
pol = [0]*i + [1]
|
| 297 |
+
tgt = pol[:]
|
| 298 |
+
for k in range(j):
|
| 299 |
+
tgt = cheb.chebint(tgt, m=1, k=[k], scl=2)
|
| 300 |
+
res = cheb.chebint(pol, m=j, k=list(range(j)), scl=2)
|
| 301 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 302 |
+
|
| 303 |
+
def test_chebint_axis(self):
|
| 304 |
+
# check that axis keyword works
|
| 305 |
+
c2d = np.random.random((3, 4))
|
| 306 |
+
|
| 307 |
+
tgt = np.vstack([cheb.chebint(c) for c in c2d.T]).T
|
| 308 |
+
res = cheb.chebint(c2d, axis=0)
|
| 309 |
+
assert_almost_equal(res, tgt)
|
| 310 |
+
|
| 311 |
+
tgt = np.vstack([cheb.chebint(c) for c in c2d])
|
| 312 |
+
res = cheb.chebint(c2d, axis=1)
|
| 313 |
+
assert_almost_equal(res, tgt)
|
| 314 |
+
|
| 315 |
+
tgt = np.vstack([cheb.chebint(c, k=3) for c in c2d])
|
| 316 |
+
res = cheb.chebint(c2d, k=3, axis=1)
|
| 317 |
+
assert_almost_equal(res, tgt)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
class TestDerivative:
|
| 321 |
+
|
| 322 |
+
def test_chebder(self):
|
| 323 |
+
# check exceptions
|
| 324 |
+
assert_raises(TypeError, cheb.chebder, [0], .5)
|
| 325 |
+
assert_raises(ValueError, cheb.chebder, [0], -1)
|
| 326 |
+
|
| 327 |
+
# check that zeroth derivative does nothing
|
| 328 |
+
for i in range(5):
|
| 329 |
+
tgt = [0]*i + [1]
|
| 330 |
+
res = cheb.chebder(tgt, m=0)
|
| 331 |
+
assert_equal(trim(res), trim(tgt))
|
| 332 |
+
|
| 333 |
+
# check that derivation is the inverse of integration
|
| 334 |
+
for i in range(5):
|
| 335 |
+
for j in range(2, 5):
|
| 336 |
+
tgt = [0]*i + [1]
|
| 337 |
+
res = cheb.chebder(cheb.chebint(tgt, m=j), m=j)
|
| 338 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 339 |
+
|
| 340 |
+
# check derivation with scaling
|
| 341 |
+
for i in range(5):
|
| 342 |
+
for j in range(2, 5):
|
| 343 |
+
tgt = [0]*i + [1]
|
| 344 |
+
res = cheb.chebder(cheb.chebint(tgt, m=j, scl=2), m=j, scl=.5)
|
| 345 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 346 |
+
|
| 347 |
+
def test_chebder_axis(self):
|
| 348 |
+
# check that axis keyword works
|
| 349 |
+
c2d = np.random.random((3, 4))
|
| 350 |
+
|
| 351 |
+
tgt = np.vstack([cheb.chebder(c) for c in c2d.T]).T
|
| 352 |
+
res = cheb.chebder(c2d, axis=0)
|
| 353 |
+
assert_almost_equal(res, tgt)
|
| 354 |
+
|
| 355 |
+
tgt = np.vstack([cheb.chebder(c) for c in c2d])
|
| 356 |
+
res = cheb.chebder(c2d, axis=1)
|
| 357 |
+
assert_almost_equal(res, tgt)
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
class TestVander:
|
| 361 |
+
# some random values in [-1, 1)
|
| 362 |
+
x = np.random.random((3, 5))*2 - 1
|
| 363 |
+
|
| 364 |
+
def test_chebvander(self):
|
| 365 |
+
# check for 1d x
|
| 366 |
+
x = np.arange(3)
|
| 367 |
+
v = cheb.chebvander(x, 3)
|
| 368 |
+
assert_(v.shape == (3, 4))
|
| 369 |
+
for i in range(4):
|
| 370 |
+
coef = [0]*i + [1]
|
| 371 |
+
assert_almost_equal(v[..., i], cheb.chebval(x, coef))
|
| 372 |
+
|
| 373 |
+
# check for 2d x
|
| 374 |
+
x = np.array([[1, 2], [3, 4], [5, 6]])
|
| 375 |
+
v = cheb.chebvander(x, 3)
|
| 376 |
+
assert_(v.shape == (3, 2, 4))
|
| 377 |
+
for i in range(4):
|
| 378 |
+
coef = [0]*i + [1]
|
| 379 |
+
assert_almost_equal(v[..., i], cheb.chebval(x, coef))
|
| 380 |
+
|
| 381 |
+
def test_chebvander2d(self):
|
| 382 |
+
# also tests chebval2d for non-square coefficient array
|
| 383 |
+
x1, x2, x3 = self.x
|
| 384 |
+
c = np.random.random((2, 3))
|
| 385 |
+
van = cheb.chebvander2d(x1, x2, [1, 2])
|
| 386 |
+
tgt = cheb.chebval2d(x1, x2, c)
|
| 387 |
+
res = np.dot(van, c.flat)
|
| 388 |
+
assert_almost_equal(res, tgt)
|
| 389 |
+
|
| 390 |
+
# check shape
|
| 391 |
+
van = cheb.chebvander2d([x1], [x2], [1, 2])
|
| 392 |
+
assert_(van.shape == (1, 5, 6))
|
| 393 |
+
|
| 394 |
+
def test_chebvander3d(self):
|
| 395 |
+
# also tests chebval3d for non-square coefficient array
|
| 396 |
+
x1, x2, x3 = self.x
|
| 397 |
+
c = np.random.random((2, 3, 4))
|
| 398 |
+
van = cheb.chebvander3d(x1, x2, x3, [1, 2, 3])
|
| 399 |
+
tgt = cheb.chebval3d(x1, x2, x3, c)
|
| 400 |
+
res = np.dot(van, c.flat)
|
| 401 |
+
assert_almost_equal(res, tgt)
|
| 402 |
+
|
| 403 |
+
# check shape
|
| 404 |
+
van = cheb.chebvander3d([x1], [x2], [x3], [1, 2, 3])
|
| 405 |
+
assert_(van.shape == (1, 5, 24))
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
class TestFitting:
|
| 409 |
+
|
| 410 |
+
def test_chebfit(self):
|
| 411 |
+
def f(x):
|
| 412 |
+
return x*(x - 1)*(x - 2)
|
| 413 |
+
|
| 414 |
+
def f2(x):
|
| 415 |
+
return x**4 + x**2 + 1
|
| 416 |
+
|
| 417 |
+
# Test exceptions
|
| 418 |
+
assert_raises(ValueError, cheb.chebfit, [1], [1], -1)
|
| 419 |
+
assert_raises(TypeError, cheb.chebfit, [[1]], [1], 0)
|
| 420 |
+
assert_raises(TypeError, cheb.chebfit, [], [1], 0)
|
| 421 |
+
assert_raises(TypeError, cheb.chebfit, [1], [[[1]]], 0)
|
| 422 |
+
assert_raises(TypeError, cheb.chebfit, [1, 2], [1], 0)
|
| 423 |
+
assert_raises(TypeError, cheb.chebfit, [1], [1, 2], 0)
|
| 424 |
+
assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[[1]])
|
| 425 |
+
assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1, 1])
|
| 426 |
+
assert_raises(ValueError, cheb.chebfit, [1], [1], [-1,])
|
| 427 |
+
assert_raises(ValueError, cheb.chebfit, [1], [1], [2, -1, 6])
|
| 428 |
+
assert_raises(TypeError, cheb.chebfit, [1], [1], [])
|
| 429 |
+
|
| 430 |
+
# Test fit
|
| 431 |
+
x = np.linspace(0, 2)
|
| 432 |
+
y = f(x)
|
| 433 |
+
#
|
| 434 |
+
coef3 = cheb.chebfit(x, y, 3)
|
| 435 |
+
assert_equal(len(coef3), 4)
|
| 436 |
+
assert_almost_equal(cheb.chebval(x, coef3), y)
|
| 437 |
+
coef3 = cheb.chebfit(x, y, [0, 1, 2, 3])
|
| 438 |
+
assert_equal(len(coef3), 4)
|
| 439 |
+
assert_almost_equal(cheb.chebval(x, coef3), y)
|
| 440 |
+
#
|
| 441 |
+
coef4 = cheb.chebfit(x, y, 4)
|
| 442 |
+
assert_equal(len(coef4), 5)
|
| 443 |
+
assert_almost_equal(cheb.chebval(x, coef4), y)
|
| 444 |
+
coef4 = cheb.chebfit(x, y, [0, 1, 2, 3, 4])
|
| 445 |
+
assert_equal(len(coef4), 5)
|
| 446 |
+
assert_almost_equal(cheb.chebval(x, coef4), y)
|
| 447 |
+
# check things still work if deg is not in strict increasing
|
| 448 |
+
coef4 = cheb.chebfit(x, y, [2, 3, 4, 1, 0])
|
| 449 |
+
assert_equal(len(coef4), 5)
|
| 450 |
+
assert_almost_equal(cheb.chebval(x, coef4), y)
|
| 451 |
+
#
|
| 452 |
+
coef2d = cheb.chebfit(x, np.array([y, y]).T, 3)
|
| 453 |
+
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
|
| 454 |
+
coef2d = cheb.chebfit(x, np.array([y, y]).T, [0, 1, 2, 3])
|
| 455 |
+
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
|
| 456 |
+
# test weighting
|
| 457 |
+
w = np.zeros_like(x)
|
| 458 |
+
yw = y.copy()
|
| 459 |
+
w[1::2] = 1
|
| 460 |
+
y[0::2] = 0
|
| 461 |
+
wcoef3 = cheb.chebfit(x, yw, 3, w=w)
|
| 462 |
+
assert_almost_equal(wcoef3, coef3)
|
| 463 |
+
wcoef3 = cheb.chebfit(x, yw, [0, 1, 2, 3], w=w)
|
| 464 |
+
assert_almost_equal(wcoef3, coef3)
|
| 465 |
+
#
|
| 466 |
+
wcoef2d = cheb.chebfit(x, np.array([yw, yw]).T, 3, w=w)
|
| 467 |
+
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
|
| 468 |
+
wcoef2d = cheb.chebfit(x, np.array([yw, yw]).T, [0, 1, 2, 3], w=w)
|
| 469 |
+
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
|
| 470 |
+
# test scaling with complex values x points whose square
|
| 471 |
+
# is zero when summed.
|
| 472 |
+
x = [1, 1j, -1, -1j]
|
| 473 |
+
assert_almost_equal(cheb.chebfit(x, x, 1), [0, 1])
|
| 474 |
+
assert_almost_equal(cheb.chebfit(x, x, [0, 1]), [0, 1])
|
| 475 |
+
# test fitting only even polynomials
|
| 476 |
+
x = np.linspace(-1, 1)
|
| 477 |
+
y = f2(x)
|
| 478 |
+
coef1 = cheb.chebfit(x, y, 4)
|
| 479 |
+
assert_almost_equal(cheb.chebval(x, coef1), y)
|
| 480 |
+
coef2 = cheb.chebfit(x, y, [0, 2, 4])
|
| 481 |
+
assert_almost_equal(cheb.chebval(x, coef2), y)
|
| 482 |
+
assert_almost_equal(coef1, coef2)
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
class TestInterpolate:
|
| 486 |
+
|
| 487 |
+
def f(self, x):
|
| 488 |
+
return x * (x - 1) * (x - 2)
|
| 489 |
+
|
| 490 |
+
def test_raises(self):
|
| 491 |
+
assert_raises(ValueError, cheb.chebinterpolate, self.f, -1)
|
| 492 |
+
assert_raises(TypeError, cheb.chebinterpolate, self.f, 10.)
|
| 493 |
+
|
| 494 |
+
def test_dimensions(self):
|
| 495 |
+
for deg in range(1, 5):
|
| 496 |
+
assert_(cheb.chebinterpolate(self.f, deg).shape == (deg + 1,))
|
| 497 |
+
|
| 498 |
+
def test_approximation(self):
|
| 499 |
+
|
| 500 |
+
def powx(x, p):
|
| 501 |
+
return x**p
|
| 502 |
+
|
| 503 |
+
x = np.linspace(-1, 1, 10)
|
| 504 |
+
for deg in range(0, 10):
|
| 505 |
+
for p in range(0, deg + 1):
|
| 506 |
+
c = cheb.chebinterpolate(powx, deg, (p,))
|
| 507 |
+
assert_almost_equal(cheb.chebval(x, c), powx(x, p), decimal=12)
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class TestCompanion:
|
| 511 |
+
|
| 512 |
+
def test_raises(self):
|
| 513 |
+
assert_raises(ValueError, cheb.chebcompanion, [])
|
| 514 |
+
assert_raises(ValueError, cheb.chebcompanion, [1])
|
| 515 |
+
|
| 516 |
+
def test_dimensions(self):
|
| 517 |
+
for i in range(1, 5):
|
| 518 |
+
coef = [0]*i + [1]
|
| 519 |
+
assert_(cheb.chebcompanion(coef).shape == (i, i))
|
| 520 |
+
|
| 521 |
+
def test_linear_root(self):
|
| 522 |
+
assert_(cheb.chebcompanion([1, 2])[0, 0] == -.5)
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
class TestGauss:
|
| 526 |
+
|
| 527 |
+
def test_100(self):
|
| 528 |
+
x, w = cheb.chebgauss(100)
|
| 529 |
+
|
| 530 |
+
# test orthogonality. Note that the results need to be normalized,
|
| 531 |
+
# otherwise the huge values that can arise from fast growing
|
| 532 |
+
# functions like Laguerre can be very confusing.
|
| 533 |
+
v = cheb.chebvander(x, 99)
|
| 534 |
+
vv = np.dot(v.T * w, v)
|
| 535 |
+
vd = 1/np.sqrt(vv.diagonal())
|
| 536 |
+
vv = vd[:, None] * vv * vd
|
| 537 |
+
assert_almost_equal(vv, np.eye(100))
|
| 538 |
+
|
| 539 |
+
# check that the integral of 1 is correct
|
| 540 |
+
tgt = np.pi
|
| 541 |
+
assert_almost_equal(w.sum(), tgt)
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
class TestMisc:
|
| 545 |
+
|
| 546 |
+
def test_chebfromroots(self):
|
| 547 |
+
res = cheb.chebfromroots([])
|
| 548 |
+
assert_almost_equal(trim(res), [1])
|
| 549 |
+
for i in range(1, 5):
|
| 550 |
+
roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
|
| 551 |
+
tgt = [0]*i + [1]
|
| 552 |
+
res = cheb.chebfromroots(roots)*2**(i-1)
|
| 553 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 554 |
+
|
| 555 |
+
def test_chebroots(self):
|
| 556 |
+
assert_almost_equal(cheb.chebroots([1]), [])
|
| 557 |
+
assert_almost_equal(cheb.chebroots([1, 2]), [-.5])
|
| 558 |
+
for i in range(2, 5):
|
| 559 |
+
tgt = np.linspace(-1, 1, i)
|
| 560 |
+
res = cheb.chebroots(cheb.chebfromroots(tgt))
|
| 561 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 562 |
+
|
| 563 |
+
def test_chebtrim(self):
|
| 564 |
+
coef = [2, -1, 1, 0]
|
| 565 |
+
|
| 566 |
+
# Test exceptions
|
| 567 |
+
assert_raises(ValueError, cheb.chebtrim, coef, -1)
|
| 568 |
+
|
| 569 |
+
# Test results
|
| 570 |
+
assert_equal(cheb.chebtrim(coef), coef[:-1])
|
| 571 |
+
assert_equal(cheb.chebtrim(coef, 1), coef[:-3])
|
| 572 |
+
assert_equal(cheb.chebtrim(coef, 2), [0])
|
| 573 |
+
|
| 574 |
+
def test_chebline(self):
|
| 575 |
+
assert_equal(cheb.chebline(3, 4), [3, 4])
|
| 576 |
+
|
| 577 |
+
def test_cheb2poly(self):
|
| 578 |
+
for i in range(10):
|
| 579 |
+
assert_almost_equal(cheb.cheb2poly([0]*i + [1]), Tlist[i])
|
| 580 |
+
|
| 581 |
+
def test_poly2cheb(self):
|
| 582 |
+
for i in range(10):
|
| 583 |
+
assert_almost_equal(cheb.poly2cheb(Tlist[i]), [0]*i + [1])
|
| 584 |
+
|
| 585 |
+
def test_weight(self):
|
| 586 |
+
x = np.linspace(-1, 1, 11)[1:-1]
|
| 587 |
+
tgt = 1./(np.sqrt(1 + x) * np.sqrt(1 - x))
|
| 588 |
+
res = cheb.chebweight(x)
|
| 589 |
+
assert_almost_equal(res, tgt)
|
| 590 |
+
|
| 591 |
+
def test_chebpts1(self):
|
| 592 |
+
#test exceptions
|
| 593 |
+
assert_raises(ValueError, cheb.chebpts1, 1.5)
|
| 594 |
+
assert_raises(ValueError, cheb.chebpts1, 0)
|
| 595 |
+
|
| 596 |
+
#test points
|
| 597 |
+
tgt = [0]
|
| 598 |
+
assert_almost_equal(cheb.chebpts1(1), tgt)
|
| 599 |
+
tgt = [-0.70710678118654746, 0.70710678118654746]
|
| 600 |
+
assert_almost_equal(cheb.chebpts1(2), tgt)
|
| 601 |
+
tgt = [-0.86602540378443871, 0, 0.86602540378443871]
|
| 602 |
+
assert_almost_equal(cheb.chebpts1(3), tgt)
|
| 603 |
+
tgt = [-0.9238795325, -0.3826834323, 0.3826834323, 0.9238795325]
|
| 604 |
+
assert_almost_equal(cheb.chebpts1(4), tgt)
|
| 605 |
+
|
| 606 |
+
def test_chebpts2(self):
|
| 607 |
+
#test exceptions
|
| 608 |
+
assert_raises(ValueError, cheb.chebpts2, 1.5)
|
| 609 |
+
assert_raises(ValueError, cheb.chebpts2, 1)
|
| 610 |
+
|
| 611 |
+
#test points
|
| 612 |
+
tgt = [-1, 1]
|
| 613 |
+
assert_almost_equal(cheb.chebpts2(2), tgt)
|
| 614 |
+
tgt = [-1, 0, 1]
|
| 615 |
+
assert_almost_equal(cheb.chebpts2(3), tgt)
|
| 616 |
+
tgt = [-1, -0.5, .5, 1]
|
| 617 |
+
assert_almost_equal(cheb.chebpts2(4), tgt)
|
| 618 |
+
tgt = [-1.0, -0.707106781187, 0, 0.707106781187, 1.0]
|
| 619 |
+
assert_almost_equal(cheb.chebpts2(5), tgt)
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/test_hermite.py
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for hermite module.
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
from functools import reduce
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
import numpy.polynomial.hermite as herm
|
| 8 |
+
from numpy.polynomial.polynomial import polyval
|
| 9 |
+
from numpy.testing import (
|
| 10 |
+
assert_almost_equal, assert_raises, assert_equal, assert_,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
H0 = np.array([1])
|
| 14 |
+
H1 = np.array([0, 2])
|
| 15 |
+
H2 = np.array([-2, 0, 4])
|
| 16 |
+
H3 = np.array([0, -12, 0, 8])
|
| 17 |
+
H4 = np.array([12, 0, -48, 0, 16])
|
| 18 |
+
H5 = np.array([0, 120, 0, -160, 0, 32])
|
| 19 |
+
H6 = np.array([-120, 0, 720, 0, -480, 0, 64])
|
| 20 |
+
H7 = np.array([0, -1680, 0, 3360, 0, -1344, 0, 128])
|
| 21 |
+
H8 = np.array([1680, 0, -13440, 0, 13440, 0, -3584, 0, 256])
|
| 22 |
+
H9 = np.array([0, 30240, 0, -80640, 0, 48384, 0, -9216, 0, 512])
|
| 23 |
+
|
| 24 |
+
Hlist = [H0, H1, H2, H3, H4, H5, H6, H7, H8, H9]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def trim(x):
|
| 28 |
+
return herm.hermtrim(x, tol=1e-6)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class TestConstants:
|
| 32 |
+
|
| 33 |
+
def test_hermdomain(self):
|
| 34 |
+
assert_equal(herm.hermdomain, [-1, 1])
|
| 35 |
+
|
| 36 |
+
def test_hermzero(self):
|
| 37 |
+
assert_equal(herm.hermzero, [0])
|
| 38 |
+
|
| 39 |
+
def test_hermone(self):
|
| 40 |
+
assert_equal(herm.hermone, [1])
|
| 41 |
+
|
| 42 |
+
def test_hermx(self):
|
| 43 |
+
assert_equal(herm.hermx, [0, .5])
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class TestArithmetic:
|
| 47 |
+
x = np.linspace(-3, 3, 100)
|
| 48 |
+
|
| 49 |
+
def test_hermadd(self):
|
| 50 |
+
for i in range(5):
|
| 51 |
+
for j in range(5):
|
| 52 |
+
msg = f"At i={i}, j={j}"
|
| 53 |
+
tgt = np.zeros(max(i, j) + 1)
|
| 54 |
+
tgt[i] += 1
|
| 55 |
+
tgt[j] += 1
|
| 56 |
+
res = herm.hermadd([0]*i + [1], [0]*j + [1])
|
| 57 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 58 |
+
|
| 59 |
+
def test_hermsub(self):
|
| 60 |
+
for i in range(5):
|
| 61 |
+
for j in range(5):
|
| 62 |
+
msg = f"At i={i}, j={j}"
|
| 63 |
+
tgt = np.zeros(max(i, j) + 1)
|
| 64 |
+
tgt[i] += 1
|
| 65 |
+
tgt[j] -= 1
|
| 66 |
+
res = herm.hermsub([0]*i + [1], [0]*j + [1])
|
| 67 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 68 |
+
|
| 69 |
+
def test_hermmulx(self):
|
| 70 |
+
assert_equal(herm.hermmulx([0]), [0])
|
| 71 |
+
assert_equal(herm.hermmulx([1]), [0, .5])
|
| 72 |
+
for i in range(1, 5):
|
| 73 |
+
ser = [0]*i + [1]
|
| 74 |
+
tgt = [0]*(i - 1) + [i, 0, .5]
|
| 75 |
+
assert_equal(herm.hermmulx(ser), tgt)
|
| 76 |
+
|
| 77 |
+
def test_hermmul(self):
|
| 78 |
+
# check values of result
|
| 79 |
+
for i in range(5):
|
| 80 |
+
pol1 = [0]*i + [1]
|
| 81 |
+
val1 = herm.hermval(self.x, pol1)
|
| 82 |
+
for j in range(5):
|
| 83 |
+
msg = f"At i={i}, j={j}"
|
| 84 |
+
pol2 = [0]*j + [1]
|
| 85 |
+
val2 = herm.hermval(self.x, pol2)
|
| 86 |
+
pol3 = herm.hermmul(pol1, pol2)
|
| 87 |
+
val3 = herm.hermval(self.x, pol3)
|
| 88 |
+
assert_(len(pol3) == i + j + 1, msg)
|
| 89 |
+
assert_almost_equal(val3, val1*val2, err_msg=msg)
|
| 90 |
+
|
| 91 |
+
def test_hermdiv(self):
|
| 92 |
+
for i in range(5):
|
| 93 |
+
for j in range(5):
|
| 94 |
+
msg = f"At i={i}, j={j}"
|
| 95 |
+
ci = [0]*i + [1]
|
| 96 |
+
cj = [0]*j + [1]
|
| 97 |
+
tgt = herm.hermadd(ci, cj)
|
| 98 |
+
quo, rem = herm.hermdiv(tgt, ci)
|
| 99 |
+
res = herm.hermadd(herm.hermmul(quo, ci), rem)
|
| 100 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 101 |
+
|
| 102 |
+
def test_hermpow(self):
|
| 103 |
+
for i in range(5):
|
| 104 |
+
for j in range(5):
|
| 105 |
+
msg = f"At i={i}, j={j}"
|
| 106 |
+
c = np.arange(i + 1)
|
| 107 |
+
tgt = reduce(herm.hermmul, [c]*j, np.array([1]))
|
| 108 |
+
res = herm.hermpow(c, j)
|
| 109 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class TestEvaluation:
|
| 113 |
+
# coefficients of 1 + 2*x + 3*x**2
|
| 114 |
+
c1d = np.array([2.5, 1., .75])
|
| 115 |
+
c2d = np.einsum('i,j->ij', c1d, c1d)
|
| 116 |
+
c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)
|
| 117 |
+
|
| 118 |
+
# some random values in [-1, 1)
|
| 119 |
+
x = np.random.random((3, 5))*2 - 1
|
| 120 |
+
y = polyval(x, [1., 2., 3.])
|
| 121 |
+
|
| 122 |
+
def test_hermval(self):
|
| 123 |
+
#check empty input
|
| 124 |
+
assert_equal(herm.hermval([], [1]).size, 0)
|
| 125 |
+
|
| 126 |
+
#check normal input)
|
| 127 |
+
x = np.linspace(-1, 1)
|
| 128 |
+
y = [polyval(x, c) for c in Hlist]
|
| 129 |
+
for i in range(10):
|
| 130 |
+
msg = f"At i={i}"
|
| 131 |
+
tgt = y[i]
|
| 132 |
+
res = herm.hermval(x, [0]*i + [1])
|
| 133 |
+
assert_almost_equal(res, tgt, err_msg=msg)
|
| 134 |
+
|
| 135 |
+
#check that shape is preserved
|
| 136 |
+
for i in range(3):
|
| 137 |
+
dims = [2]*i
|
| 138 |
+
x = np.zeros(dims)
|
| 139 |
+
assert_equal(herm.hermval(x, [1]).shape, dims)
|
| 140 |
+
assert_equal(herm.hermval(x, [1, 0]).shape, dims)
|
| 141 |
+
assert_equal(herm.hermval(x, [1, 0, 0]).shape, dims)
|
| 142 |
+
|
| 143 |
+
def test_hermval2d(self):
|
| 144 |
+
x1, x2, x3 = self.x
|
| 145 |
+
y1, y2, y3 = self.y
|
| 146 |
+
|
| 147 |
+
#test exceptions
|
| 148 |
+
assert_raises(ValueError, herm.hermval2d, x1, x2[:2], self.c2d)
|
| 149 |
+
|
| 150 |
+
#test values
|
| 151 |
+
tgt = y1*y2
|
| 152 |
+
res = herm.hermval2d(x1, x2, self.c2d)
|
| 153 |
+
assert_almost_equal(res, tgt)
|
| 154 |
+
|
| 155 |
+
#test shape
|
| 156 |
+
z = np.ones((2, 3))
|
| 157 |
+
res = herm.hermval2d(z, z, self.c2d)
|
| 158 |
+
assert_(res.shape == (2, 3))
|
| 159 |
+
|
| 160 |
+
def test_hermval3d(self):
|
| 161 |
+
x1, x2, x3 = self.x
|
| 162 |
+
y1, y2, y3 = self.y
|
| 163 |
+
|
| 164 |
+
#test exceptions
|
| 165 |
+
assert_raises(ValueError, herm.hermval3d, x1, x2, x3[:2], self.c3d)
|
| 166 |
+
|
| 167 |
+
#test values
|
| 168 |
+
tgt = y1*y2*y3
|
| 169 |
+
res = herm.hermval3d(x1, x2, x3, self.c3d)
|
| 170 |
+
assert_almost_equal(res, tgt)
|
| 171 |
+
|
| 172 |
+
#test shape
|
| 173 |
+
z = np.ones((2, 3))
|
| 174 |
+
res = herm.hermval3d(z, z, z, self.c3d)
|
| 175 |
+
assert_(res.shape == (2, 3))
|
| 176 |
+
|
| 177 |
+
def test_hermgrid2d(self):
|
| 178 |
+
x1, x2, x3 = self.x
|
| 179 |
+
y1, y2, y3 = self.y
|
| 180 |
+
|
| 181 |
+
#test values
|
| 182 |
+
tgt = np.einsum('i,j->ij', y1, y2)
|
| 183 |
+
res = herm.hermgrid2d(x1, x2, self.c2d)
|
| 184 |
+
assert_almost_equal(res, tgt)
|
| 185 |
+
|
| 186 |
+
#test shape
|
| 187 |
+
z = np.ones((2, 3))
|
| 188 |
+
res = herm.hermgrid2d(z, z, self.c2d)
|
| 189 |
+
assert_(res.shape == (2, 3)*2)
|
| 190 |
+
|
| 191 |
+
def test_hermgrid3d(self):
|
| 192 |
+
x1, x2, x3 = self.x
|
| 193 |
+
y1, y2, y3 = self.y
|
| 194 |
+
|
| 195 |
+
#test values
|
| 196 |
+
tgt = np.einsum('i,j,k->ijk', y1, y2, y3)
|
| 197 |
+
res = herm.hermgrid3d(x1, x2, x3, self.c3d)
|
| 198 |
+
assert_almost_equal(res, tgt)
|
| 199 |
+
|
| 200 |
+
#test shape
|
| 201 |
+
z = np.ones((2, 3))
|
| 202 |
+
res = herm.hermgrid3d(z, z, z, self.c3d)
|
| 203 |
+
assert_(res.shape == (2, 3)*3)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
class TestIntegral:
|
| 207 |
+
|
| 208 |
+
def test_hermint(self):
|
| 209 |
+
# check exceptions
|
| 210 |
+
assert_raises(TypeError, herm.hermint, [0], .5)
|
| 211 |
+
assert_raises(ValueError, herm.hermint, [0], -1)
|
| 212 |
+
assert_raises(ValueError, herm.hermint, [0], 1, [0, 0])
|
| 213 |
+
assert_raises(ValueError, herm.hermint, [0], lbnd=[0])
|
| 214 |
+
assert_raises(ValueError, herm.hermint, [0], scl=[0])
|
| 215 |
+
assert_raises(TypeError, herm.hermint, [0], axis=.5)
|
| 216 |
+
|
| 217 |
+
# test integration of zero polynomial
|
| 218 |
+
for i in range(2, 5):
|
| 219 |
+
k = [0]*(i - 2) + [1]
|
| 220 |
+
res = herm.hermint([0], m=i, k=k)
|
| 221 |
+
assert_almost_equal(res, [0, .5])
|
| 222 |
+
|
| 223 |
+
# check single integration with integration constant
|
| 224 |
+
for i in range(5):
|
| 225 |
+
scl = i + 1
|
| 226 |
+
pol = [0]*i + [1]
|
| 227 |
+
tgt = [i] + [0]*i + [1/scl]
|
| 228 |
+
hermpol = herm.poly2herm(pol)
|
| 229 |
+
hermint = herm.hermint(hermpol, m=1, k=[i])
|
| 230 |
+
res = herm.herm2poly(hermint)
|
| 231 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 232 |
+
|
| 233 |
+
# check single integration with integration constant and lbnd
|
| 234 |
+
for i in range(5):
|
| 235 |
+
scl = i + 1
|
| 236 |
+
pol = [0]*i + [1]
|
| 237 |
+
hermpol = herm.poly2herm(pol)
|
| 238 |
+
hermint = herm.hermint(hermpol, m=1, k=[i], lbnd=-1)
|
| 239 |
+
assert_almost_equal(herm.hermval(-1, hermint), i)
|
| 240 |
+
|
| 241 |
+
# check single integration with integration constant and scaling
|
| 242 |
+
for i in range(5):
|
| 243 |
+
scl = i + 1
|
| 244 |
+
pol = [0]*i + [1]
|
| 245 |
+
tgt = [i] + [0]*i + [2/scl]
|
| 246 |
+
hermpol = herm.poly2herm(pol)
|
| 247 |
+
hermint = herm.hermint(hermpol, m=1, k=[i], scl=2)
|
| 248 |
+
res = herm.herm2poly(hermint)
|
| 249 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 250 |
+
|
| 251 |
+
# check multiple integrations with default k
|
| 252 |
+
for i in range(5):
|
| 253 |
+
for j in range(2, 5):
|
| 254 |
+
pol = [0]*i + [1]
|
| 255 |
+
tgt = pol[:]
|
| 256 |
+
for k in range(j):
|
| 257 |
+
tgt = herm.hermint(tgt, m=1)
|
| 258 |
+
res = herm.hermint(pol, m=j)
|
| 259 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 260 |
+
|
| 261 |
+
# check multiple integrations with defined k
|
| 262 |
+
for i in range(5):
|
| 263 |
+
for j in range(2, 5):
|
| 264 |
+
pol = [0]*i + [1]
|
| 265 |
+
tgt = pol[:]
|
| 266 |
+
for k in range(j):
|
| 267 |
+
tgt = herm.hermint(tgt, m=1, k=[k])
|
| 268 |
+
res = herm.hermint(pol, m=j, k=list(range(j)))
|
| 269 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 270 |
+
|
| 271 |
+
# check multiple integrations with lbnd
|
| 272 |
+
for i in range(5):
|
| 273 |
+
for j in range(2, 5):
|
| 274 |
+
pol = [0]*i + [1]
|
| 275 |
+
tgt = pol[:]
|
| 276 |
+
for k in range(j):
|
| 277 |
+
tgt = herm.hermint(tgt, m=1, k=[k], lbnd=-1)
|
| 278 |
+
res = herm.hermint(pol, m=j, k=list(range(j)), lbnd=-1)
|
| 279 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 280 |
+
|
| 281 |
+
# check multiple integrations with scaling
|
| 282 |
+
for i in range(5):
|
| 283 |
+
for j in range(2, 5):
|
| 284 |
+
pol = [0]*i + [1]
|
| 285 |
+
tgt = pol[:]
|
| 286 |
+
for k in range(j):
|
| 287 |
+
tgt = herm.hermint(tgt, m=1, k=[k], scl=2)
|
| 288 |
+
res = herm.hermint(pol, m=j, k=list(range(j)), scl=2)
|
| 289 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 290 |
+
|
| 291 |
+
def test_hermint_axis(self):
|
| 292 |
+
# check that axis keyword works
|
| 293 |
+
c2d = np.random.random((3, 4))
|
| 294 |
+
|
| 295 |
+
tgt = np.vstack([herm.hermint(c) for c in c2d.T]).T
|
| 296 |
+
res = herm.hermint(c2d, axis=0)
|
| 297 |
+
assert_almost_equal(res, tgt)
|
| 298 |
+
|
| 299 |
+
tgt = np.vstack([herm.hermint(c) for c in c2d])
|
| 300 |
+
res = herm.hermint(c2d, axis=1)
|
| 301 |
+
assert_almost_equal(res, tgt)
|
| 302 |
+
|
| 303 |
+
tgt = np.vstack([herm.hermint(c, k=3) for c in c2d])
|
| 304 |
+
res = herm.hermint(c2d, k=3, axis=1)
|
| 305 |
+
assert_almost_equal(res, tgt)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
class TestDerivative:
|
| 309 |
+
|
| 310 |
+
def test_hermder(self):
|
| 311 |
+
# check exceptions
|
| 312 |
+
assert_raises(TypeError, herm.hermder, [0], .5)
|
| 313 |
+
assert_raises(ValueError, herm.hermder, [0], -1)
|
| 314 |
+
|
| 315 |
+
# check that zeroth derivative does nothing
|
| 316 |
+
for i in range(5):
|
| 317 |
+
tgt = [0]*i + [1]
|
| 318 |
+
res = herm.hermder(tgt, m=0)
|
| 319 |
+
assert_equal(trim(res), trim(tgt))
|
| 320 |
+
|
| 321 |
+
# check that derivation is the inverse of integration
|
| 322 |
+
for i in range(5):
|
| 323 |
+
for j in range(2, 5):
|
| 324 |
+
tgt = [0]*i + [1]
|
| 325 |
+
res = herm.hermder(herm.hermint(tgt, m=j), m=j)
|
| 326 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 327 |
+
|
| 328 |
+
# check derivation with scaling
|
| 329 |
+
for i in range(5):
|
| 330 |
+
for j in range(2, 5):
|
| 331 |
+
tgt = [0]*i + [1]
|
| 332 |
+
res = herm.hermder(herm.hermint(tgt, m=j, scl=2), m=j, scl=.5)
|
| 333 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 334 |
+
|
| 335 |
+
def test_hermder_axis(self):
|
| 336 |
+
# check that axis keyword works
|
| 337 |
+
c2d = np.random.random((3, 4))
|
| 338 |
+
|
| 339 |
+
tgt = np.vstack([herm.hermder(c) for c in c2d.T]).T
|
| 340 |
+
res = herm.hermder(c2d, axis=0)
|
| 341 |
+
assert_almost_equal(res, tgt)
|
| 342 |
+
|
| 343 |
+
tgt = np.vstack([herm.hermder(c) for c in c2d])
|
| 344 |
+
res = herm.hermder(c2d, axis=1)
|
| 345 |
+
assert_almost_equal(res, tgt)
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
class TestVander:
|
| 349 |
+
# some random values in [-1, 1)
|
| 350 |
+
x = np.random.random((3, 5))*2 - 1
|
| 351 |
+
|
| 352 |
+
def test_hermvander(self):
|
| 353 |
+
# check for 1d x
|
| 354 |
+
x = np.arange(3)
|
| 355 |
+
v = herm.hermvander(x, 3)
|
| 356 |
+
assert_(v.shape == (3, 4))
|
| 357 |
+
for i in range(4):
|
| 358 |
+
coef = [0]*i + [1]
|
| 359 |
+
assert_almost_equal(v[..., i], herm.hermval(x, coef))
|
| 360 |
+
|
| 361 |
+
# check for 2d x
|
| 362 |
+
x = np.array([[1, 2], [3, 4], [5, 6]])
|
| 363 |
+
v = herm.hermvander(x, 3)
|
| 364 |
+
assert_(v.shape == (3, 2, 4))
|
| 365 |
+
for i in range(4):
|
| 366 |
+
coef = [0]*i + [1]
|
| 367 |
+
assert_almost_equal(v[..., i], herm.hermval(x, coef))
|
| 368 |
+
|
| 369 |
+
def test_hermvander2d(self):
|
| 370 |
+
# also tests hermval2d for non-square coefficient array
|
| 371 |
+
x1, x2, x3 = self.x
|
| 372 |
+
c = np.random.random((2, 3))
|
| 373 |
+
van = herm.hermvander2d(x1, x2, [1, 2])
|
| 374 |
+
tgt = herm.hermval2d(x1, x2, c)
|
| 375 |
+
res = np.dot(van, c.flat)
|
| 376 |
+
assert_almost_equal(res, tgt)
|
| 377 |
+
|
| 378 |
+
# check shape
|
| 379 |
+
van = herm.hermvander2d([x1], [x2], [1, 2])
|
| 380 |
+
assert_(van.shape == (1, 5, 6))
|
| 381 |
+
|
| 382 |
+
def test_hermvander3d(self):
|
| 383 |
+
# also tests hermval3d for non-square coefficient array
|
| 384 |
+
x1, x2, x3 = self.x
|
| 385 |
+
c = np.random.random((2, 3, 4))
|
| 386 |
+
van = herm.hermvander3d(x1, x2, x3, [1, 2, 3])
|
| 387 |
+
tgt = herm.hermval3d(x1, x2, x3, c)
|
| 388 |
+
res = np.dot(van, c.flat)
|
| 389 |
+
assert_almost_equal(res, tgt)
|
| 390 |
+
|
| 391 |
+
# check shape
|
| 392 |
+
van = herm.hermvander3d([x1], [x2], [x3], [1, 2, 3])
|
| 393 |
+
assert_(van.shape == (1, 5, 24))
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
class TestFitting:
|
| 397 |
+
|
| 398 |
+
def test_hermfit(self):
|
| 399 |
+
def f(x):
|
| 400 |
+
return x*(x - 1)*(x - 2)
|
| 401 |
+
|
| 402 |
+
def f2(x):
|
| 403 |
+
return x**4 + x**2 + 1
|
| 404 |
+
|
| 405 |
+
# Test exceptions
|
| 406 |
+
assert_raises(ValueError, herm.hermfit, [1], [1], -1)
|
| 407 |
+
assert_raises(TypeError, herm.hermfit, [[1]], [1], 0)
|
| 408 |
+
assert_raises(TypeError, herm.hermfit, [], [1], 0)
|
| 409 |
+
assert_raises(TypeError, herm.hermfit, [1], [[[1]]], 0)
|
| 410 |
+
assert_raises(TypeError, herm.hermfit, [1, 2], [1], 0)
|
| 411 |
+
assert_raises(TypeError, herm.hermfit, [1], [1, 2], 0)
|
| 412 |
+
assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[[1]])
|
| 413 |
+
assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[1, 1])
|
| 414 |
+
assert_raises(ValueError, herm.hermfit, [1], [1], [-1,])
|
| 415 |
+
assert_raises(ValueError, herm.hermfit, [1], [1], [2, -1, 6])
|
| 416 |
+
assert_raises(TypeError, herm.hermfit, [1], [1], [])
|
| 417 |
+
|
| 418 |
+
# Test fit
|
| 419 |
+
x = np.linspace(0, 2)
|
| 420 |
+
y = f(x)
|
| 421 |
+
#
|
| 422 |
+
coef3 = herm.hermfit(x, y, 3)
|
| 423 |
+
assert_equal(len(coef3), 4)
|
| 424 |
+
assert_almost_equal(herm.hermval(x, coef3), y)
|
| 425 |
+
coef3 = herm.hermfit(x, y, [0, 1, 2, 3])
|
| 426 |
+
assert_equal(len(coef3), 4)
|
| 427 |
+
assert_almost_equal(herm.hermval(x, coef3), y)
|
| 428 |
+
#
|
| 429 |
+
coef4 = herm.hermfit(x, y, 4)
|
| 430 |
+
assert_equal(len(coef4), 5)
|
| 431 |
+
assert_almost_equal(herm.hermval(x, coef4), y)
|
| 432 |
+
coef4 = herm.hermfit(x, y, [0, 1, 2, 3, 4])
|
| 433 |
+
assert_equal(len(coef4), 5)
|
| 434 |
+
assert_almost_equal(herm.hermval(x, coef4), y)
|
| 435 |
+
# check things still work if deg is not in strict increasing
|
| 436 |
+
coef4 = herm.hermfit(x, y, [2, 3, 4, 1, 0])
|
| 437 |
+
assert_equal(len(coef4), 5)
|
| 438 |
+
assert_almost_equal(herm.hermval(x, coef4), y)
|
| 439 |
+
#
|
| 440 |
+
coef2d = herm.hermfit(x, np.array([y, y]).T, 3)
|
| 441 |
+
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
|
| 442 |
+
coef2d = herm.hermfit(x, np.array([y, y]).T, [0, 1, 2, 3])
|
| 443 |
+
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
|
| 444 |
+
# test weighting
|
| 445 |
+
w = np.zeros_like(x)
|
| 446 |
+
yw = y.copy()
|
| 447 |
+
w[1::2] = 1
|
| 448 |
+
y[0::2] = 0
|
| 449 |
+
wcoef3 = herm.hermfit(x, yw, 3, w=w)
|
| 450 |
+
assert_almost_equal(wcoef3, coef3)
|
| 451 |
+
wcoef3 = herm.hermfit(x, yw, [0, 1, 2, 3], w=w)
|
| 452 |
+
assert_almost_equal(wcoef3, coef3)
|
| 453 |
+
#
|
| 454 |
+
wcoef2d = herm.hermfit(x, np.array([yw, yw]).T, 3, w=w)
|
| 455 |
+
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
|
| 456 |
+
wcoef2d = herm.hermfit(x, np.array([yw, yw]).T, [0, 1, 2, 3], w=w)
|
| 457 |
+
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
|
| 458 |
+
# test scaling with complex values x points whose square
|
| 459 |
+
# is zero when summed.
|
| 460 |
+
x = [1, 1j, -1, -1j]
|
| 461 |
+
assert_almost_equal(herm.hermfit(x, x, 1), [0, .5])
|
| 462 |
+
assert_almost_equal(herm.hermfit(x, x, [0, 1]), [0, .5])
|
| 463 |
+
# test fitting only even Legendre polynomials
|
| 464 |
+
x = np.linspace(-1, 1)
|
| 465 |
+
y = f2(x)
|
| 466 |
+
coef1 = herm.hermfit(x, y, 4)
|
| 467 |
+
assert_almost_equal(herm.hermval(x, coef1), y)
|
| 468 |
+
coef2 = herm.hermfit(x, y, [0, 2, 4])
|
| 469 |
+
assert_almost_equal(herm.hermval(x, coef2), y)
|
| 470 |
+
assert_almost_equal(coef1, coef2)
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
class TestCompanion:
|
| 474 |
+
|
| 475 |
+
def test_raises(self):
|
| 476 |
+
assert_raises(ValueError, herm.hermcompanion, [])
|
| 477 |
+
assert_raises(ValueError, herm.hermcompanion, [1])
|
| 478 |
+
|
| 479 |
+
def test_dimensions(self):
|
| 480 |
+
for i in range(1, 5):
|
| 481 |
+
coef = [0]*i + [1]
|
| 482 |
+
assert_(herm.hermcompanion(coef).shape == (i, i))
|
| 483 |
+
|
| 484 |
+
def test_linear_root(self):
|
| 485 |
+
assert_(herm.hermcompanion([1, 2])[0, 0] == -.25)
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
class TestGauss:
|
| 489 |
+
|
| 490 |
+
def test_100(self):
|
| 491 |
+
x, w = herm.hermgauss(100)
|
| 492 |
+
|
| 493 |
+
# test orthogonality. Note that the results need to be normalized,
|
| 494 |
+
# otherwise the huge values that can arise from fast growing
|
| 495 |
+
# functions like Laguerre can be very confusing.
|
| 496 |
+
v = herm.hermvander(x, 99)
|
| 497 |
+
vv = np.dot(v.T * w, v)
|
| 498 |
+
vd = 1/np.sqrt(vv.diagonal())
|
| 499 |
+
vv = vd[:, None] * vv * vd
|
| 500 |
+
assert_almost_equal(vv, np.eye(100))
|
| 501 |
+
|
| 502 |
+
# check that the integral of 1 is correct
|
| 503 |
+
tgt = np.sqrt(np.pi)
|
| 504 |
+
assert_almost_equal(w.sum(), tgt)
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
class TestMisc:
|
| 508 |
+
|
| 509 |
+
def test_hermfromroots(self):
|
| 510 |
+
res = herm.hermfromroots([])
|
| 511 |
+
assert_almost_equal(trim(res), [1])
|
| 512 |
+
for i in range(1, 5):
|
| 513 |
+
roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
|
| 514 |
+
pol = herm.hermfromroots(roots)
|
| 515 |
+
res = herm.hermval(roots, pol)
|
| 516 |
+
tgt = 0
|
| 517 |
+
assert_(len(pol) == i + 1)
|
| 518 |
+
assert_almost_equal(herm.herm2poly(pol)[-1], 1)
|
| 519 |
+
assert_almost_equal(res, tgt)
|
| 520 |
+
|
| 521 |
+
def test_hermroots(self):
|
| 522 |
+
assert_almost_equal(herm.hermroots([1]), [])
|
| 523 |
+
assert_almost_equal(herm.hermroots([1, 1]), [-.5])
|
| 524 |
+
for i in range(2, 5):
|
| 525 |
+
tgt = np.linspace(-1, 1, i)
|
| 526 |
+
res = herm.hermroots(herm.hermfromroots(tgt))
|
| 527 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 528 |
+
|
| 529 |
+
def test_hermtrim(self):
|
| 530 |
+
coef = [2, -1, 1, 0]
|
| 531 |
+
|
| 532 |
+
# Test exceptions
|
| 533 |
+
assert_raises(ValueError, herm.hermtrim, coef, -1)
|
| 534 |
+
|
| 535 |
+
# Test results
|
| 536 |
+
assert_equal(herm.hermtrim(coef), coef[:-1])
|
| 537 |
+
assert_equal(herm.hermtrim(coef, 1), coef[:-3])
|
| 538 |
+
assert_equal(herm.hermtrim(coef, 2), [0])
|
| 539 |
+
|
| 540 |
+
def test_hermline(self):
|
| 541 |
+
assert_equal(herm.hermline(3, 4), [3, 2])
|
| 542 |
+
|
| 543 |
+
def test_herm2poly(self):
|
| 544 |
+
for i in range(10):
|
| 545 |
+
assert_almost_equal(herm.herm2poly([0]*i + [1]), Hlist[i])
|
| 546 |
+
|
| 547 |
+
def test_poly2herm(self):
|
| 548 |
+
for i in range(10):
|
| 549 |
+
assert_almost_equal(herm.poly2herm(Hlist[i]), [0]*i + [1])
|
| 550 |
+
|
| 551 |
+
def test_weight(self):
|
| 552 |
+
x = np.linspace(-5, 5, 11)
|
| 553 |
+
tgt = np.exp(-x**2)
|
| 554 |
+
res = herm.hermweight(x)
|
| 555 |
+
assert_almost_equal(res, tgt)
|
parrot/lib/python3.10/site-packages/numpy/polynomial/tests/test_laguerre.py
ADDED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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for laguerre module.
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
from functools import reduce
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
import numpy.polynomial.laguerre as lag
|
| 8 |
+
from numpy.polynomial.polynomial import polyval
|
| 9 |
+
from numpy.testing import (
|
| 10 |
+
assert_almost_equal, assert_raises, assert_equal, assert_,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
L0 = np.array([1])/1
|
| 14 |
+
L1 = np.array([1, -1])/1
|
| 15 |
+
L2 = np.array([2, -4, 1])/2
|
| 16 |
+
L3 = np.array([6, -18, 9, -1])/6
|
| 17 |
+
L4 = np.array([24, -96, 72, -16, 1])/24
|
| 18 |
+
L5 = np.array([120, -600, 600, -200, 25, -1])/120
|
| 19 |
+
L6 = np.array([720, -4320, 5400, -2400, 450, -36, 1])/720
|
| 20 |
+
|
| 21 |
+
Llist = [L0, L1, L2, L3, L4, L5, L6]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def trim(x):
|
| 25 |
+
return lag.lagtrim(x, tol=1e-6)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class TestConstants:
|
| 29 |
+
|
| 30 |
+
def test_lagdomain(self):
|
| 31 |
+
assert_equal(lag.lagdomain, [0, 1])
|
| 32 |
+
|
| 33 |
+
def test_lagzero(self):
|
| 34 |
+
assert_equal(lag.lagzero, [0])
|
| 35 |
+
|
| 36 |
+
def test_lagone(self):
|
| 37 |
+
assert_equal(lag.lagone, [1])
|
| 38 |
+
|
| 39 |
+
def test_lagx(self):
|
| 40 |
+
assert_equal(lag.lagx, [1, -1])
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class TestArithmetic:
|
| 44 |
+
x = np.linspace(-3, 3, 100)
|
| 45 |
+
|
| 46 |
+
def test_lagadd(self):
|
| 47 |
+
for i in range(5):
|
| 48 |
+
for j in range(5):
|
| 49 |
+
msg = f"At i={i}, j={j}"
|
| 50 |
+
tgt = np.zeros(max(i, j) + 1)
|
| 51 |
+
tgt[i] += 1
|
| 52 |
+
tgt[j] += 1
|
| 53 |
+
res = lag.lagadd([0]*i + [1], [0]*j + [1])
|
| 54 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 55 |
+
|
| 56 |
+
def test_lagsub(self):
|
| 57 |
+
for i in range(5):
|
| 58 |
+
for j in range(5):
|
| 59 |
+
msg = f"At i={i}, j={j}"
|
| 60 |
+
tgt = np.zeros(max(i, j) + 1)
|
| 61 |
+
tgt[i] += 1
|
| 62 |
+
tgt[j] -= 1
|
| 63 |
+
res = lag.lagsub([0]*i + [1], [0]*j + [1])
|
| 64 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 65 |
+
|
| 66 |
+
def test_lagmulx(self):
|
| 67 |
+
assert_equal(lag.lagmulx([0]), [0])
|
| 68 |
+
assert_equal(lag.lagmulx([1]), [1, -1])
|
| 69 |
+
for i in range(1, 5):
|
| 70 |
+
ser = [0]*i + [1]
|
| 71 |
+
tgt = [0]*(i - 1) + [-i, 2*i + 1, -(i + 1)]
|
| 72 |
+
assert_almost_equal(lag.lagmulx(ser), tgt)
|
| 73 |
+
|
| 74 |
+
def test_lagmul(self):
|
| 75 |
+
# check values of result
|
| 76 |
+
for i in range(5):
|
| 77 |
+
pol1 = [0]*i + [1]
|
| 78 |
+
val1 = lag.lagval(self.x, pol1)
|
| 79 |
+
for j in range(5):
|
| 80 |
+
msg = f"At i={i}, j={j}"
|
| 81 |
+
pol2 = [0]*j + [1]
|
| 82 |
+
val2 = lag.lagval(self.x, pol2)
|
| 83 |
+
pol3 = lag.lagmul(pol1, pol2)
|
| 84 |
+
val3 = lag.lagval(self.x, pol3)
|
| 85 |
+
assert_(len(pol3) == i + j + 1, msg)
|
| 86 |
+
assert_almost_equal(val3, val1*val2, err_msg=msg)
|
| 87 |
+
|
| 88 |
+
def test_lagdiv(self):
|
| 89 |
+
for i in range(5):
|
| 90 |
+
for j in range(5):
|
| 91 |
+
msg = f"At i={i}, j={j}"
|
| 92 |
+
ci = [0]*i + [1]
|
| 93 |
+
cj = [0]*j + [1]
|
| 94 |
+
tgt = lag.lagadd(ci, cj)
|
| 95 |
+
quo, rem = lag.lagdiv(tgt, ci)
|
| 96 |
+
res = lag.lagadd(lag.lagmul(quo, ci), rem)
|
| 97 |
+
assert_almost_equal(trim(res), trim(tgt), err_msg=msg)
|
| 98 |
+
|
| 99 |
+
def test_lagpow(self):
|
| 100 |
+
for i in range(5):
|
| 101 |
+
for j in range(5):
|
| 102 |
+
msg = f"At i={i}, j={j}"
|
| 103 |
+
c = np.arange(i + 1)
|
| 104 |
+
tgt = reduce(lag.lagmul, [c]*j, np.array([1]))
|
| 105 |
+
res = lag.lagpow(c, j)
|
| 106 |
+
assert_equal(trim(res), trim(tgt), err_msg=msg)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class TestEvaluation:
|
| 110 |
+
# coefficients of 1 + 2*x + 3*x**2
|
| 111 |
+
c1d = np.array([9., -14., 6.])
|
| 112 |
+
c2d = np.einsum('i,j->ij', c1d, c1d)
|
| 113 |
+
c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)
|
| 114 |
+
|
| 115 |
+
# some random values in [-1, 1)
|
| 116 |
+
x = np.random.random((3, 5))*2 - 1
|
| 117 |
+
y = polyval(x, [1., 2., 3.])
|
| 118 |
+
|
| 119 |
+
def test_lagval(self):
|
| 120 |
+
#check empty input
|
| 121 |
+
assert_equal(lag.lagval([], [1]).size, 0)
|
| 122 |
+
|
| 123 |
+
#check normal input)
|
| 124 |
+
x = np.linspace(-1, 1)
|
| 125 |
+
y = [polyval(x, c) for c in Llist]
|
| 126 |
+
for i in range(7):
|
| 127 |
+
msg = f"At i={i}"
|
| 128 |
+
tgt = y[i]
|
| 129 |
+
res = lag.lagval(x, [0]*i + [1])
|
| 130 |
+
assert_almost_equal(res, tgt, err_msg=msg)
|
| 131 |
+
|
| 132 |
+
#check that shape is preserved
|
| 133 |
+
for i in range(3):
|
| 134 |
+
dims = [2]*i
|
| 135 |
+
x = np.zeros(dims)
|
| 136 |
+
assert_equal(lag.lagval(x, [1]).shape, dims)
|
| 137 |
+
assert_equal(lag.lagval(x, [1, 0]).shape, dims)
|
| 138 |
+
assert_equal(lag.lagval(x, [1, 0, 0]).shape, dims)
|
| 139 |
+
|
| 140 |
+
def test_lagval2d(self):
|
| 141 |
+
x1, x2, x3 = self.x
|
| 142 |
+
y1, y2, y3 = self.y
|
| 143 |
+
|
| 144 |
+
#test exceptions
|
| 145 |
+
assert_raises(ValueError, lag.lagval2d, x1, x2[:2], self.c2d)
|
| 146 |
+
|
| 147 |
+
#test values
|
| 148 |
+
tgt = y1*y2
|
| 149 |
+
res = lag.lagval2d(x1, x2, self.c2d)
|
| 150 |
+
assert_almost_equal(res, tgt)
|
| 151 |
+
|
| 152 |
+
#test shape
|
| 153 |
+
z = np.ones((2, 3))
|
| 154 |
+
res = lag.lagval2d(z, z, self.c2d)
|
| 155 |
+
assert_(res.shape == (2, 3))
|
| 156 |
+
|
| 157 |
+
def test_lagval3d(self):
|
| 158 |
+
x1, x2, x3 = self.x
|
| 159 |
+
y1, y2, y3 = self.y
|
| 160 |
+
|
| 161 |
+
#test exceptions
|
| 162 |
+
assert_raises(ValueError, lag.lagval3d, x1, x2, x3[:2], self.c3d)
|
| 163 |
+
|
| 164 |
+
#test values
|
| 165 |
+
tgt = y1*y2*y3
|
| 166 |
+
res = lag.lagval3d(x1, x2, x3, self.c3d)
|
| 167 |
+
assert_almost_equal(res, tgt)
|
| 168 |
+
|
| 169 |
+
#test shape
|
| 170 |
+
z = np.ones((2, 3))
|
| 171 |
+
res = lag.lagval3d(z, z, z, self.c3d)
|
| 172 |
+
assert_(res.shape == (2, 3))
|
| 173 |
+
|
| 174 |
+
def test_laggrid2d(self):
|
| 175 |
+
x1, x2, x3 = self.x
|
| 176 |
+
y1, y2, y3 = self.y
|
| 177 |
+
|
| 178 |
+
#test values
|
| 179 |
+
tgt = np.einsum('i,j->ij', y1, y2)
|
| 180 |
+
res = lag.laggrid2d(x1, x2, self.c2d)
|
| 181 |
+
assert_almost_equal(res, tgt)
|
| 182 |
+
|
| 183 |
+
#test shape
|
| 184 |
+
z = np.ones((2, 3))
|
| 185 |
+
res = lag.laggrid2d(z, z, self.c2d)
|
| 186 |
+
assert_(res.shape == (2, 3)*2)
|
| 187 |
+
|
| 188 |
+
def test_laggrid3d(self):
|
| 189 |
+
x1, x2, x3 = self.x
|
| 190 |
+
y1, y2, y3 = self.y
|
| 191 |
+
|
| 192 |
+
#test values
|
| 193 |
+
tgt = np.einsum('i,j,k->ijk', y1, y2, y3)
|
| 194 |
+
res = lag.laggrid3d(x1, x2, x3, self.c3d)
|
| 195 |
+
assert_almost_equal(res, tgt)
|
| 196 |
+
|
| 197 |
+
#test shape
|
| 198 |
+
z = np.ones((2, 3))
|
| 199 |
+
res = lag.laggrid3d(z, z, z, self.c3d)
|
| 200 |
+
assert_(res.shape == (2, 3)*3)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
class TestIntegral:
|
| 204 |
+
|
| 205 |
+
def test_lagint(self):
|
| 206 |
+
# check exceptions
|
| 207 |
+
assert_raises(TypeError, lag.lagint, [0], .5)
|
| 208 |
+
assert_raises(ValueError, lag.lagint, [0], -1)
|
| 209 |
+
assert_raises(ValueError, lag.lagint, [0], 1, [0, 0])
|
| 210 |
+
assert_raises(ValueError, lag.lagint, [0], lbnd=[0])
|
| 211 |
+
assert_raises(ValueError, lag.lagint, [0], scl=[0])
|
| 212 |
+
assert_raises(TypeError, lag.lagint, [0], axis=.5)
|
| 213 |
+
|
| 214 |
+
# test integration of zero polynomial
|
| 215 |
+
for i in range(2, 5):
|
| 216 |
+
k = [0]*(i - 2) + [1]
|
| 217 |
+
res = lag.lagint([0], m=i, k=k)
|
| 218 |
+
assert_almost_equal(res, [1, -1])
|
| 219 |
+
|
| 220 |
+
# check single integration with integration constant
|
| 221 |
+
for i in range(5):
|
| 222 |
+
scl = i + 1
|
| 223 |
+
pol = [0]*i + [1]
|
| 224 |
+
tgt = [i] + [0]*i + [1/scl]
|
| 225 |
+
lagpol = lag.poly2lag(pol)
|
| 226 |
+
lagint = lag.lagint(lagpol, m=1, k=[i])
|
| 227 |
+
res = lag.lag2poly(lagint)
|
| 228 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 229 |
+
|
| 230 |
+
# check single integration with integration constant and lbnd
|
| 231 |
+
for i in range(5):
|
| 232 |
+
scl = i + 1
|
| 233 |
+
pol = [0]*i + [1]
|
| 234 |
+
lagpol = lag.poly2lag(pol)
|
| 235 |
+
lagint = lag.lagint(lagpol, m=1, k=[i], lbnd=-1)
|
| 236 |
+
assert_almost_equal(lag.lagval(-1, lagint), i)
|
| 237 |
+
|
| 238 |
+
# check single integration with integration constant and scaling
|
| 239 |
+
for i in range(5):
|
| 240 |
+
scl = i + 1
|
| 241 |
+
pol = [0]*i + [1]
|
| 242 |
+
tgt = [i] + [0]*i + [2/scl]
|
| 243 |
+
lagpol = lag.poly2lag(pol)
|
| 244 |
+
lagint = lag.lagint(lagpol, m=1, k=[i], scl=2)
|
| 245 |
+
res = lag.lag2poly(lagint)
|
| 246 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 247 |
+
|
| 248 |
+
# check multiple integrations with default k
|
| 249 |
+
for i in range(5):
|
| 250 |
+
for j in range(2, 5):
|
| 251 |
+
pol = [0]*i + [1]
|
| 252 |
+
tgt = pol[:]
|
| 253 |
+
for k in range(j):
|
| 254 |
+
tgt = lag.lagint(tgt, m=1)
|
| 255 |
+
res = lag.lagint(pol, m=j)
|
| 256 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 257 |
+
|
| 258 |
+
# check multiple integrations with defined k
|
| 259 |
+
for i in range(5):
|
| 260 |
+
for j in range(2, 5):
|
| 261 |
+
pol = [0]*i + [1]
|
| 262 |
+
tgt = pol[:]
|
| 263 |
+
for k in range(j):
|
| 264 |
+
tgt = lag.lagint(tgt, m=1, k=[k])
|
| 265 |
+
res = lag.lagint(pol, m=j, k=list(range(j)))
|
| 266 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 267 |
+
|
| 268 |
+
# check multiple integrations with lbnd
|
| 269 |
+
for i in range(5):
|
| 270 |
+
for j in range(2, 5):
|
| 271 |
+
pol = [0]*i + [1]
|
| 272 |
+
tgt = pol[:]
|
| 273 |
+
for k in range(j):
|
| 274 |
+
tgt = lag.lagint(tgt, m=1, k=[k], lbnd=-1)
|
| 275 |
+
res = lag.lagint(pol, m=j, k=list(range(j)), lbnd=-1)
|
| 276 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 277 |
+
|
| 278 |
+
# check multiple integrations with scaling
|
| 279 |
+
for i in range(5):
|
| 280 |
+
for j in range(2, 5):
|
| 281 |
+
pol = [0]*i + [1]
|
| 282 |
+
tgt = pol[:]
|
| 283 |
+
for k in range(j):
|
| 284 |
+
tgt = lag.lagint(tgt, m=1, k=[k], scl=2)
|
| 285 |
+
res = lag.lagint(pol, m=j, k=list(range(j)), scl=2)
|
| 286 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 287 |
+
|
| 288 |
+
def test_lagint_axis(self):
|
| 289 |
+
# check that axis keyword works
|
| 290 |
+
c2d = np.random.random((3, 4))
|
| 291 |
+
|
| 292 |
+
tgt = np.vstack([lag.lagint(c) for c in c2d.T]).T
|
| 293 |
+
res = lag.lagint(c2d, axis=0)
|
| 294 |
+
assert_almost_equal(res, tgt)
|
| 295 |
+
|
| 296 |
+
tgt = np.vstack([lag.lagint(c) for c in c2d])
|
| 297 |
+
res = lag.lagint(c2d, axis=1)
|
| 298 |
+
assert_almost_equal(res, tgt)
|
| 299 |
+
|
| 300 |
+
tgt = np.vstack([lag.lagint(c, k=3) for c in c2d])
|
| 301 |
+
res = lag.lagint(c2d, k=3, axis=1)
|
| 302 |
+
assert_almost_equal(res, tgt)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
class TestDerivative:
|
| 306 |
+
|
| 307 |
+
def test_lagder(self):
|
| 308 |
+
# check exceptions
|
| 309 |
+
assert_raises(TypeError, lag.lagder, [0], .5)
|
| 310 |
+
assert_raises(ValueError, lag.lagder, [0], -1)
|
| 311 |
+
|
| 312 |
+
# check that zeroth derivative does nothing
|
| 313 |
+
for i in range(5):
|
| 314 |
+
tgt = [0]*i + [1]
|
| 315 |
+
res = lag.lagder(tgt, m=0)
|
| 316 |
+
assert_equal(trim(res), trim(tgt))
|
| 317 |
+
|
| 318 |
+
# check that derivation is the inverse of integration
|
| 319 |
+
for i in range(5):
|
| 320 |
+
for j in range(2, 5):
|
| 321 |
+
tgt = [0]*i + [1]
|
| 322 |
+
res = lag.lagder(lag.lagint(tgt, m=j), m=j)
|
| 323 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 324 |
+
|
| 325 |
+
# check derivation with scaling
|
| 326 |
+
for i in range(5):
|
| 327 |
+
for j in range(2, 5):
|
| 328 |
+
tgt = [0]*i + [1]
|
| 329 |
+
res = lag.lagder(lag.lagint(tgt, m=j, scl=2), m=j, scl=.5)
|
| 330 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 331 |
+
|
| 332 |
+
def test_lagder_axis(self):
|
| 333 |
+
# check that axis keyword works
|
| 334 |
+
c2d = np.random.random((3, 4))
|
| 335 |
+
|
| 336 |
+
tgt = np.vstack([lag.lagder(c) for c in c2d.T]).T
|
| 337 |
+
res = lag.lagder(c2d, axis=0)
|
| 338 |
+
assert_almost_equal(res, tgt)
|
| 339 |
+
|
| 340 |
+
tgt = np.vstack([lag.lagder(c) for c in c2d])
|
| 341 |
+
res = lag.lagder(c2d, axis=1)
|
| 342 |
+
assert_almost_equal(res, tgt)
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class TestVander:
|
| 346 |
+
# some random values in [-1, 1)
|
| 347 |
+
x = np.random.random((3, 5))*2 - 1
|
| 348 |
+
|
| 349 |
+
def test_lagvander(self):
|
| 350 |
+
# check for 1d x
|
| 351 |
+
x = np.arange(3)
|
| 352 |
+
v = lag.lagvander(x, 3)
|
| 353 |
+
assert_(v.shape == (3, 4))
|
| 354 |
+
for i in range(4):
|
| 355 |
+
coef = [0]*i + [1]
|
| 356 |
+
assert_almost_equal(v[..., i], lag.lagval(x, coef))
|
| 357 |
+
|
| 358 |
+
# check for 2d x
|
| 359 |
+
x = np.array([[1, 2], [3, 4], [5, 6]])
|
| 360 |
+
v = lag.lagvander(x, 3)
|
| 361 |
+
assert_(v.shape == (3, 2, 4))
|
| 362 |
+
for i in range(4):
|
| 363 |
+
coef = [0]*i + [1]
|
| 364 |
+
assert_almost_equal(v[..., i], lag.lagval(x, coef))
|
| 365 |
+
|
| 366 |
+
def test_lagvander2d(self):
|
| 367 |
+
# also tests lagval2d for non-square coefficient array
|
| 368 |
+
x1, x2, x3 = self.x
|
| 369 |
+
c = np.random.random((2, 3))
|
| 370 |
+
van = lag.lagvander2d(x1, x2, [1, 2])
|
| 371 |
+
tgt = lag.lagval2d(x1, x2, c)
|
| 372 |
+
res = np.dot(van, c.flat)
|
| 373 |
+
assert_almost_equal(res, tgt)
|
| 374 |
+
|
| 375 |
+
# check shape
|
| 376 |
+
van = lag.lagvander2d([x1], [x2], [1, 2])
|
| 377 |
+
assert_(van.shape == (1, 5, 6))
|
| 378 |
+
|
| 379 |
+
def test_lagvander3d(self):
|
| 380 |
+
# also tests lagval3d for non-square coefficient array
|
| 381 |
+
x1, x2, x3 = self.x
|
| 382 |
+
c = np.random.random((2, 3, 4))
|
| 383 |
+
van = lag.lagvander3d(x1, x2, x3, [1, 2, 3])
|
| 384 |
+
tgt = lag.lagval3d(x1, x2, x3, c)
|
| 385 |
+
res = np.dot(van, c.flat)
|
| 386 |
+
assert_almost_equal(res, tgt)
|
| 387 |
+
|
| 388 |
+
# check shape
|
| 389 |
+
van = lag.lagvander3d([x1], [x2], [x3], [1, 2, 3])
|
| 390 |
+
assert_(van.shape == (1, 5, 24))
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class TestFitting:
|
| 394 |
+
|
| 395 |
+
def test_lagfit(self):
|
| 396 |
+
def f(x):
|
| 397 |
+
return x*(x - 1)*(x - 2)
|
| 398 |
+
|
| 399 |
+
# Test exceptions
|
| 400 |
+
assert_raises(ValueError, lag.lagfit, [1], [1], -1)
|
| 401 |
+
assert_raises(TypeError, lag.lagfit, [[1]], [1], 0)
|
| 402 |
+
assert_raises(TypeError, lag.lagfit, [], [1], 0)
|
| 403 |
+
assert_raises(TypeError, lag.lagfit, [1], [[[1]]], 0)
|
| 404 |
+
assert_raises(TypeError, lag.lagfit, [1, 2], [1], 0)
|
| 405 |
+
assert_raises(TypeError, lag.lagfit, [1], [1, 2], 0)
|
| 406 |
+
assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[[1]])
|
| 407 |
+
assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[1, 1])
|
| 408 |
+
assert_raises(ValueError, lag.lagfit, [1], [1], [-1,])
|
| 409 |
+
assert_raises(ValueError, lag.lagfit, [1], [1], [2, -1, 6])
|
| 410 |
+
assert_raises(TypeError, lag.lagfit, [1], [1], [])
|
| 411 |
+
|
| 412 |
+
# Test fit
|
| 413 |
+
x = np.linspace(0, 2)
|
| 414 |
+
y = f(x)
|
| 415 |
+
#
|
| 416 |
+
coef3 = lag.lagfit(x, y, 3)
|
| 417 |
+
assert_equal(len(coef3), 4)
|
| 418 |
+
assert_almost_equal(lag.lagval(x, coef3), y)
|
| 419 |
+
coef3 = lag.lagfit(x, y, [0, 1, 2, 3])
|
| 420 |
+
assert_equal(len(coef3), 4)
|
| 421 |
+
assert_almost_equal(lag.lagval(x, coef3), y)
|
| 422 |
+
#
|
| 423 |
+
coef4 = lag.lagfit(x, y, 4)
|
| 424 |
+
assert_equal(len(coef4), 5)
|
| 425 |
+
assert_almost_equal(lag.lagval(x, coef4), y)
|
| 426 |
+
coef4 = lag.lagfit(x, y, [0, 1, 2, 3, 4])
|
| 427 |
+
assert_equal(len(coef4), 5)
|
| 428 |
+
assert_almost_equal(lag.lagval(x, coef4), y)
|
| 429 |
+
#
|
| 430 |
+
coef2d = lag.lagfit(x, np.array([y, y]).T, 3)
|
| 431 |
+
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
|
| 432 |
+
coef2d = lag.lagfit(x, np.array([y, y]).T, [0, 1, 2, 3])
|
| 433 |
+
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
|
| 434 |
+
# test weighting
|
| 435 |
+
w = np.zeros_like(x)
|
| 436 |
+
yw = y.copy()
|
| 437 |
+
w[1::2] = 1
|
| 438 |
+
y[0::2] = 0
|
| 439 |
+
wcoef3 = lag.lagfit(x, yw, 3, w=w)
|
| 440 |
+
assert_almost_equal(wcoef3, coef3)
|
| 441 |
+
wcoef3 = lag.lagfit(x, yw, [0, 1, 2, 3], w=w)
|
| 442 |
+
assert_almost_equal(wcoef3, coef3)
|
| 443 |
+
#
|
| 444 |
+
wcoef2d = lag.lagfit(x, np.array([yw, yw]).T, 3, w=w)
|
| 445 |
+
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
|
| 446 |
+
wcoef2d = lag.lagfit(x, np.array([yw, yw]).T, [0, 1, 2, 3], w=w)
|
| 447 |
+
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
|
| 448 |
+
# test scaling with complex values x points whose square
|
| 449 |
+
# is zero when summed.
|
| 450 |
+
x = [1, 1j, -1, -1j]
|
| 451 |
+
assert_almost_equal(lag.lagfit(x, x, 1), [1, -1])
|
| 452 |
+
assert_almost_equal(lag.lagfit(x, x, [0, 1]), [1, -1])
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
class TestCompanion:
|
| 456 |
+
|
| 457 |
+
def test_raises(self):
|
| 458 |
+
assert_raises(ValueError, lag.lagcompanion, [])
|
| 459 |
+
assert_raises(ValueError, lag.lagcompanion, [1])
|
| 460 |
+
|
| 461 |
+
def test_dimensions(self):
|
| 462 |
+
for i in range(1, 5):
|
| 463 |
+
coef = [0]*i + [1]
|
| 464 |
+
assert_(lag.lagcompanion(coef).shape == (i, i))
|
| 465 |
+
|
| 466 |
+
def test_linear_root(self):
|
| 467 |
+
assert_(lag.lagcompanion([1, 2])[0, 0] == 1.5)
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
class TestGauss:
|
| 471 |
+
|
| 472 |
+
def test_100(self):
|
| 473 |
+
x, w = lag.laggauss(100)
|
| 474 |
+
|
| 475 |
+
# test orthogonality. Note that the results need to be normalized,
|
| 476 |
+
# otherwise the huge values that can arise from fast growing
|
| 477 |
+
# functions like Laguerre can be very confusing.
|
| 478 |
+
v = lag.lagvander(x, 99)
|
| 479 |
+
vv = np.dot(v.T * w, v)
|
| 480 |
+
vd = 1/np.sqrt(vv.diagonal())
|
| 481 |
+
vv = vd[:, None] * vv * vd
|
| 482 |
+
assert_almost_equal(vv, np.eye(100))
|
| 483 |
+
|
| 484 |
+
# check that the integral of 1 is correct
|
| 485 |
+
tgt = 1.0
|
| 486 |
+
assert_almost_equal(w.sum(), tgt)
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
class TestMisc:
|
| 490 |
+
|
| 491 |
+
def test_lagfromroots(self):
|
| 492 |
+
res = lag.lagfromroots([])
|
| 493 |
+
assert_almost_equal(trim(res), [1])
|
| 494 |
+
for i in range(1, 5):
|
| 495 |
+
roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
|
| 496 |
+
pol = lag.lagfromroots(roots)
|
| 497 |
+
res = lag.lagval(roots, pol)
|
| 498 |
+
tgt = 0
|
| 499 |
+
assert_(len(pol) == i + 1)
|
| 500 |
+
assert_almost_equal(lag.lag2poly(pol)[-1], 1)
|
| 501 |
+
assert_almost_equal(res, tgt)
|
| 502 |
+
|
| 503 |
+
def test_lagroots(self):
|
| 504 |
+
assert_almost_equal(lag.lagroots([1]), [])
|
| 505 |
+
assert_almost_equal(lag.lagroots([0, 1]), [1])
|
| 506 |
+
for i in range(2, 5):
|
| 507 |
+
tgt = np.linspace(0, 3, i)
|
| 508 |
+
res = lag.lagroots(lag.lagfromroots(tgt))
|
| 509 |
+
assert_almost_equal(trim(res), trim(tgt))
|
| 510 |
+
|
| 511 |
+
def test_lagtrim(self):
|
| 512 |
+
coef = [2, -1, 1, 0]
|
| 513 |
+
|
| 514 |
+
# Test exceptions
|
| 515 |
+
assert_raises(ValueError, lag.lagtrim, coef, -1)
|
| 516 |
+
|
| 517 |
+
# Test results
|
| 518 |
+
assert_equal(lag.lagtrim(coef), coef[:-1])
|
| 519 |
+
assert_equal(lag.lagtrim(coef, 1), coef[:-3])
|
| 520 |
+
assert_equal(lag.lagtrim(coef, 2), [0])
|
| 521 |
+
|
| 522 |
+
def test_lagline(self):
|
| 523 |
+
assert_equal(lag.lagline(3, 4), [7, -4])
|
| 524 |
+
|
| 525 |
+
def test_lag2poly(self):
|
| 526 |
+
for i in range(7):
|
| 527 |
+
assert_almost_equal(lag.lag2poly([0]*i + [1]), Llist[i])
|
| 528 |
+
|
| 529 |
+
def test_poly2lag(self):
|
| 530 |
+
for i in range(7):
|
| 531 |
+
assert_almost_equal(lag.poly2lag(Llist[i]), [0]*i + [1])
|
| 532 |
+
|
| 533 |
+
def test_weight(self):
|
| 534 |
+
x = np.linspace(0, 10, 11)
|
| 535 |
+
tgt = np.exp(-x)
|
| 536 |
+
res = lag.lagweight(x)
|
| 537 |
+
assert_almost_equal(res, tgt)
|
parrot/lib/python3.10/site-packages/numpy/random/__init__.pxd
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cimport numpy as np
|
| 2 |
+
from libc.stdint cimport uint32_t, uint64_t
|
| 3 |
+
|
| 4 |
+
cdef extern from "numpy/random/bitgen.h":
|
| 5 |
+
struct bitgen:
|
| 6 |
+
void *state
|
| 7 |
+
uint64_t (*next_uint64)(void *st) nogil
|
| 8 |
+
uint32_t (*next_uint32)(void *st) nogil
|
| 9 |
+
double (*next_double)(void *st) nogil
|
| 10 |
+
uint64_t (*next_raw)(void *st) nogil
|
| 11 |
+
|
| 12 |
+
ctypedef bitgen bitgen_t
|
| 13 |
+
|
| 14 |
+
from numpy.random.bit_generator cimport BitGenerator, SeedSequence
|
parrot/lib/python3.10/site-packages/numpy/random/__init__.pyi
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numpy._pytesttester import PytestTester
|
| 2 |
+
|
| 3 |
+
from numpy.random._generator import Generator as Generator
|
| 4 |
+
from numpy.random._generator import default_rng as default_rng
|
| 5 |
+
from numpy.random._mt19937 import MT19937 as MT19937
|
| 6 |
+
from numpy.random._pcg64 import (
|
| 7 |
+
PCG64 as PCG64,
|
| 8 |
+
PCG64DXSM as PCG64DXSM,
|
| 9 |
+
)
|
| 10 |
+
from numpy.random._philox import Philox as Philox
|
| 11 |
+
from numpy.random._sfc64 import SFC64 as SFC64
|
| 12 |
+
from numpy.random.bit_generator import BitGenerator as BitGenerator
|
| 13 |
+
from numpy.random.bit_generator import SeedSequence as SeedSequence
|
| 14 |
+
from numpy.random.mtrand import (
|
| 15 |
+
RandomState as RandomState,
|
| 16 |
+
beta as beta,
|
| 17 |
+
binomial as binomial,
|
| 18 |
+
bytes as bytes,
|
| 19 |
+
chisquare as chisquare,
|
| 20 |
+
choice as choice,
|
| 21 |
+
dirichlet as dirichlet,
|
| 22 |
+
exponential as exponential,
|
| 23 |
+
f as f,
|
| 24 |
+
gamma as gamma,
|
| 25 |
+
geometric as geometric,
|
| 26 |
+
get_bit_generator as get_bit_generator,
|
| 27 |
+
get_state as get_state,
|
| 28 |
+
gumbel as gumbel,
|
| 29 |
+
hypergeometric as hypergeometric,
|
| 30 |
+
laplace as laplace,
|
| 31 |
+
logistic as logistic,
|
| 32 |
+
lognormal as lognormal,
|
| 33 |
+
logseries as logseries,
|
| 34 |
+
multinomial as multinomial,
|
| 35 |
+
multivariate_normal as multivariate_normal,
|
| 36 |
+
negative_binomial as negative_binomial,
|
| 37 |
+
noncentral_chisquare as noncentral_chisquare,
|
| 38 |
+
noncentral_f as noncentral_f,
|
| 39 |
+
normal as normal,
|
| 40 |
+
pareto as pareto,
|
| 41 |
+
permutation as permutation,
|
| 42 |
+
poisson as poisson,
|
| 43 |
+
power as power,
|
| 44 |
+
rand as rand,
|
| 45 |
+
randint as randint,
|
| 46 |
+
randn as randn,
|
| 47 |
+
random as random,
|
| 48 |
+
random_integers as random_integers,
|
| 49 |
+
random_sample as random_sample,
|
| 50 |
+
ranf as ranf,
|
| 51 |
+
rayleigh as rayleigh,
|
| 52 |
+
sample as sample,
|
| 53 |
+
seed as seed,
|
| 54 |
+
set_bit_generator as set_bit_generator,
|
| 55 |
+
set_state as set_state,
|
| 56 |
+
shuffle as shuffle,
|
| 57 |
+
standard_cauchy as standard_cauchy,
|
| 58 |
+
standard_exponential as standard_exponential,
|
| 59 |
+
standard_gamma as standard_gamma,
|
| 60 |
+
standard_normal as standard_normal,
|
| 61 |
+
standard_t as standard_t,
|
| 62 |
+
triangular as triangular,
|
| 63 |
+
uniform as uniform,
|
| 64 |
+
vonmises as vonmises,
|
| 65 |
+
wald as wald,
|
| 66 |
+
weibull as weibull,
|
| 67 |
+
zipf as zipf,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
__all__: list[str]
|
| 71 |
+
test: PytestTester
|
parrot/lib/python3.10/site-packages/numpy/random/_bounded_integers.pxd
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from libc.stdint cimport (uint8_t, uint16_t, uint32_t, uint64_t,
|
| 2 |
+
int8_t, int16_t, int32_t, int64_t, intptr_t)
|
| 3 |
+
import numpy as np
|
| 4 |
+
cimport numpy as np
|
| 5 |
+
ctypedef np.npy_bool bool_t
|
| 6 |
+
|
| 7 |
+
from numpy.random cimport bitgen_t
|
| 8 |
+
|
| 9 |
+
cdef inline uint64_t _gen_mask(uint64_t max_val) noexcept nogil:
|
| 10 |
+
"""Mask generator for use in bounded random numbers"""
|
| 11 |
+
# Smallest bit mask >= max
|
| 12 |
+
cdef uint64_t mask = max_val
|
| 13 |
+
mask |= mask >> 1
|
| 14 |
+
mask |= mask >> 2
|
| 15 |
+
mask |= mask >> 4
|
| 16 |
+
mask |= mask >> 8
|
| 17 |
+
mask |= mask >> 16
|
| 18 |
+
mask |= mask >> 32
|
| 19 |
+
return mask
|
| 20 |
+
|
| 21 |
+
cdef object _rand_uint64(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 22 |
+
cdef object _rand_uint32(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 23 |
+
cdef object _rand_uint16(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 24 |
+
cdef object _rand_uint8(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 25 |
+
cdef object _rand_bool(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 26 |
+
cdef object _rand_int64(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 27 |
+
cdef object _rand_int32(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 28 |
+
cdef object _rand_int16(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 29 |
+
cdef object _rand_int8(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
parrot/lib/python3.10/site-packages/numpy/random/_generator.pyi
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable
|
| 2 |
+
from typing import Any, overload, TypeVar, Literal
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
from numpy import (
|
| 6 |
+
dtype,
|
| 7 |
+
float32,
|
| 8 |
+
float64,
|
| 9 |
+
int8,
|
| 10 |
+
int16,
|
| 11 |
+
int32,
|
| 12 |
+
int64,
|
| 13 |
+
int_,
|
| 14 |
+
uint,
|
| 15 |
+
uint8,
|
| 16 |
+
uint16,
|
| 17 |
+
uint32,
|
| 18 |
+
uint64,
|
| 19 |
+
)
|
| 20 |
+
from numpy.random import BitGenerator, SeedSequence
|
| 21 |
+
from numpy._typing import (
|
| 22 |
+
ArrayLike,
|
| 23 |
+
NDArray,
|
| 24 |
+
_ArrayLikeFloat_co,
|
| 25 |
+
_ArrayLikeInt_co,
|
| 26 |
+
_DoubleCodes,
|
| 27 |
+
_DTypeLikeBool,
|
| 28 |
+
_DTypeLikeInt,
|
| 29 |
+
_DTypeLikeUInt,
|
| 30 |
+
_Float32Codes,
|
| 31 |
+
_Float64Codes,
|
| 32 |
+
_FloatLike_co,
|
| 33 |
+
_Int8Codes,
|
| 34 |
+
_Int16Codes,
|
| 35 |
+
_Int32Codes,
|
| 36 |
+
_Int64Codes,
|
| 37 |
+
_IntCodes,
|
| 38 |
+
_ShapeLike,
|
| 39 |
+
_SingleCodes,
|
| 40 |
+
_SupportsDType,
|
| 41 |
+
_UInt8Codes,
|
| 42 |
+
_UInt16Codes,
|
| 43 |
+
_UInt32Codes,
|
| 44 |
+
_UInt64Codes,
|
| 45 |
+
_UIntCodes,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
|
| 49 |
+
|
| 50 |
+
_DTypeLikeFloat32 = (
|
| 51 |
+
dtype[float32]
|
| 52 |
+
| _SupportsDType[dtype[float32]]
|
| 53 |
+
| type[float32]
|
| 54 |
+
| _Float32Codes
|
| 55 |
+
| _SingleCodes
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
_DTypeLikeFloat64 = (
|
| 59 |
+
dtype[float64]
|
| 60 |
+
| _SupportsDType[dtype[float64]]
|
| 61 |
+
| type[float]
|
| 62 |
+
| type[float64]
|
| 63 |
+
| _Float64Codes
|
| 64 |
+
| _DoubleCodes
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
class Generator:
|
| 68 |
+
def __init__(self, bit_generator: BitGenerator) -> None: ...
|
| 69 |
+
def __repr__(self) -> str: ...
|
| 70 |
+
def __str__(self) -> str: ...
|
| 71 |
+
def __getstate__(self) -> None: ...
|
| 72 |
+
def __setstate__(self, state: dict[str, Any] | None) -> None: ...
|
| 73 |
+
def __reduce__(self) -> tuple[
|
| 74 |
+
Callable[[BitGenerator], Generator],
|
| 75 |
+
tuple[BitGenerator],
|
| 76 |
+
None]: ...
|
| 77 |
+
@property
|
| 78 |
+
def bit_generator(self) -> BitGenerator: ...
|
| 79 |
+
def spawn(self, n_children: int) -> list[Generator]: ...
|
| 80 |
+
def bytes(self, length: int) -> bytes: ...
|
| 81 |
+
@overload
|
| 82 |
+
def standard_normal( # type: ignore[misc]
|
| 83 |
+
self,
|
| 84 |
+
size: None = ...,
|
| 85 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 86 |
+
out: None = ...,
|
| 87 |
+
) -> float: ...
|
| 88 |
+
@overload
|
| 89 |
+
def standard_normal( # type: ignore[misc]
|
| 90 |
+
self,
|
| 91 |
+
size: _ShapeLike = ...,
|
| 92 |
+
) -> NDArray[float64]: ...
|
| 93 |
+
@overload
|
| 94 |
+
def standard_normal( # type: ignore[misc]
|
| 95 |
+
self,
|
| 96 |
+
*,
|
| 97 |
+
out: NDArray[float64] = ...,
|
| 98 |
+
) -> NDArray[float64]: ...
|
| 99 |
+
@overload
|
| 100 |
+
def standard_normal( # type: ignore[misc]
|
| 101 |
+
self,
|
| 102 |
+
size: _ShapeLike = ...,
|
| 103 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 104 |
+
out: None | NDArray[float32] = ...,
|
| 105 |
+
) -> NDArray[float32]: ...
|
| 106 |
+
@overload
|
| 107 |
+
def standard_normal( # type: ignore[misc]
|
| 108 |
+
self,
|
| 109 |
+
size: _ShapeLike = ...,
|
| 110 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 111 |
+
out: None | NDArray[float64] = ...,
|
| 112 |
+
) -> NDArray[float64]: ...
|
| 113 |
+
@overload
|
| 114 |
+
def permutation(self, x: int, axis: int = ...) -> NDArray[int64]: ...
|
| 115 |
+
@overload
|
| 116 |
+
def permutation(self, x: ArrayLike, axis: int = ...) -> NDArray[Any]: ...
|
| 117 |
+
@overload
|
| 118 |
+
def standard_exponential( # type: ignore[misc]
|
| 119 |
+
self,
|
| 120 |
+
size: None = ...,
|
| 121 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 122 |
+
method: Literal["zig", "inv"] = ...,
|
| 123 |
+
out: None = ...,
|
| 124 |
+
) -> float: ...
|
| 125 |
+
@overload
|
| 126 |
+
def standard_exponential(
|
| 127 |
+
self,
|
| 128 |
+
size: _ShapeLike = ...,
|
| 129 |
+
) -> NDArray[float64]: ...
|
| 130 |
+
@overload
|
| 131 |
+
def standard_exponential(
|
| 132 |
+
self,
|
| 133 |
+
*,
|
| 134 |
+
out: NDArray[float64] = ...,
|
| 135 |
+
) -> NDArray[float64]: ...
|
| 136 |
+
@overload
|
| 137 |
+
def standard_exponential(
|
| 138 |
+
self,
|
| 139 |
+
size: _ShapeLike = ...,
|
| 140 |
+
*,
|
| 141 |
+
method: Literal["zig", "inv"] = ...,
|
| 142 |
+
out: None | NDArray[float64] = ...,
|
| 143 |
+
) -> NDArray[float64]: ...
|
| 144 |
+
@overload
|
| 145 |
+
def standard_exponential(
|
| 146 |
+
self,
|
| 147 |
+
size: _ShapeLike = ...,
|
| 148 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 149 |
+
method: Literal["zig", "inv"] = ...,
|
| 150 |
+
out: None | NDArray[float32] = ...,
|
| 151 |
+
) -> NDArray[float32]: ...
|
| 152 |
+
@overload
|
| 153 |
+
def standard_exponential(
|
| 154 |
+
self,
|
| 155 |
+
size: _ShapeLike = ...,
|
| 156 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 157 |
+
method: Literal["zig", "inv"] = ...,
|
| 158 |
+
out: None | NDArray[float64] = ...,
|
| 159 |
+
) -> NDArray[float64]: ...
|
| 160 |
+
@overload
|
| 161 |
+
def random( # type: ignore[misc]
|
| 162 |
+
self,
|
| 163 |
+
size: None = ...,
|
| 164 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 165 |
+
out: None = ...,
|
| 166 |
+
) -> float: ...
|
| 167 |
+
@overload
|
| 168 |
+
def random(
|
| 169 |
+
self,
|
| 170 |
+
*,
|
| 171 |
+
out: NDArray[float64] = ...,
|
| 172 |
+
) -> NDArray[float64]: ...
|
| 173 |
+
@overload
|
| 174 |
+
def random(
|
| 175 |
+
self,
|
| 176 |
+
size: _ShapeLike = ...,
|
| 177 |
+
*,
|
| 178 |
+
out: None | NDArray[float64] = ...,
|
| 179 |
+
) -> NDArray[float64]: ...
|
| 180 |
+
@overload
|
| 181 |
+
def random(
|
| 182 |
+
self,
|
| 183 |
+
size: _ShapeLike = ...,
|
| 184 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 185 |
+
out: None | NDArray[float32] = ...,
|
| 186 |
+
) -> NDArray[float32]: ...
|
| 187 |
+
@overload
|
| 188 |
+
def random(
|
| 189 |
+
self,
|
| 190 |
+
size: _ShapeLike = ...,
|
| 191 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 192 |
+
out: None | NDArray[float64] = ...,
|
| 193 |
+
) -> NDArray[float64]: ...
|
| 194 |
+
@overload
|
| 195 |
+
def beta(
|
| 196 |
+
self,
|
| 197 |
+
a: _FloatLike_co,
|
| 198 |
+
b: _FloatLike_co,
|
| 199 |
+
size: None = ...,
|
| 200 |
+
) -> float: ... # type: ignore[misc]
|
| 201 |
+
@overload
|
| 202 |
+
def beta(
|
| 203 |
+
self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 204 |
+
) -> NDArray[float64]: ...
|
| 205 |
+
@overload
|
| 206 |
+
def exponential(self, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 207 |
+
@overload
|
| 208 |
+
def exponential(
|
| 209 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 210 |
+
) -> NDArray[float64]: ...
|
| 211 |
+
@overload
|
| 212 |
+
def integers( # type: ignore[misc]
|
| 213 |
+
self,
|
| 214 |
+
low: int,
|
| 215 |
+
high: None | int = ...,
|
| 216 |
+
size: None = ...,
|
| 217 |
+
) -> int: ...
|
| 218 |
+
@overload
|
| 219 |
+
def integers( # type: ignore[misc]
|
| 220 |
+
self,
|
| 221 |
+
low: int,
|
| 222 |
+
high: None | int = ...,
|
| 223 |
+
size: None = ...,
|
| 224 |
+
dtype: type[bool] = ...,
|
| 225 |
+
endpoint: bool = ...,
|
| 226 |
+
) -> bool: ...
|
| 227 |
+
@overload
|
| 228 |
+
def integers( # type: ignore[misc]
|
| 229 |
+
self,
|
| 230 |
+
low: int,
|
| 231 |
+
high: None | int = ...,
|
| 232 |
+
size: None = ...,
|
| 233 |
+
dtype: type[np.bool] = ...,
|
| 234 |
+
endpoint: bool = ...,
|
| 235 |
+
) -> np.bool: ...
|
| 236 |
+
@overload
|
| 237 |
+
def integers( # type: ignore[misc]
|
| 238 |
+
self,
|
| 239 |
+
low: int,
|
| 240 |
+
high: None | int = ...,
|
| 241 |
+
size: None = ...,
|
| 242 |
+
dtype: type[int] = ...,
|
| 243 |
+
endpoint: bool = ...,
|
| 244 |
+
) -> int: ...
|
| 245 |
+
@overload
|
| 246 |
+
def integers( # type: ignore[misc]
|
| 247 |
+
self,
|
| 248 |
+
low: int,
|
| 249 |
+
high: None | int = ...,
|
| 250 |
+
size: None = ...,
|
| 251 |
+
dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
|
| 252 |
+
endpoint: bool = ...,
|
| 253 |
+
) -> uint8: ...
|
| 254 |
+
@overload
|
| 255 |
+
def integers( # type: ignore[misc]
|
| 256 |
+
self,
|
| 257 |
+
low: int,
|
| 258 |
+
high: None | int = ...,
|
| 259 |
+
size: None = ...,
|
| 260 |
+
dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
|
| 261 |
+
endpoint: bool = ...,
|
| 262 |
+
) -> uint16: ...
|
| 263 |
+
@overload
|
| 264 |
+
def integers( # type: ignore[misc]
|
| 265 |
+
self,
|
| 266 |
+
low: int,
|
| 267 |
+
high: None | int = ...,
|
| 268 |
+
size: None = ...,
|
| 269 |
+
dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
|
| 270 |
+
endpoint: bool = ...,
|
| 271 |
+
) -> uint32: ...
|
| 272 |
+
@overload
|
| 273 |
+
def integers( # type: ignore[misc]
|
| 274 |
+
self,
|
| 275 |
+
low: int,
|
| 276 |
+
high: None | int = ...,
|
| 277 |
+
size: None = ...,
|
| 278 |
+
dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ...,
|
| 279 |
+
endpoint: bool = ...,
|
| 280 |
+
) -> uint: ...
|
| 281 |
+
@overload
|
| 282 |
+
def integers( # type: ignore[misc]
|
| 283 |
+
self,
|
| 284 |
+
low: int,
|
| 285 |
+
high: None | int = ...,
|
| 286 |
+
size: None = ...,
|
| 287 |
+
dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
|
| 288 |
+
endpoint: bool = ...,
|
| 289 |
+
) -> uint64: ...
|
| 290 |
+
@overload
|
| 291 |
+
def integers( # type: ignore[misc]
|
| 292 |
+
self,
|
| 293 |
+
low: int,
|
| 294 |
+
high: None | int = ...,
|
| 295 |
+
size: None = ...,
|
| 296 |
+
dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
|
| 297 |
+
endpoint: bool = ...,
|
| 298 |
+
) -> int8: ...
|
| 299 |
+
@overload
|
| 300 |
+
def integers( # type: ignore[misc]
|
| 301 |
+
self,
|
| 302 |
+
low: int,
|
| 303 |
+
high: None | int = ...,
|
| 304 |
+
size: None = ...,
|
| 305 |
+
dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
|
| 306 |
+
endpoint: bool = ...,
|
| 307 |
+
) -> int16: ...
|
| 308 |
+
@overload
|
| 309 |
+
def integers( # type: ignore[misc]
|
| 310 |
+
self,
|
| 311 |
+
low: int,
|
| 312 |
+
high: None | int = ...,
|
| 313 |
+
size: None = ...,
|
| 314 |
+
dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
|
| 315 |
+
endpoint: bool = ...,
|
| 316 |
+
) -> int32: ...
|
| 317 |
+
@overload
|
| 318 |
+
def integers( # type: ignore[misc]
|
| 319 |
+
self,
|
| 320 |
+
low: int,
|
| 321 |
+
high: None | int = ...,
|
| 322 |
+
size: None = ...,
|
| 323 |
+
dtype: dtype[int_] | type[int] | type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ...,
|
| 324 |
+
endpoint: bool = ...,
|
| 325 |
+
) -> int_: ...
|
| 326 |
+
@overload
|
| 327 |
+
def integers( # type: ignore[misc]
|
| 328 |
+
self,
|
| 329 |
+
low: int,
|
| 330 |
+
high: None | int = ...,
|
| 331 |
+
size: None = ...,
|
| 332 |
+
dtype: dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
|
| 333 |
+
endpoint: bool = ...,
|
| 334 |
+
) -> int64: ...
|
| 335 |
+
@overload
|
| 336 |
+
def integers( # type: ignore[misc]
|
| 337 |
+
self,
|
| 338 |
+
low: _ArrayLikeInt_co,
|
| 339 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 340 |
+
size: None | _ShapeLike = ...,
|
| 341 |
+
) -> NDArray[int64]: ...
|
| 342 |
+
@overload
|
| 343 |
+
def integers( # type: ignore[misc]
|
| 344 |
+
self,
|
| 345 |
+
low: _ArrayLikeInt_co,
|
| 346 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 347 |
+
size: None | _ShapeLike = ...,
|
| 348 |
+
dtype: _DTypeLikeBool = ...,
|
| 349 |
+
endpoint: bool = ...,
|
| 350 |
+
) -> NDArray[np.bool]: ...
|
| 351 |
+
@overload
|
| 352 |
+
def integers( # type: ignore[misc]
|
| 353 |
+
self,
|
| 354 |
+
low: _ArrayLikeInt_co,
|
| 355 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 356 |
+
size: None | _ShapeLike = ...,
|
| 357 |
+
dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
|
| 358 |
+
endpoint: bool = ...,
|
| 359 |
+
) -> NDArray[int8]: ...
|
| 360 |
+
@overload
|
| 361 |
+
def integers( # type: ignore[misc]
|
| 362 |
+
self,
|
| 363 |
+
low: _ArrayLikeInt_co,
|
| 364 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 365 |
+
size: None | _ShapeLike = ...,
|
| 366 |
+
dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
|
| 367 |
+
endpoint: bool = ...,
|
| 368 |
+
) -> NDArray[int16]: ...
|
| 369 |
+
@overload
|
| 370 |
+
def integers( # type: ignore[misc]
|
| 371 |
+
self,
|
| 372 |
+
low: _ArrayLikeInt_co,
|
| 373 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 374 |
+
size: None | _ShapeLike = ...,
|
| 375 |
+
dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
|
| 376 |
+
endpoint: bool = ...,
|
| 377 |
+
) -> NDArray[int32]: ...
|
| 378 |
+
@overload
|
| 379 |
+
def integers( # type: ignore[misc]
|
| 380 |
+
self,
|
| 381 |
+
low: _ArrayLikeInt_co,
|
| 382 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 383 |
+
size: None | _ShapeLike = ...,
|
| 384 |
+
dtype: None | dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
|
| 385 |
+
endpoint: bool = ...,
|
| 386 |
+
) -> NDArray[int64]: ...
|
| 387 |
+
@overload
|
| 388 |
+
def integers( # type: ignore[misc]
|
| 389 |
+
self,
|
| 390 |
+
low: _ArrayLikeInt_co,
|
| 391 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 392 |
+
size: None | _ShapeLike = ...,
|
| 393 |
+
dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
|
| 394 |
+
endpoint: bool = ...,
|
| 395 |
+
) -> NDArray[uint8]: ...
|
| 396 |
+
@overload
|
| 397 |
+
def integers( # type: ignore[misc]
|
| 398 |
+
self,
|
| 399 |
+
low: _ArrayLikeInt_co,
|
| 400 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 401 |
+
size: None | _ShapeLike = ...,
|
| 402 |
+
dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
|
| 403 |
+
endpoint: bool = ...,
|
| 404 |
+
) -> NDArray[uint16]: ...
|
| 405 |
+
@overload
|
| 406 |
+
def integers( # type: ignore[misc]
|
| 407 |
+
self,
|
| 408 |
+
low: _ArrayLikeInt_co,
|
| 409 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 410 |
+
size: None | _ShapeLike = ...,
|
| 411 |
+
dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
|
| 412 |
+
endpoint: bool = ...,
|
| 413 |
+
) -> NDArray[uint32]: ...
|
| 414 |
+
@overload
|
| 415 |
+
def integers( # type: ignore[misc]
|
| 416 |
+
self,
|
| 417 |
+
low: _ArrayLikeInt_co,
|
| 418 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 419 |
+
size: None | _ShapeLike = ...,
|
| 420 |
+
dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
|
| 421 |
+
endpoint: bool = ...,
|
| 422 |
+
) -> NDArray[uint64]: ...
|
| 423 |
+
@overload
|
| 424 |
+
def integers( # type: ignore[misc]
|
| 425 |
+
self,
|
| 426 |
+
low: _ArrayLikeInt_co,
|
| 427 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 428 |
+
size: None | _ShapeLike = ...,
|
| 429 |
+
dtype: dtype[int_] | type[int] | type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ...,
|
| 430 |
+
endpoint: bool = ...,
|
| 431 |
+
) -> NDArray[int_]: ...
|
| 432 |
+
@overload
|
| 433 |
+
def integers( # type: ignore[misc]
|
| 434 |
+
self,
|
| 435 |
+
low: _ArrayLikeInt_co,
|
| 436 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 437 |
+
size: None | _ShapeLike = ...,
|
| 438 |
+
dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ...,
|
| 439 |
+
endpoint: bool = ...,
|
| 440 |
+
) -> NDArray[uint]: ...
|
| 441 |
+
# TODO: Use a TypeVar _T here to get away from Any output? Should be int->NDArray[int64], ArrayLike[_T] -> _T | NDArray[Any]
|
| 442 |
+
@overload
|
| 443 |
+
def choice(
|
| 444 |
+
self,
|
| 445 |
+
a: int,
|
| 446 |
+
size: None = ...,
|
| 447 |
+
replace: bool = ...,
|
| 448 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 449 |
+
axis: int = ...,
|
| 450 |
+
shuffle: bool = ...,
|
| 451 |
+
) -> int: ...
|
| 452 |
+
@overload
|
| 453 |
+
def choice(
|
| 454 |
+
self,
|
| 455 |
+
a: int,
|
| 456 |
+
size: _ShapeLike = ...,
|
| 457 |
+
replace: bool = ...,
|
| 458 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 459 |
+
axis: int = ...,
|
| 460 |
+
shuffle: bool = ...,
|
| 461 |
+
) -> NDArray[int64]: ...
|
| 462 |
+
@overload
|
| 463 |
+
def choice(
|
| 464 |
+
self,
|
| 465 |
+
a: ArrayLike,
|
| 466 |
+
size: None = ...,
|
| 467 |
+
replace: bool = ...,
|
| 468 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 469 |
+
axis: int = ...,
|
| 470 |
+
shuffle: bool = ...,
|
| 471 |
+
) -> Any: ...
|
| 472 |
+
@overload
|
| 473 |
+
def choice(
|
| 474 |
+
self,
|
| 475 |
+
a: ArrayLike,
|
| 476 |
+
size: _ShapeLike = ...,
|
| 477 |
+
replace: bool = ...,
|
| 478 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 479 |
+
axis: int = ...,
|
| 480 |
+
shuffle: bool = ...,
|
| 481 |
+
) -> NDArray[Any]: ...
|
| 482 |
+
@overload
|
| 483 |
+
def uniform(
|
| 484 |
+
self,
|
| 485 |
+
low: _FloatLike_co = ...,
|
| 486 |
+
high: _FloatLike_co = ...,
|
| 487 |
+
size: None = ...,
|
| 488 |
+
) -> float: ... # type: ignore[misc]
|
| 489 |
+
@overload
|
| 490 |
+
def uniform(
|
| 491 |
+
self,
|
| 492 |
+
low: _ArrayLikeFloat_co = ...,
|
| 493 |
+
high: _ArrayLikeFloat_co = ...,
|
| 494 |
+
size: None | _ShapeLike = ...,
|
| 495 |
+
) -> NDArray[float64]: ...
|
| 496 |
+
@overload
|
| 497 |
+
def normal(
|
| 498 |
+
self,
|
| 499 |
+
loc: _FloatLike_co = ...,
|
| 500 |
+
scale: _FloatLike_co = ...,
|
| 501 |
+
size: None = ...,
|
| 502 |
+
) -> float: ... # type: ignore[misc]
|
| 503 |
+
@overload
|
| 504 |
+
def normal(
|
| 505 |
+
self,
|
| 506 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 507 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 508 |
+
size: None | _ShapeLike = ...,
|
| 509 |
+
) -> NDArray[float64]: ...
|
| 510 |
+
@overload
|
| 511 |
+
def standard_gamma( # type: ignore[misc]
|
| 512 |
+
self,
|
| 513 |
+
shape: _FloatLike_co,
|
| 514 |
+
size: None = ...,
|
| 515 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 516 |
+
out: None = ...,
|
| 517 |
+
) -> float: ...
|
| 518 |
+
@overload
|
| 519 |
+
def standard_gamma(
|
| 520 |
+
self,
|
| 521 |
+
shape: _ArrayLikeFloat_co,
|
| 522 |
+
size: None | _ShapeLike = ...,
|
| 523 |
+
) -> NDArray[float64]: ...
|
| 524 |
+
@overload
|
| 525 |
+
def standard_gamma(
|
| 526 |
+
self,
|
| 527 |
+
shape: _ArrayLikeFloat_co,
|
| 528 |
+
*,
|
| 529 |
+
out: NDArray[float64] = ...,
|
| 530 |
+
) -> NDArray[float64]: ...
|
| 531 |
+
@overload
|
| 532 |
+
def standard_gamma(
|
| 533 |
+
self,
|
| 534 |
+
shape: _ArrayLikeFloat_co,
|
| 535 |
+
size: None | _ShapeLike = ...,
|
| 536 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 537 |
+
out: None | NDArray[float32] = ...,
|
| 538 |
+
) -> NDArray[float32]: ...
|
| 539 |
+
@overload
|
| 540 |
+
def standard_gamma(
|
| 541 |
+
self,
|
| 542 |
+
shape: _ArrayLikeFloat_co,
|
| 543 |
+
size: None | _ShapeLike = ...,
|
| 544 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 545 |
+
out: None | NDArray[float64] = ...,
|
| 546 |
+
) -> NDArray[float64]: ...
|
| 547 |
+
@overload
|
| 548 |
+
def gamma(self, shape: _FloatLike_co, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 549 |
+
@overload
|
| 550 |
+
def gamma(
|
| 551 |
+
self,
|
| 552 |
+
shape: _ArrayLikeFloat_co,
|
| 553 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 554 |
+
size: None | _ShapeLike = ...,
|
| 555 |
+
) -> NDArray[float64]: ...
|
| 556 |
+
@overload
|
| 557 |
+
def f(self, dfnum: _FloatLike_co, dfden: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 558 |
+
@overload
|
| 559 |
+
def f(
|
| 560 |
+
self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 561 |
+
) -> NDArray[float64]: ...
|
| 562 |
+
@overload
|
| 563 |
+
def noncentral_f(self, dfnum: _FloatLike_co, dfden: _FloatLike_co, nonc: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 564 |
+
@overload
|
| 565 |
+
def noncentral_f(
|
| 566 |
+
self,
|
| 567 |
+
dfnum: _ArrayLikeFloat_co,
|
| 568 |
+
dfden: _ArrayLikeFloat_co,
|
| 569 |
+
nonc: _ArrayLikeFloat_co,
|
| 570 |
+
size: None | _ShapeLike = ...,
|
| 571 |
+
) -> NDArray[float64]: ...
|
| 572 |
+
@overload
|
| 573 |
+
def chisquare(self, df: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 574 |
+
@overload
|
| 575 |
+
def chisquare(
|
| 576 |
+
self, df: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 577 |
+
) -> NDArray[float64]: ...
|
| 578 |
+
@overload
|
| 579 |
+
def noncentral_chisquare(self, df: _FloatLike_co, nonc: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 580 |
+
@overload
|
| 581 |
+
def noncentral_chisquare(
|
| 582 |
+
self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 583 |
+
) -> NDArray[float64]: ...
|
| 584 |
+
@overload
|
| 585 |
+
def standard_t(self, df: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 586 |
+
@overload
|
| 587 |
+
def standard_t(
|
| 588 |
+
self, df: _ArrayLikeFloat_co, size: None = ...
|
| 589 |
+
) -> NDArray[float64]: ...
|
| 590 |
+
@overload
|
| 591 |
+
def standard_t(
|
| 592 |
+
self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...
|
| 593 |
+
) -> NDArray[float64]: ...
|
| 594 |
+
@overload
|
| 595 |
+
def vonmises(self, mu: _FloatLike_co, kappa: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 596 |
+
@overload
|
| 597 |
+
def vonmises(
|
| 598 |
+
self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 599 |
+
) -> NDArray[float64]: ...
|
| 600 |
+
@overload
|
| 601 |
+
def pareto(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 602 |
+
@overload
|
| 603 |
+
def pareto(
|
| 604 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 605 |
+
) -> NDArray[float64]: ...
|
| 606 |
+
@overload
|
| 607 |
+
def weibull(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 608 |
+
@overload
|
| 609 |
+
def weibull(
|
| 610 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 611 |
+
) -> NDArray[float64]: ...
|
| 612 |
+
@overload
|
| 613 |
+
def power(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 614 |
+
@overload
|
| 615 |
+
def power(
|
| 616 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 617 |
+
) -> NDArray[float64]: ...
|
| 618 |
+
@overload
|
| 619 |
+
def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 620 |
+
@overload
|
| 621 |
+
def standard_cauchy(self, size: _ShapeLike = ...) -> NDArray[float64]: ...
|
| 622 |
+
@overload
|
| 623 |
+
def laplace(
|
| 624 |
+
self,
|
| 625 |
+
loc: _FloatLike_co = ...,
|
| 626 |
+
scale: _FloatLike_co = ...,
|
| 627 |
+
size: None = ...,
|
| 628 |
+
) -> float: ... # type: ignore[misc]
|
| 629 |
+
@overload
|
| 630 |
+
def laplace(
|
| 631 |
+
self,
|
| 632 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 633 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 634 |
+
size: None | _ShapeLike = ...,
|
| 635 |
+
) -> NDArray[float64]: ...
|
| 636 |
+
@overload
|
| 637 |
+
def gumbel(
|
| 638 |
+
self,
|
| 639 |
+
loc: _FloatLike_co = ...,
|
| 640 |
+
scale: _FloatLike_co = ...,
|
| 641 |
+
size: None = ...,
|
| 642 |
+
) -> float: ... # type: ignore[misc]
|
| 643 |
+
@overload
|
| 644 |
+
def gumbel(
|
| 645 |
+
self,
|
| 646 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 647 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 648 |
+
size: None | _ShapeLike = ...,
|
| 649 |
+
) -> NDArray[float64]: ...
|
| 650 |
+
@overload
|
| 651 |
+
def logistic(
|
| 652 |
+
self,
|
| 653 |
+
loc: _FloatLike_co = ...,
|
| 654 |
+
scale: _FloatLike_co = ...,
|
| 655 |
+
size: None = ...,
|
| 656 |
+
) -> float: ... # type: ignore[misc]
|
| 657 |
+
@overload
|
| 658 |
+
def logistic(
|
| 659 |
+
self,
|
| 660 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 661 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 662 |
+
size: None | _ShapeLike = ...,
|
| 663 |
+
) -> NDArray[float64]: ...
|
| 664 |
+
@overload
|
| 665 |
+
def lognormal(
|
| 666 |
+
self,
|
| 667 |
+
mean: _FloatLike_co = ...,
|
| 668 |
+
sigma: _FloatLike_co = ...,
|
| 669 |
+
size: None = ...,
|
| 670 |
+
) -> float: ... # type: ignore[misc]
|
| 671 |
+
@overload
|
| 672 |
+
def lognormal(
|
| 673 |
+
self,
|
| 674 |
+
mean: _ArrayLikeFloat_co = ...,
|
| 675 |
+
sigma: _ArrayLikeFloat_co = ...,
|
| 676 |
+
size: None | _ShapeLike = ...,
|
| 677 |
+
) -> NDArray[float64]: ...
|
| 678 |
+
@overload
|
| 679 |
+
def rayleigh(self, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 680 |
+
@overload
|
| 681 |
+
def rayleigh(
|
| 682 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 683 |
+
) -> NDArray[float64]: ...
|
| 684 |
+
@overload
|
| 685 |
+
def wald(self, mean: _FloatLike_co, scale: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 686 |
+
@overload
|
| 687 |
+
def wald(
|
| 688 |
+
self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 689 |
+
) -> NDArray[float64]: ...
|
| 690 |
+
@overload
|
| 691 |
+
def triangular(
|
| 692 |
+
self,
|
| 693 |
+
left: _FloatLike_co,
|
| 694 |
+
mode: _FloatLike_co,
|
| 695 |
+
right: _FloatLike_co,
|
| 696 |
+
size: None = ...,
|
| 697 |
+
) -> float: ... # type: ignore[misc]
|
| 698 |
+
@overload
|
| 699 |
+
def triangular(
|
| 700 |
+
self,
|
| 701 |
+
left: _ArrayLikeFloat_co,
|
| 702 |
+
mode: _ArrayLikeFloat_co,
|
| 703 |
+
right: _ArrayLikeFloat_co,
|
| 704 |
+
size: None | _ShapeLike = ...,
|
| 705 |
+
) -> NDArray[float64]: ...
|
| 706 |
+
@overload
|
| 707 |
+
def binomial(self, n: int, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 708 |
+
@overload
|
| 709 |
+
def binomial(
|
| 710 |
+
self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 711 |
+
) -> NDArray[int64]: ...
|
| 712 |
+
@overload
|
| 713 |
+
def negative_binomial(self, n: _FloatLike_co, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 714 |
+
@overload
|
| 715 |
+
def negative_binomial(
|
| 716 |
+
self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 717 |
+
) -> NDArray[int64]: ...
|
| 718 |
+
@overload
|
| 719 |
+
def poisson(self, lam: _FloatLike_co = ..., size: None = ...) -> int: ... # type: ignore[misc]
|
| 720 |
+
@overload
|
| 721 |
+
def poisson(
|
| 722 |
+
self, lam: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 723 |
+
) -> NDArray[int64]: ...
|
| 724 |
+
@overload
|
| 725 |
+
def zipf(self, a: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 726 |
+
@overload
|
| 727 |
+
def zipf(
|
| 728 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 729 |
+
) -> NDArray[int64]: ...
|
| 730 |
+
@overload
|
| 731 |
+
def geometric(self, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 732 |
+
@overload
|
| 733 |
+
def geometric(
|
| 734 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 735 |
+
) -> NDArray[int64]: ...
|
| 736 |
+
@overload
|
| 737 |
+
def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc]
|
| 738 |
+
@overload
|
| 739 |
+
def hypergeometric(
|
| 740 |
+
self,
|
| 741 |
+
ngood: _ArrayLikeInt_co,
|
| 742 |
+
nbad: _ArrayLikeInt_co,
|
| 743 |
+
nsample: _ArrayLikeInt_co,
|
| 744 |
+
size: None | _ShapeLike = ...,
|
| 745 |
+
) -> NDArray[int64]: ...
|
| 746 |
+
@overload
|
| 747 |
+
def logseries(self, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 748 |
+
@overload
|
| 749 |
+
def logseries(
|
| 750 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 751 |
+
) -> NDArray[int64]: ...
|
| 752 |
+
def multivariate_normal(
|
| 753 |
+
self,
|
| 754 |
+
mean: _ArrayLikeFloat_co,
|
| 755 |
+
cov: _ArrayLikeFloat_co,
|
| 756 |
+
size: None | _ShapeLike = ...,
|
| 757 |
+
check_valid: Literal["warn", "raise", "ignore"] = ...,
|
| 758 |
+
tol: float = ...,
|
| 759 |
+
*,
|
| 760 |
+
method: Literal["svd", "eigh", "cholesky"] = ...,
|
| 761 |
+
) -> NDArray[float64]: ...
|
| 762 |
+
def multinomial(
|
| 763 |
+
self, n: _ArrayLikeInt_co,
|
| 764 |
+
pvals: _ArrayLikeFloat_co,
|
| 765 |
+
size: None | _ShapeLike = ...
|
| 766 |
+
) -> NDArray[int64]: ...
|
| 767 |
+
def multivariate_hypergeometric(
|
| 768 |
+
self,
|
| 769 |
+
colors: _ArrayLikeInt_co,
|
| 770 |
+
nsample: int,
|
| 771 |
+
size: None | _ShapeLike = ...,
|
| 772 |
+
method: Literal["marginals", "count"] = ...,
|
| 773 |
+
) -> NDArray[int64]: ...
|
| 774 |
+
def dirichlet(
|
| 775 |
+
self, alpha: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 776 |
+
) -> NDArray[float64]: ...
|
| 777 |
+
def permuted(
|
| 778 |
+
self, x: ArrayLike, *, axis: None | int = ..., out: None | NDArray[Any] = ...
|
| 779 |
+
) -> NDArray[Any]: ...
|
| 780 |
+
def shuffle(self, x: ArrayLike, axis: int = ...) -> None: ...
|
| 781 |
+
|
| 782 |
+
def default_rng(
|
| 783 |
+
seed: None | _ArrayLikeInt_co | SeedSequence | BitGenerator | Generator = ...
|
| 784 |
+
) -> Generator: ...
|
parrot/lib/python3.10/site-packages/numpy/random/bit_generator.pxd
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cimport numpy as np
|
| 2 |
+
from libc.stdint cimport uint32_t, uint64_t
|
| 3 |
+
|
| 4 |
+
cdef extern from "numpy/random/bitgen.h":
|
| 5 |
+
struct bitgen:
|
| 6 |
+
void *state
|
| 7 |
+
uint64_t (*next_uint64)(void *st) nogil
|
| 8 |
+
uint32_t (*next_uint32)(void *st) nogil
|
| 9 |
+
double (*next_double)(void *st) nogil
|
| 10 |
+
uint64_t (*next_raw)(void *st) nogil
|
| 11 |
+
|
| 12 |
+
ctypedef bitgen bitgen_t
|
| 13 |
+
|
| 14 |
+
cdef class BitGenerator():
|
| 15 |
+
cdef readonly object _seed_seq
|
| 16 |
+
cdef readonly object lock
|
| 17 |
+
cdef bitgen_t _bitgen
|
| 18 |
+
cdef readonly object _ctypes
|
| 19 |
+
cdef readonly object _cffi
|
| 20 |
+
cdef readonly object capsule
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
cdef class SeedSequence():
|
| 24 |
+
cdef readonly object entropy
|
| 25 |
+
cdef readonly tuple spawn_key
|
| 26 |
+
cdef readonly Py_ssize_t pool_size
|
| 27 |
+
cdef readonly object pool
|
| 28 |
+
cdef readonly uint32_t n_children_spawned
|
| 29 |
+
|
| 30 |
+
cdef mix_entropy(self, np.ndarray[np.npy_uint32, ndim=1] mixer,
|
| 31 |
+
np.ndarray[np.npy_uint32, ndim=1] entropy_array)
|
| 32 |
+
cdef get_assembled_entropy(self)
|
| 33 |
+
|
| 34 |
+
cdef class SeedlessSequence():
|
| 35 |
+
pass
|
parrot/lib/python3.10/site-packages/numpy/random/bit_generator.pyi
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import abc
|
| 2 |
+
from threading import Lock
|
| 3 |
+
from collections.abc import Callable, Mapping, Sequence
|
| 4 |
+
from typing import (
|
| 5 |
+
Any,
|
| 6 |
+
NamedTuple,
|
| 7 |
+
TypedDict,
|
| 8 |
+
TypeVar,
|
| 9 |
+
overload,
|
| 10 |
+
Literal,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
from numpy import dtype, uint32, uint64
|
| 14 |
+
from numpy._typing import (
|
| 15 |
+
NDArray,
|
| 16 |
+
_ArrayLikeInt_co,
|
| 17 |
+
_ShapeLike,
|
| 18 |
+
_SupportsDType,
|
| 19 |
+
_UInt32Codes,
|
| 20 |
+
_UInt64Codes,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
_T = TypeVar("_T")
|
| 24 |
+
|
| 25 |
+
_DTypeLikeUint32 = (
|
| 26 |
+
dtype[uint32]
|
| 27 |
+
| _SupportsDType[dtype[uint32]]
|
| 28 |
+
| type[uint32]
|
| 29 |
+
| _UInt32Codes
|
| 30 |
+
)
|
| 31 |
+
_DTypeLikeUint64 = (
|
| 32 |
+
dtype[uint64]
|
| 33 |
+
| _SupportsDType[dtype[uint64]]
|
| 34 |
+
| type[uint64]
|
| 35 |
+
| _UInt64Codes
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
class _SeedSeqState(TypedDict):
|
| 39 |
+
entropy: None | int | Sequence[int]
|
| 40 |
+
spawn_key: tuple[int, ...]
|
| 41 |
+
pool_size: int
|
| 42 |
+
n_children_spawned: int
|
| 43 |
+
|
| 44 |
+
class _Interface(NamedTuple):
|
| 45 |
+
state_address: Any
|
| 46 |
+
state: Any
|
| 47 |
+
next_uint64: Any
|
| 48 |
+
next_uint32: Any
|
| 49 |
+
next_double: Any
|
| 50 |
+
bit_generator: Any
|
| 51 |
+
|
| 52 |
+
class ISeedSequence(abc.ABC):
|
| 53 |
+
@abc.abstractmethod
|
| 54 |
+
def generate_state(
|
| 55 |
+
self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
|
| 56 |
+
) -> NDArray[uint32 | uint64]: ...
|
| 57 |
+
|
| 58 |
+
class ISpawnableSeedSequence(ISeedSequence):
|
| 59 |
+
@abc.abstractmethod
|
| 60 |
+
def spawn(self: _T, n_children: int) -> list[_T]: ...
|
| 61 |
+
|
| 62 |
+
class SeedlessSeedSequence(ISpawnableSeedSequence):
|
| 63 |
+
def generate_state(
|
| 64 |
+
self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
|
| 65 |
+
) -> NDArray[uint32 | uint64]: ...
|
| 66 |
+
def spawn(self: _T, n_children: int) -> list[_T]: ...
|
| 67 |
+
|
| 68 |
+
class SeedSequence(ISpawnableSeedSequence):
|
| 69 |
+
entropy: None | int | Sequence[int]
|
| 70 |
+
spawn_key: tuple[int, ...]
|
| 71 |
+
pool_size: int
|
| 72 |
+
n_children_spawned: int
|
| 73 |
+
pool: NDArray[uint32]
|
| 74 |
+
def __init__(
|
| 75 |
+
self,
|
| 76 |
+
entropy: None | int | Sequence[int] | _ArrayLikeInt_co = ...,
|
| 77 |
+
*,
|
| 78 |
+
spawn_key: Sequence[int] = ...,
|
| 79 |
+
pool_size: int = ...,
|
| 80 |
+
n_children_spawned: int = ...,
|
| 81 |
+
) -> None: ...
|
| 82 |
+
def __repr__(self) -> str: ...
|
| 83 |
+
@property
|
| 84 |
+
def state(
|
| 85 |
+
self,
|
| 86 |
+
) -> _SeedSeqState: ...
|
| 87 |
+
def generate_state(
|
| 88 |
+
self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
|
| 89 |
+
) -> NDArray[uint32 | uint64]: ...
|
| 90 |
+
def spawn(self, n_children: int) -> list[SeedSequence]: ...
|
| 91 |
+
|
| 92 |
+
class BitGenerator(abc.ABC):
|
| 93 |
+
lock: Lock
|
| 94 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 95 |
+
def __getstate__(self) -> tuple[dict[str, Any], ISeedSequence]: ...
|
| 96 |
+
def __setstate__(
|
| 97 |
+
self, state_seed_seq: dict[str, Any] | tuple[dict[str, Any], ISeedSequence]
|
| 98 |
+
) -> None: ...
|
| 99 |
+
def __reduce__(
|
| 100 |
+
self,
|
| 101 |
+
) -> tuple[
|
| 102 |
+
Callable[[str], BitGenerator],
|
| 103 |
+
tuple[str],
|
| 104 |
+
tuple[dict[str, Any], ISeedSequence]
|
| 105 |
+
]: ...
|
| 106 |
+
@abc.abstractmethod
|
| 107 |
+
@property
|
| 108 |
+
def state(self) -> Mapping[str, Any]: ...
|
| 109 |
+
@state.setter
|
| 110 |
+
def state(self, value: Mapping[str, Any]) -> None: ...
|
| 111 |
+
@property
|
| 112 |
+
def seed_seq(self) -> ISeedSequence: ...
|
| 113 |
+
def spawn(self, n_children: int) -> list[BitGenerator]: ...
|
| 114 |
+
@overload
|
| 115 |
+
def random_raw(self, size: None = ..., output: Literal[True] = ...) -> int: ... # type: ignore[misc]
|
| 116 |
+
@overload
|
| 117 |
+
def random_raw(self, size: _ShapeLike = ..., output: Literal[True] = ...) -> NDArray[uint64]: ... # type: ignore[misc]
|
| 118 |
+
@overload
|
| 119 |
+
def random_raw(self, size: None | _ShapeLike = ..., output: Literal[False] = ...) -> None: ... # type: ignore[misc]
|
| 120 |
+
def _benchmark(self, cnt: int, method: str = ...) -> None: ...
|
| 121 |
+
@property
|
| 122 |
+
def ctypes(self) -> _Interface: ...
|
| 123 |
+
@property
|
| 124 |
+
def cffi(self) -> _Interface: ...
|
parrot/lib/python3.10/site-packages/numpy/random/mtrand.pyi
ADDED
|
@@ -0,0 +1,681 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import builtins
|
| 2 |
+
from collections.abc import Callable
|
| 3 |
+
from typing import Any, overload, Literal
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
from numpy import (
|
| 7 |
+
dtype,
|
| 8 |
+
float32,
|
| 9 |
+
float64,
|
| 10 |
+
int8,
|
| 11 |
+
int16,
|
| 12 |
+
int32,
|
| 13 |
+
int64,
|
| 14 |
+
int_,
|
| 15 |
+
long,
|
| 16 |
+
uint8,
|
| 17 |
+
uint16,
|
| 18 |
+
uint32,
|
| 19 |
+
uint64,
|
| 20 |
+
uint,
|
| 21 |
+
ulong,
|
| 22 |
+
)
|
| 23 |
+
from numpy.random.bit_generator import BitGenerator
|
| 24 |
+
from numpy._typing import (
|
| 25 |
+
ArrayLike,
|
| 26 |
+
NDArray,
|
| 27 |
+
_ArrayLikeFloat_co,
|
| 28 |
+
_ArrayLikeInt_co,
|
| 29 |
+
_DoubleCodes,
|
| 30 |
+
_DTypeLikeBool,
|
| 31 |
+
_DTypeLikeInt,
|
| 32 |
+
_DTypeLikeUInt,
|
| 33 |
+
_Float32Codes,
|
| 34 |
+
_Float64Codes,
|
| 35 |
+
_Int8Codes,
|
| 36 |
+
_Int16Codes,
|
| 37 |
+
_Int32Codes,
|
| 38 |
+
_Int64Codes,
|
| 39 |
+
_IntCodes,
|
| 40 |
+
_LongCodes,
|
| 41 |
+
_ShapeLike,
|
| 42 |
+
_SingleCodes,
|
| 43 |
+
_SupportsDType,
|
| 44 |
+
_UInt8Codes,
|
| 45 |
+
_UInt16Codes,
|
| 46 |
+
_UInt32Codes,
|
| 47 |
+
_UInt64Codes,
|
| 48 |
+
_UIntCodes,
|
| 49 |
+
_ULongCodes,
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
_DTypeLikeFloat32 = (
|
| 53 |
+
dtype[float32]
|
| 54 |
+
| _SupportsDType[dtype[float32]]
|
| 55 |
+
| type[float32]
|
| 56 |
+
| _Float32Codes
|
| 57 |
+
| _SingleCodes
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
_DTypeLikeFloat64 = (
|
| 61 |
+
dtype[float64]
|
| 62 |
+
| _SupportsDType[dtype[float64]]
|
| 63 |
+
| type[float]
|
| 64 |
+
| type[float64]
|
| 65 |
+
| _Float64Codes
|
| 66 |
+
| _DoubleCodes
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
class RandomState:
|
| 70 |
+
_bit_generator: BitGenerator
|
| 71 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | BitGenerator = ...) -> None: ...
|
| 72 |
+
def __repr__(self) -> str: ...
|
| 73 |
+
def __str__(self) -> str: ...
|
| 74 |
+
def __getstate__(self) -> dict[str, Any]: ...
|
| 75 |
+
def __setstate__(self, state: dict[str, Any]) -> None: ...
|
| 76 |
+
def __reduce__(self) -> tuple[Callable[[BitGenerator], RandomState], tuple[BitGenerator], dict[str, Any]]: ...
|
| 77 |
+
def seed(self, seed: None | _ArrayLikeFloat_co = ...) -> None: ...
|
| 78 |
+
@overload
|
| 79 |
+
def get_state(self, legacy: Literal[False] = ...) -> dict[str, Any]: ...
|
| 80 |
+
@overload
|
| 81 |
+
def get_state(
|
| 82 |
+
self, legacy: Literal[True] = ...
|
| 83 |
+
) -> dict[str, Any] | tuple[str, NDArray[uint32], int, int, float]: ...
|
| 84 |
+
def set_state(
|
| 85 |
+
self, state: dict[str, Any] | tuple[str, NDArray[uint32], int, int, float]
|
| 86 |
+
) -> None: ...
|
| 87 |
+
@overload
|
| 88 |
+
def random_sample(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 89 |
+
@overload
|
| 90 |
+
def random_sample(self, size: _ShapeLike) -> NDArray[float64]: ...
|
| 91 |
+
@overload
|
| 92 |
+
def random(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 93 |
+
@overload
|
| 94 |
+
def random(self, size: _ShapeLike) -> NDArray[float64]: ...
|
| 95 |
+
@overload
|
| 96 |
+
def beta(self, a: float, b: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 97 |
+
@overload
|
| 98 |
+
def beta(
|
| 99 |
+
self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 100 |
+
) -> NDArray[float64]: ...
|
| 101 |
+
@overload
|
| 102 |
+
def exponential(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 103 |
+
@overload
|
| 104 |
+
def exponential(
|
| 105 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 106 |
+
) -> NDArray[float64]: ...
|
| 107 |
+
@overload
|
| 108 |
+
def standard_exponential(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 109 |
+
@overload
|
| 110 |
+
def standard_exponential(self, size: _ShapeLike) -> NDArray[float64]: ...
|
| 111 |
+
@overload
|
| 112 |
+
def tomaxint(self, size: None = ...) -> int: ... # type: ignore[misc]
|
| 113 |
+
@overload
|
| 114 |
+
# Generates long values, but stores it in a 64bit int:
|
| 115 |
+
def tomaxint(self, size: _ShapeLike) -> NDArray[int64]: ...
|
| 116 |
+
@overload
|
| 117 |
+
def randint( # type: ignore[misc]
|
| 118 |
+
self,
|
| 119 |
+
low: int,
|
| 120 |
+
high: None | int = ...,
|
| 121 |
+
size: None = ...,
|
| 122 |
+
) -> int: ...
|
| 123 |
+
@overload
|
| 124 |
+
def randint( # type: ignore[misc]
|
| 125 |
+
self,
|
| 126 |
+
low: int,
|
| 127 |
+
high: None | int = ...,
|
| 128 |
+
size: None = ...,
|
| 129 |
+
dtype: type[bool] = ...,
|
| 130 |
+
) -> bool: ...
|
| 131 |
+
@overload
|
| 132 |
+
def randint( # type: ignore[misc]
|
| 133 |
+
self,
|
| 134 |
+
low: int,
|
| 135 |
+
high: None | int = ...,
|
| 136 |
+
size: None = ...,
|
| 137 |
+
dtype: type[np.bool] = ...,
|
| 138 |
+
) -> np.bool: ...
|
| 139 |
+
@overload
|
| 140 |
+
def randint( # type: ignore[misc]
|
| 141 |
+
self,
|
| 142 |
+
low: int,
|
| 143 |
+
high: None | int = ...,
|
| 144 |
+
size: None = ...,
|
| 145 |
+
dtype: type[int] = ...,
|
| 146 |
+
) -> int: ...
|
| 147 |
+
@overload
|
| 148 |
+
def randint( # type: ignore[misc]
|
| 149 |
+
self,
|
| 150 |
+
low: int,
|
| 151 |
+
high: None | int = ...,
|
| 152 |
+
size: None = ...,
|
| 153 |
+
dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
|
| 154 |
+
) -> uint8: ...
|
| 155 |
+
@overload
|
| 156 |
+
def randint( # type: ignore[misc]
|
| 157 |
+
self,
|
| 158 |
+
low: int,
|
| 159 |
+
high: None | int = ...,
|
| 160 |
+
size: None = ...,
|
| 161 |
+
dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
|
| 162 |
+
) -> uint16: ...
|
| 163 |
+
@overload
|
| 164 |
+
def randint( # type: ignore[misc]
|
| 165 |
+
self,
|
| 166 |
+
low: int,
|
| 167 |
+
high: None | int = ...,
|
| 168 |
+
size: None = ...,
|
| 169 |
+
dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
|
| 170 |
+
) -> uint32: ...
|
| 171 |
+
@overload
|
| 172 |
+
def randint( # type: ignore[misc]
|
| 173 |
+
self,
|
| 174 |
+
low: int,
|
| 175 |
+
high: None | int = ...,
|
| 176 |
+
size: None = ...,
|
| 177 |
+
dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ...,
|
| 178 |
+
) -> uint: ...
|
| 179 |
+
@overload
|
| 180 |
+
def randint( # type: ignore[misc]
|
| 181 |
+
self,
|
| 182 |
+
low: int,
|
| 183 |
+
high: None | int = ...,
|
| 184 |
+
size: None = ...,
|
| 185 |
+
dtype: dtype[ulong] | type[ulong] | _ULongCodes | _SupportsDType[dtype[ulong]] = ...,
|
| 186 |
+
) -> ulong: ...
|
| 187 |
+
@overload
|
| 188 |
+
def randint( # type: ignore[misc]
|
| 189 |
+
self,
|
| 190 |
+
low: int,
|
| 191 |
+
high: None | int = ...,
|
| 192 |
+
size: None = ...,
|
| 193 |
+
dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
|
| 194 |
+
) -> uint64: ...
|
| 195 |
+
@overload
|
| 196 |
+
def randint( # type: ignore[misc]
|
| 197 |
+
self,
|
| 198 |
+
low: int,
|
| 199 |
+
high: None | int = ...,
|
| 200 |
+
size: None = ...,
|
| 201 |
+
dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
|
| 202 |
+
) -> int8: ...
|
| 203 |
+
@overload
|
| 204 |
+
def randint( # type: ignore[misc]
|
| 205 |
+
self,
|
| 206 |
+
low: int,
|
| 207 |
+
high: None | int = ...,
|
| 208 |
+
size: None = ...,
|
| 209 |
+
dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
|
| 210 |
+
) -> int16: ...
|
| 211 |
+
@overload
|
| 212 |
+
def randint( # type: ignore[misc]
|
| 213 |
+
self,
|
| 214 |
+
low: int,
|
| 215 |
+
high: None | int = ...,
|
| 216 |
+
size: None = ...,
|
| 217 |
+
dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
|
| 218 |
+
) -> int32: ...
|
| 219 |
+
@overload
|
| 220 |
+
def randint( # type: ignore[misc]
|
| 221 |
+
self,
|
| 222 |
+
low: int,
|
| 223 |
+
high: None | int = ...,
|
| 224 |
+
size: None = ...,
|
| 225 |
+
dtype: dtype[int_] | type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ...,
|
| 226 |
+
) -> int_: ...
|
| 227 |
+
@overload
|
| 228 |
+
def randint( # type: ignore[misc]
|
| 229 |
+
self,
|
| 230 |
+
low: int,
|
| 231 |
+
high: None | int = ...,
|
| 232 |
+
size: None = ...,
|
| 233 |
+
dtype: dtype[long] | type[long] | _LongCodes | _SupportsDType[dtype[long]] = ...,
|
| 234 |
+
) -> long: ...
|
| 235 |
+
@overload
|
| 236 |
+
def randint( # type: ignore[misc]
|
| 237 |
+
self,
|
| 238 |
+
low: int,
|
| 239 |
+
high: None | int = ...,
|
| 240 |
+
size: None = ...,
|
| 241 |
+
dtype: dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
|
| 242 |
+
) -> int64: ...
|
| 243 |
+
@overload
|
| 244 |
+
def randint( # type: ignore[misc]
|
| 245 |
+
self,
|
| 246 |
+
low: _ArrayLikeInt_co,
|
| 247 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 248 |
+
size: None | _ShapeLike = ...,
|
| 249 |
+
) -> NDArray[long]: ...
|
| 250 |
+
@overload
|
| 251 |
+
def randint( # type: ignore[misc]
|
| 252 |
+
self,
|
| 253 |
+
low: _ArrayLikeInt_co,
|
| 254 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 255 |
+
size: None | _ShapeLike = ...,
|
| 256 |
+
dtype: _DTypeLikeBool = ...,
|
| 257 |
+
) -> NDArray[np.bool]: ...
|
| 258 |
+
@overload
|
| 259 |
+
def randint( # type: ignore[misc]
|
| 260 |
+
self,
|
| 261 |
+
low: _ArrayLikeInt_co,
|
| 262 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 263 |
+
size: None | _ShapeLike = ...,
|
| 264 |
+
dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
|
| 265 |
+
) -> NDArray[int8]: ...
|
| 266 |
+
@overload
|
| 267 |
+
def randint( # type: ignore[misc]
|
| 268 |
+
self,
|
| 269 |
+
low: _ArrayLikeInt_co,
|
| 270 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 271 |
+
size: None | _ShapeLike = ...,
|
| 272 |
+
dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
|
| 273 |
+
) -> NDArray[int16]: ...
|
| 274 |
+
@overload
|
| 275 |
+
def randint( # type: ignore[misc]
|
| 276 |
+
self,
|
| 277 |
+
low: _ArrayLikeInt_co,
|
| 278 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 279 |
+
size: None | _ShapeLike = ...,
|
| 280 |
+
dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
|
| 281 |
+
) -> NDArray[int32]: ...
|
| 282 |
+
@overload
|
| 283 |
+
def randint( # type: ignore[misc]
|
| 284 |
+
self,
|
| 285 |
+
low: _ArrayLikeInt_co,
|
| 286 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 287 |
+
size: None | _ShapeLike = ...,
|
| 288 |
+
dtype: None | dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
|
| 289 |
+
) -> NDArray[int64]: ...
|
| 290 |
+
@overload
|
| 291 |
+
def randint( # type: ignore[misc]
|
| 292 |
+
self,
|
| 293 |
+
low: _ArrayLikeInt_co,
|
| 294 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 295 |
+
size: None | _ShapeLike = ...,
|
| 296 |
+
dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
|
| 297 |
+
) -> NDArray[uint8]: ...
|
| 298 |
+
@overload
|
| 299 |
+
def randint( # type: ignore[misc]
|
| 300 |
+
self,
|
| 301 |
+
low: _ArrayLikeInt_co,
|
| 302 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 303 |
+
size: None | _ShapeLike = ...,
|
| 304 |
+
dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
|
| 305 |
+
) -> NDArray[uint16]: ...
|
| 306 |
+
@overload
|
| 307 |
+
def randint( # type: ignore[misc]
|
| 308 |
+
self,
|
| 309 |
+
low: _ArrayLikeInt_co,
|
| 310 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 311 |
+
size: None | _ShapeLike = ...,
|
| 312 |
+
dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
|
| 313 |
+
) -> NDArray[uint32]: ...
|
| 314 |
+
@overload
|
| 315 |
+
def randint( # type: ignore[misc]
|
| 316 |
+
self,
|
| 317 |
+
low: _ArrayLikeInt_co,
|
| 318 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 319 |
+
size: None | _ShapeLike = ...,
|
| 320 |
+
dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
|
| 321 |
+
) -> NDArray[uint64]: ...
|
| 322 |
+
@overload
|
| 323 |
+
def randint( # type: ignore[misc]
|
| 324 |
+
self,
|
| 325 |
+
low: _ArrayLikeInt_co,
|
| 326 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 327 |
+
size: None | _ShapeLike = ...,
|
| 328 |
+
dtype: dtype[long] | type[int] | type[long] | _LongCodes | _SupportsDType[dtype[long]] = ...,
|
| 329 |
+
) -> NDArray[long]: ...
|
| 330 |
+
@overload
|
| 331 |
+
def randint( # type: ignore[misc]
|
| 332 |
+
self,
|
| 333 |
+
low: _ArrayLikeInt_co,
|
| 334 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 335 |
+
size: None | _ShapeLike = ...,
|
| 336 |
+
dtype: dtype[ulong] | type[ulong] | _ULongCodes | _SupportsDType[dtype[ulong]] = ...,
|
| 337 |
+
) -> NDArray[ulong]: ...
|
| 338 |
+
def bytes(self, length: int) -> builtins.bytes: ...
|
| 339 |
+
@overload
|
| 340 |
+
def choice(
|
| 341 |
+
self,
|
| 342 |
+
a: int,
|
| 343 |
+
size: None = ...,
|
| 344 |
+
replace: bool = ...,
|
| 345 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 346 |
+
) -> int: ...
|
| 347 |
+
@overload
|
| 348 |
+
def choice(
|
| 349 |
+
self,
|
| 350 |
+
a: int,
|
| 351 |
+
size: _ShapeLike = ...,
|
| 352 |
+
replace: bool = ...,
|
| 353 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 354 |
+
) -> NDArray[long]: ...
|
| 355 |
+
@overload
|
| 356 |
+
def choice(
|
| 357 |
+
self,
|
| 358 |
+
a: ArrayLike,
|
| 359 |
+
size: None = ...,
|
| 360 |
+
replace: bool = ...,
|
| 361 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 362 |
+
) -> Any: ...
|
| 363 |
+
@overload
|
| 364 |
+
def choice(
|
| 365 |
+
self,
|
| 366 |
+
a: ArrayLike,
|
| 367 |
+
size: _ShapeLike = ...,
|
| 368 |
+
replace: bool = ...,
|
| 369 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 370 |
+
) -> NDArray[Any]: ...
|
| 371 |
+
@overload
|
| 372 |
+
def uniform(self, low: float = ..., high: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 373 |
+
@overload
|
| 374 |
+
def uniform(
|
| 375 |
+
self,
|
| 376 |
+
low: _ArrayLikeFloat_co = ...,
|
| 377 |
+
high: _ArrayLikeFloat_co = ...,
|
| 378 |
+
size: None | _ShapeLike = ...,
|
| 379 |
+
) -> NDArray[float64]: ...
|
| 380 |
+
@overload
|
| 381 |
+
def rand(self) -> float: ...
|
| 382 |
+
@overload
|
| 383 |
+
def rand(self, *args: int) -> NDArray[float64]: ...
|
| 384 |
+
@overload
|
| 385 |
+
def randn(self) -> float: ...
|
| 386 |
+
@overload
|
| 387 |
+
def randn(self, *args: int) -> NDArray[float64]: ...
|
| 388 |
+
@overload
|
| 389 |
+
def random_integers(self, low: int, high: None | int = ..., size: None = ...) -> int: ... # type: ignore[misc]
|
| 390 |
+
@overload
|
| 391 |
+
def random_integers(
|
| 392 |
+
self,
|
| 393 |
+
low: _ArrayLikeInt_co,
|
| 394 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 395 |
+
size: None | _ShapeLike = ...,
|
| 396 |
+
) -> NDArray[long]: ...
|
| 397 |
+
@overload
|
| 398 |
+
def standard_normal(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 399 |
+
@overload
|
| 400 |
+
def standard_normal( # type: ignore[misc]
|
| 401 |
+
self, size: _ShapeLike = ...
|
| 402 |
+
) -> NDArray[float64]: ...
|
| 403 |
+
@overload
|
| 404 |
+
def normal(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 405 |
+
@overload
|
| 406 |
+
def normal(
|
| 407 |
+
self,
|
| 408 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 409 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 410 |
+
size: None | _ShapeLike = ...,
|
| 411 |
+
) -> NDArray[float64]: ...
|
| 412 |
+
@overload
|
| 413 |
+
def standard_gamma( # type: ignore[misc]
|
| 414 |
+
self,
|
| 415 |
+
shape: float,
|
| 416 |
+
size: None = ...,
|
| 417 |
+
) -> float: ...
|
| 418 |
+
@overload
|
| 419 |
+
def standard_gamma(
|
| 420 |
+
self,
|
| 421 |
+
shape: _ArrayLikeFloat_co,
|
| 422 |
+
size: None | _ShapeLike = ...,
|
| 423 |
+
) -> NDArray[float64]: ...
|
| 424 |
+
@overload
|
| 425 |
+
def gamma(self, shape: float, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 426 |
+
@overload
|
| 427 |
+
def gamma(
|
| 428 |
+
self,
|
| 429 |
+
shape: _ArrayLikeFloat_co,
|
| 430 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 431 |
+
size: None | _ShapeLike = ...,
|
| 432 |
+
) -> NDArray[float64]: ...
|
| 433 |
+
@overload
|
| 434 |
+
def f(self, dfnum: float, dfden: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 435 |
+
@overload
|
| 436 |
+
def f(
|
| 437 |
+
self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 438 |
+
) -> NDArray[float64]: ...
|
| 439 |
+
@overload
|
| 440 |
+
def noncentral_f(self, dfnum: float, dfden: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 441 |
+
@overload
|
| 442 |
+
def noncentral_f(
|
| 443 |
+
self,
|
| 444 |
+
dfnum: _ArrayLikeFloat_co,
|
| 445 |
+
dfden: _ArrayLikeFloat_co,
|
| 446 |
+
nonc: _ArrayLikeFloat_co,
|
| 447 |
+
size: None | _ShapeLike = ...,
|
| 448 |
+
) -> NDArray[float64]: ...
|
| 449 |
+
@overload
|
| 450 |
+
def chisquare(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 451 |
+
@overload
|
| 452 |
+
def chisquare(
|
| 453 |
+
self, df: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 454 |
+
) -> NDArray[float64]: ...
|
| 455 |
+
@overload
|
| 456 |
+
def noncentral_chisquare(self, df: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 457 |
+
@overload
|
| 458 |
+
def noncentral_chisquare(
|
| 459 |
+
self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 460 |
+
) -> NDArray[float64]: ...
|
| 461 |
+
@overload
|
| 462 |
+
def standard_t(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 463 |
+
@overload
|
| 464 |
+
def standard_t(
|
| 465 |
+
self, df: _ArrayLikeFloat_co, size: None = ...
|
| 466 |
+
) -> NDArray[float64]: ...
|
| 467 |
+
@overload
|
| 468 |
+
def standard_t(
|
| 469 |
+
self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...
|
| 470 |
+
) -> NDArray[float64]: ...
|
| 471 |
+
@overload
|
| 472 |
+
def vonmises(self, mu: float, kappa: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 473 |
+
@overload
|
| 474 |
+
def vonmises(
|
| 475 |
+
self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 476 |
+
) -> NDArray[float64]: ...
|
| 477 |
+
@overload
|
| 478 |
+
def pareto(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 479 |
+
@overload
|
| 480 |
+
def pareto(
|
| 481 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 482 |
+
) -> NDArray[float64]: ...
|
| 483 |
+
@overload
|
| 484 |
+
def weibull(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 485 |
+
@overload
|
| 486 |
+
def weibull(
|
| 487 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 488 |
+
) -> NDArray[float64]: ...
|
| 489 |
+
@overload
|
| 490 |
+
def power(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 491 |
+
@overload
|
| 492 |
+
def power(
|
| 493 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 494 |
+
) -> NDArray[float64]: ...
|
| 495 |
+
@overload
|
| 496 |
+
def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 497 |
+
@overload
|
| 498 |
+
def standard_cauchy(self, size: _ShapeLike = ...) -> NDArray[float64]: ...
|
| 499 |
+
@overload
|
| 500 |
+
def laplace(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 501 |
+
@overload
|
| 502 |
+
def laplace(
|
| 503 |
+
self,
|
| 504 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 505 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 506 |
+
size: None | _ShapeLike = ...,
|
| 507 |
+
) -> NDArray[float64]: ...
|
| 508 |
+
@overload
|
| 509 |
+
def gumbel(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 510 |
+
@overload
|
| 511 |
+
def gumbel(
|
| 512 |
+
self,
|
| 513 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 514 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 515 |
+
size: None | _ShapeLike = ...,
|
| 516 |
+
) -> NDArray[float64]: ...
|
| 517 |
+
@overload
|
| 518 |
+
def logistic(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 519 |
+
@overload
|
| 520 |
+
def logistic(
|
| 521 |
+
self,
|
| 522 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 523 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 524 |
+
size: None | _ShapeLike = ...,
|
| 525 |
+
) -> NDArray[float64]: ...
|
| 526 |
+
@overload
|
| 527 |
+
def lognormal(self, mean: float = ..., sigma: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 528 |
+
@overload
|
| 529 |
+
def lognormal(
|
| 530 |
+
self,
|
| 531 |
+
mean: _ArrayLikeFloat_co = ...,
|
| 532 |
+
sigma: _ArrayLikeFloat_co = ...,
|
| 533 |
+
size: None | _ShapeLike = ...,
|
| 534 |
+
) -> NDArray[float64]: ...
|
| 535 |
+
@overload
|
| 536 |
+
def rayleigh(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 537 |
+
@overload
|
| 538 |
+
def rayleigh(
|
| 539 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 540 |
+
) -> NDArray[float64]: ...
|
| 541 |
+
@overload
|
| 542 |
+
def wald(self, mean: float, scale: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 543 |
+
@overload
|
| 544 |
+
def wald(
|
| 545 |
+
self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 546 |
+
) -> NDArray[float64]: ...
|
| 547 |
+
@overload
|
| 548 |
+
def triangular(self, left: float, mode: float, right: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 549 |
+
@overload
|
| 550 |
+
def triangular(
|
| 551 |
+
self,
|
| 552 |
+
left: _ArrayLikeFloat_co,
|
| 553 |
+
mode: _ArrayLikeFloat_co,
|
| 554 |
+
right: _ArrayLikeFloat_co,
|
| 555 |
+
size: None | _ShapeLike = ...,
|
| 556 |
+
) -> NDArray[float64]: ...
|
| 557 |
+
@overload
|
| 558 |
+
def binomial(self, n: int, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 559 |
+
@overload
|
| 560 |
+
def binomial(
|
| 561 |
+
self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 562 |
+
) -> NDArray[long]: ...
|
| 563 |
+
@overload
|
| 564 |
+
def negative_binomial(self, n: float, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 565 |
+
@overload
|
| 566 |
+
def negative_binomial(
|
| 567 |
+
self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 568 |
+
) -> NDArray[long]: ...
|
| 569 |
+
@overload
|
| 570 |
+
def poisson(self, lam: float = ..., size: None = ...) -> int: ... # type: ignore[misc]
|
| 571 |
+
@overload
|
| 572 |
+
def poisson(
|
| 573 |
+
self, lam: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 574 |
+
) -> NDArray[long]: ...
|
| 575 |
+
@overload
|
| 576 |
+
def zipf(self, a: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 577 |
+
@overload
|
| 578 |
+
def zipf(
|
| 579 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 580 |
+
) -> NDArray[long]: ...
|
| 581 |
+
@overload
|
| 582 |
+
def geometric(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 583 |
+
@overload
|
| 584 |
+
def geometric(
|
| 585 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 586 |
+
) -> NDArray[long]: ...
|
| 587 |
+
@overload
|
| 588 |
+
def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc]
|
| 589 |
+
@overload
|
| 590 |
+
def hypergeometric(
|
| 591 |
+
self,
|
| 592 |
+
ngood: _ArrayLikeInt_co,
|
| 593 |
+
nbad: _ArrayLikeInt_co,
|
| 594 |
+
nsample: _ArrayLikeInt_co,
|
| 595 |
+
size: None | _ShapeLike = ...,
|
| 596 |
+
) -> NDArray[long]: ...
|
| 597 |
+
@overload
|
| 598 |
+
def logseries(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 599 |
+
@overload
|
| 600 |
+
def logseries(
|
| 601 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 602 |
+
) -> NDArray[long]: ...
|
| 603 |
+
def multivariate_normal(
|
| 604 |
+
self,
|
| 605 |
+
mean: _ArrayLikeFloat_co,
|
| 606 |
+
cov: _ArrayLikeFloat_co,
|
| 607 |
+
size: None | _ShapeLike = ...,
|
| 608 |
+
check_valid: Literal["warn", "raise", "ignore"] = ...,
|
| 609 |
+
tol: float = ...,
|
| 610 |
+
) -> NDArray[float64]: ...
|
| 611 |
+
def multinomial(
|
| 612 |
+
self, n: _ArrayLikeInt_co, pvals: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 613 |
+
) -> NDArray[long]: ...
|
| 614 |
+
def dirichlet(
|
| 615 |
+
self, alpha: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 616 |
+
) -> NDArray[float64]: ...
|
| 617 |
+
def shuffle(self, x: ArrayLike) -> None: ...
|
| 618 |
+
@overload
|
| 619 |
+
def permutation(self, x: int) -> NDArray[long]: ...
|
| 620 |
+
@overload
|
| 621 |
+
def permutation(self, x: ArrayLike) -> NDArray[Any]: ...
|
| 622 |
+
|
| 623 |
+
_rand: RandomState
|
| 624 |
+
|
| 625 |
+
beta = _rand.beta
|
| 626 |
+
binomial = _rand.binomial
|
| 627 |
+
bytes = _rand.bytes
|
| 628 |
+
chisquare = _rand.chisquare
|
| 629 |
+
choice = _rand.choice
|
| 630 |
+
dirichlet = _rand.dirichlet
|
| 631 |
+
exponential = _rand.exponential
|
| 632 |
+
f = _rand.f
|
| 633 |
+
gamma = _rand.gamma
|
| 634 |
+
get_state = _rand.get_state
|
| 635 |
+
geometric = _rand.geometric
|
| 636 |
+
gumbel = _rand.gumbel
|
| 637 |
+
hypergeometric = _rand.hypergeometric
|
| 638 |
+
laplace = _rand.laplace
|
| 639 |
+
logistic = _rand.logistic
|
| 640 |
+
lognormal = _rand.lognormal
|
| 641 |
+
logseries = _rand.logseries
|
| 642 |
+
multinomial = _rand.multinomial
|
| 643 |
+
multivariate_normal = _rand.multivariate_normal
|
| 644 |
+
negative_binomial = _rand.negative_binomial
|
| 645 |
+
noncentral_chisquare = _rand.noncentral_chisquare
|
| 646 |
+
noncentral_f = _rand.noncentral_f
|
| 647 |
+
normal = _rand.normal
|
| 648 |
+
pareto = _rand.pareto
|
| 649 |
+
permutation = _rand.permutation
|
| 650 |
+
poisson = _rand.poisson
|
| 651 |
+
power = _rand.power
|
| 652 |
+
rand = _rand.rand
|
| 653 |
+
randint = _rand.randint
|
| 654 |
+
randn = _rand.randn
|
| 655 |
+
random = _rand.random
|
| 656 |
+
random_integers = _rand.random_integers
|
| 657 |
+
random_sample = _rand.random_sample
|
| 658 |
+
rayleigh = _rand.rayleigh
|
| 659 |
+
seed = _rand.seed
|
| 660 |
+
set_state = _rand.set_state
|
| 661 |
+
shuffle = _rand.shuffle
|
| 662 |
+
standard_cauchy = _rand.standard_cauchy
|
| 663 |
+
standard_exponential = _rand.standard_exponential
|
| 664 |
+
standard_gamma = _rand.standard_gamma
|
| 665 |
+
standard_normal = _rand.standard_normal
|
| 666 |
+
standard_t = _rand.standard_t
|
| 667 |
+
triangular = _rand.triangular
|
| 668 |
+
uniform = _rand.uniform
|
| 669 |
+
vonmises = _rand.vonmises
|
| 670 |
+
wald = _rand.wald
|
| 671 |
+
weibull = _rand.weibull
|
| 672 |
+
zipf = _rand.zipf
|
| 673 |
+
# Two legacy that are trivial wrappers around random_sample
|
| 674 |
+
sample = _rand.random_sample
|
| 675 |
+
ranf = _rand.random_sample
|
| 676 |
+
|
| 677 |
+
def set_bit_generator(bitgen: BitGenerator) -> None:
|
| 678 |
+
...
|
| 679 |
+
|
| 680 |
+
def get_bit_generator() -> BitGenerator:
|
| 681 |
+
...
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/__pycache__/conftest.cpython-310.pyc
ADDED
|
Binary file (1.21 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/__pycache__/setup.cpython-310.pyc
ADDED
|
Binary file (1.85 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (182 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_promise_list.cpython-310.pyc
ADDED
|
Binary file (2.53 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_spec.cpython-310.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (381 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
Pygments
|
| 4 |
+
~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Pygments is a syntax highlighting package written in Python.
|
| 7 |
+
|
| 8 |
+
It is a generic syntax highlighter for general use in all kinds of software
|
| 9 |
+
such as forum systems, wikis or other applications that need to prettify
|
| 10 |
+
source code. Highlights are:
|
| 11 |
+
|
| 12 |
+
* a wide range of common languages and markup formats is supported
|
| 13 |
+
* special attention is paid to details, increasing quality by a fair amount
|
| 14 |
+
* support for new languages and formats are added easily
|
| 15 |
+
* a number of output formats, presently HTML, LaTeX, RTF, SVG, all image
|
| 16 |
+
formats that PIL supports, and ANSI sequences
|
| 17 |
+
* it is usable as a command-line tool and as a library
|
| 18 |
+
* ... and it highlights even Brainfuck!
|
| 19 |
+
|
| 20 |
+
The `Pygments tip`_ is installable with ``easy_install Pygments==dev``.
|
| 21 |
+
|
| 22 |
+
.. _Pygments tip:
|
| 23 |
+
http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev
|
| 24 |
+
|
| 25 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 26 |
+
:license: BSD, see LICENSE for details.
|
| 27 |
+
"""
|
| 28 |
+
import sys
|
| 29 |
+
|
| 30 |
+
from pygments.util import StringIO, BytesIO
|
| 31 |
+
|
| 32 |
+
__version__ = '2.2.0'
|
| 33 |
+
__docformat__ = 'restructuredtext'
|
| 34 |
+
|
| 35 |
+
__all__ = ['lex', 'format', 'highlight']
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def lex(code, lexer):
|
| 39 |
+
"""
|
| 40 |
+
Lex ``code`` with ``lexer`` and return an iterable of tokens.
|
| 41 |
+
"""
|
| 42 |
+
try:
|
| 43 |
+
return lexer.get_tokens(code)
|
| 44 |
+
except TypeError as err:
|
| 45 |
+
if (isinstance(err.args[0], str) and
|
| 46 |
+
('unbound method get_tokens' in err.args[0] or
|
| 47 |
+
'missing 1 required positional argument' in err.args[0])):
|
| 48 |
+
raise TypeError('lex() argument must be a lexer instance, '
|
| 49 |
+
'not a class')
|
| 50 |
+
raise
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin
|
| 54 |
+
"""
|
| 55 |
+
Format a tokenlist ``tokens`` with the formatter ``formatter``.
|
| 56 |
+
|
| 57 |
+
If ``outfile`` is given and a valid file object (an object
|
| 58 |
+
with a ``write`` method), the result will be written to it, otherwise
|
| 59 |
+
it is returned as a string.
|
| 60 |
+
"""
|
| 61 |
+
try:
|
| 62 |
+
if not outfile:
|
| 63 |
+
realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
|
| 64 |
+
formatter.format(tokens, realoutfile)
|
| 65 |
+
return realoutfile.getvalue()
|
| 66 |
+
else:
|
| 67 |
+
formatter.format(tokens, outfile)
|
| 68 |
+
except TypeError as err:
|
| 69 |
+
if (isinstance(err.args[0], str) and
|
| 70 |
+
('unbound method format' in err.args[0] or
|
| 71 |
+
'missing 1 required positional argument' in err.args[0])):
|
| 72 |
+
raise TypeError('format() argument must be a formatter instance, '
|
| 73 |
+
'not a class')
|
| 74 |
+
raise
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def highlight(code, lexer, formatter, outfile=None):
|
| 78 |
+
"""
|
| 79 |
+
Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``.
|
| 80 |
+
|
| 81 |
+
If ``outfile`` is given and a valid file object (an object
|
| 82 |
+
with a ``write`` method), the result will be written to it, otherwise
|
| 83 |
+
it is returned as a string.
|
| 84 |
+
"""
|
| 85 |
+
return format(lex(code, lexer), formatter, outfile)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
if __name__ == '__main__': # pragma: no cover
|
| 89 |
+
from pygments.cmdline import main
|
| 90 |
+
sys.exit(main(sys.argv))
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/cmdline.py
ADDED
|
@@ -0,0 +1,568 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.cmdline
|
| 4 |
+
~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Command line interface.
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import print_function
|
| 13 |
+
|
| 14 |
+
import sys
|
| 15 |
+
import getopt
|
| 16 |
+
from textwrap import dedent
|
| 17 |
+
|
| 18 |
+
from pygments import __version__, highlight
|
| 19 |
+
from pygments.util import ClassNotFound, OptionError, docstring_headline, \
|
| 20 |
+
guess_decode, guess_decode_from_terminal, terminal_encoding
|
| 21 |
+
from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, \
|
| 22 |
+
load_lexer_from_file, get_lexer_for_filename, find_lexer_class_for_filename
|
| 23 |
+
from pygments.lexers.special import TextLexer
|
| 24 |
+
from pygments.formatters.latex import LatexEmbeddedLexer, LatexFormatter
|
| 25 |
+
from pygments.formatters import get_all_formatters, get_formatter_by_name, \
|
| 26 |
+
load_formatter_from_file, get_formatter_for_filename, find_formatter_class
|
| 27 |
+
from pygments.formatters.terminal import TerminalFormatter
|
| 28 |
+
from pygments.filters import get_all_filters, find_filter_class
|
| 29 |
+
from pygments.styles import get_all_styles, get_style_by_name
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
USAGE = """\
|
| 33 |
+
Usage: %s [-l <lexer> | -g] [-F <filter>[:<options>]] [-f <formatter>]
|
| 34 |
+
[-O <options>] [-P <option=value>] [-s] [-v] [-x] [-o <outfile>] [<infile>]
|
| 35 |
+
|
| 36 |
+
%s -S <style> -f <formatter> [-a <arg>] [-O <options>] [-P <option=value>]
|
| 37 |
+
%s -L [<which> ...]
|
| 38 |
+
%s -N <filename>
|
| 39 |
+
%s -H <type> <name>
|
| 40 |
+
%s -h | -V
|
| 41 |
+
|
| 42 |
+
Highlight the input file and write the result to <outfile>.
|
| 43 |
+
|
| 44 |
+
If no input file is given, use stdin, if -o is not given, use stdout.
|
| 45 |
+
|
| 46 |
+
If -s is passed, lexing will be done in "streaming" mode, reading and
|
| 47 |
+
highlighting one line at a time. This will only work properly with
|
| 48 |
+
lexers that have no constructs spanning multiple lines!
|
| 49 |
+
|
| 50 |
+
<lexer> is a lexer name (query all lexer names with -L). If -l is not
|
| 51 |
+
given, the lexer is guessed from the extension of the input file name
|
| 52 |
+
(this obviously doesn't work if the input is stdin). If -g is passed,
|
| 53 |
+
attempt to guess the lexer from the file contents, or pass through as
|
| 54 |
+
plain text if this fails (this can work for stdin).
|
| 55 |
+
|
| 56 |
+
Likewise, <formatter> is a formatter name, and will be guessed from
|
| 57 |
+
the extension of the output file name. If no output file is given,
|
| 58 |
+
the terminal formatter will be used by default.
|
| 59 |
+
|
| 60 |
+
The additional option -x allows custom lexers and formatters to be
|
| 61 |
+
loaded from a .py file relative to the current working directory. For
|
| 62 |
+
example, ``-l ./customlexer.py -x``. By default, this option expects a
|
| 63 |
+
file with a class named CustomLexer or CustomFormatter; you can also
|
| 64 |
+
specify your own class name with a colon (``-l ./lexer.py:MyLexer``).
|
| 65 |
+
Users should be very careful not to use this option with untrusted files,
|
| 66 |
+
because it will import and run them.
|
| 67 |
+
|
| 68 |
+
With the -O option, you can give the lexer and formatter a comma-
|
| 69 |
+
separated list of options, e.g. ``-O bg=light,python=cool``.
|
| 70 |
+
|
| 71 |
+
The -P option adds lexer and formatter options like the -O option, but
|
| 72 |
+
you can only give one option per -P. That way, the option value may
|
| 73 |
+
contain commas and equals signs, which it can't with -O, e.g.
|
| 74 |
+
``-P "heading=Pygments, the Python highlighter".
|
| 75 |
+
|
| 76 |
+
With the -F option, you can add filters to the token stream, you can
|
| 77 |
+
give options in the same way as for -O after a colon (note: there must
|
| 78 |
+
not be spaces around the colon).
|
| 79 |
+
|
| 80 |
+
The -O, -P and -F options can be given multiple times.
|
| 81 |
+
|
| 82 |
+
With the -S option, print out style definitions for style <style>
|
| 83 |
+
for formatter <formatter>. The argument given by -a is formatter
|
| 84 |
+
dependent.
|
| 85 |
+
|
| 86 |
+
The -L option lists lexers, formatters, styles or filters -- set
|
| 87 |
+
`which` to the thing you want to list (e.g. "styles"), or omit it to
|
| 88 |
+
list everything.
|
| 89 |
+
|
| 90 |
+
The -N option guesses and prints out a lexer name based solely on
|
| 91 |
+
the given filename. It does not take input or highlight anything.
|
| 92 |
+
If no specific lexer can be determined "text" is returned.
|
| 93 |
+
|
| 94 |
+
The -H option prints detailed help for the object <name> of type <type>,
|
| 95 |
+
where <type> is one of "lexer", "formatter" or "filter".
|
| 96 |
+
|
| 97 |
+
The -s option processes lines one at a time until EOF, rather than
|
| 98 |
+
waiting to process the entire file. This only works for stdin, and
|
| 99 |
+
is intended for streaming input such as you get from 'tail -f'.
|
| 100 |
+
Example usage: "tail -f sql.log | pygmentize -s -l sql"
|
| 101 |
+
|
| 102 |
+
The -v option prints a detailed traceback on unhandled exceptions,
|
| 103 |
+
which is useful for debugging and bug reports.
|
| 104 |
+
|
| 105 |
+
The -h option prints this help.
|
| 106 |
+
The -V option prints the package version.
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def _parse_options(o_strs):
|
| 111 |
+
opts = {}
|
| 112 |
+
if not o_strs:
|
| 113 |
+
return opts
|
| 114 |
+
for o_str in o_strs:
|
| 115 |
+
if not o_str.strip():
|
| 116 |
+
continue
|
| 117 |
+
o_args = o_str.split(',')
|
| 118 |
+
for o_arg in o_args:
|
| 119 |
+
o_arg = o_arg.strip()
|
| 120 |
+
try:
|
| 121 |
+
o_key, o_val = o_arg.split('=', 1)
|
| 122 |
+
o_key = o_key.strip()
|
| 123 |
+
o_val = o_val.strip()
|
| 124 |
+
except ValueError:
|
| 125 |
+
opts[o_arg] = True
|
| 126 |
+
else:
|
| 127 |
+
opts[o_key] = o_val
|
| 128 |
+
return opts
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _parse_filters(f_strs):
|
| 132 |
+
filters = []
|
| 133 |
+
if not f_strs:
|
| 134 |
+
return filters
|
| 135 |
+
for f_str in f_strs:
|
| 136 |
+
if ':' in f_str:
|
| 137 |
+
fname, fopts = f_str.split(':', 1)
|
| 138 |
+
filters.append((fname, _parse_options([fopts])))
|
| 139 |
+
else:
|
| 140 |
+
filters.append((f_str, {}))
|
| 141 |
+
return filters
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def _print_help(what, name):
|
| 145 |
+
try:
|
| 146 |
+
if what == 'lexer':
|
| 147 |
+
cls = get_lexer_by_name(name)
|
| 148 |
+
print("Help on the %s lexer:" % cls.name)
|
| 149 |
+
print(dedent(cls.__doc__))
|
| 150 |
+
elif what == 'formatter':
|
| 151 |
+
cls = find_formatter_class(name)
|
| 152 |
+
print("Help on the %s formatter:" % cls.name)
|
| 153 |
+
print(dedent(cls.__doc__))
|
| 154 |
+
elif what == 'filter':
|
| 155 |
+
cls = find_filter_class(name)
|
| 156 |
+
print("Help on the %s filter:" % name)
|
| 157 |
+
print(dedent(cls.__doc__))
|
| 158 |
+
return 0
|
| 159 |
+
except (AttributeError, ValueError):
|
| 160 |
+
print("%s not found!" % what, file=sys.stderr)
|
| 161 |
+
return 1
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _print_list(what):
|
| 165 |
+
if what == 'lexer':
|
| 166 |
+
print()
|
| 167 |
+
print("Lexers:")
|
| 168 |
+
print("~~~~~~~")
|
| 169 |
+
|
| 170 |
+
info = []
|
| 171 |
+
for fullname, names, exts, _ in get_all_lexers():
|
| 172 |
+
tup = (', '.join(names)+':', fullname,
|
| 173 |
+
exts and '(filenames ' + ', '.join(exts) + ')' or '')
|
| 174 |
+
info.append(tup)
|
| 175 |
+
info.sort()
|
| 176 |
+
for i in info:
|
| 177 |
+
print(('* %s\n %s %s') % i)
|
| 178 |
+
|
| 179 |
+
elif what == 'formatter':
|
| 180 |
+
print()
|
| 181 |
+
print("Formatters:")
|
| 182 |
+
print("~~~~~~~~~~~")
|
| 183 |
+
|
| 184 |
+
info = []
|
| 185 |
+
for cls in get_all_formatters():
|
| 186 |
+
doc = docstring_headline(cls)
|
| 187 |
+
tup = (', '.join(cls.aliases) + ':', doc, cls.filenames and
|
| 188 |
+
'(filenames ' + ', '.join(cls.filenames) + ')' or '')
|
| 189 |
+
info.append(tup)
|
| 190 |
+
info.sort()
|
| 191 |
+
for i in info:
|
| 192 |
+
print(('* %s\n %s %s') % i)
|
| 193 |
+
|
| 194 |
+
elif what == 'filter':
|
| 195 |
+
print()
|
| 196 |
+
print("Filters:")
|
| 197 |
+
print("~~~~~~~~")
|
| 198 |
+
|
| 199 |
+
for name in get_all_filters():
|
| 200 |
+
cls = find_filter_class(name)
|
| 201 |
+
print("* " + name + ':')
|
| 202 |
+
print(" %s" % docstring_headline(cls))
|
| 203 |
+
|
| 204 |
+
elif what == 'style':
|
| 205 |
+
print()
|
| 206 |
+
print("Styles:")
|
| 207 |
+
print("~~~~~~~")
|
| 208 |
+
|
| 209 |
+
for name in get_all_styles():
|
| 210 |
+
cls = get_style_by_name(name)
|
| 211 |
+
print("* " + name + ':')
|
| 212 |
+
print(" %s" % docstring_headline(cls))
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def main_inner(popts, args, usage):
|
| 216 |
+
opts = {}
|
| 217 |
+
O_opts = []
|
| 218 |
+
P_opts = []
|
| 219 |
+
F_opts = []
|
| 220 |
+
for opt, arg in popts:
|
| 221 |
+
if opt == '-O':
|
| 222 |
+
O_opts.append(arg)
|
| 223 |
+
elif opt == '-P':
|
| 224 |
+
P_opts.append(arg)
|
| 225 |
+
elif opt == '-F':
|
| 226 |
+
F_opts.append(arg)
|
| 227 |
+
opts[opt] = arg
|
| 228 |
+
|
| 229 |
+
if opts.pop('-h', None) is not None:
|
| 230 |
+
print(usage)
|
| 231 |
+
return 0
|
| 232 |
+
|
| 233 |
+
if opts.pop('-V', None) is not None:
|
| 234 |
+
print('Pygments version %s, (c) 2006-2017 by Georg Brandl.' % __version__)
|
| 235 |
+
return 0
|
| 236 |
+
|
| 237 |
+
# handle ``pygmentize -L``
|
| 238 |
+
L_opt = opts.pop('-L', None)
|
| 239 |
+
if L_opt is not None:
|
| 240 |
+
if opts:
|
| 241 |
+
print(usage, file=sys.stderr)
|
| 242 |
+
return 2
|
| 243 |
+
|
| 244 |
+
# print version
|
| 245 |
+
main(['', '-V'])
|
| 246 |
+
if not args:
|
| 247 |
+
args = ['lexer', 'formatter', 'filter', 'style']
|
| 248 |
+
for arg in args:
|
| 249 |
+
_print_list(arg.rstrip('s'))
|
| 250 |
+
return 0
|
| 251 |
+
|
| 252 |
+
# handle ``pygmentize -H``
|
| 253 |
+
H_opt = opts.pop('-H', None)
|
| 254 |
+
if H_opt is not None:
|
| 255 |
+
if opts or len(args) != 2:
|
| 256 |
+
print(usage, file=sys.stderr)
|
| 257 |
+
return 2
|
| 258 |
+
|
| 259 |
+
what, name = args # pylint: disable=unbalanced-tuple-unpacking
|
| 260 |
+
if what not in ('lexer', 'formatter', 'filter'):
|
| 261 |
+
print(usage, file=sys.stderr)
|
| 262 |
+
return 2
|
| 263 |
+
|
| 264 |
+
return _print_help(what, name)
|
| 265 |
+
|
| 266 |
+
# parse -O options
|
| 267 |
+
parsed_opts = _parse_options(O_opts)
|
| 268 |
+
opts.pop('-O', None)
|
| 269 |
+
|
| 270 |
+
# parse -P options
|
| 271 |
+
for p_opt in P_opts:
|
| 272 |
+
try:
|
| 273 |
+
name, value = p_opt.split('=', 1)
|
| 274 |
+
except ValueError:
|
| 275 |
+
parsed_opts[p_opt] = True
|
| 276 |
+
else:
|
| 277 |
+
parsed_opts[name] = value
|
| 278 |
+
opts.pop('-P', None)
|
| 279 |
+
|
| 280 |
+
# encodings
|
| 281 |
+
inencoding = parsed_opts.get('inencoding', parsed_opts.get('encoding'))
|
| 282 |
+
outencoding = parsed_opts.get('outencoding', parsed_opts.get('encoding'))
|
| 283 |
+
|
| 284 |
+
# handle ``pygmentize -N``
|
| 285 |
+
infn = opts.pop('-N', None)
|
| 286 |
+
if infn is not None:
|
| 287 |
+
lexer = find_lexer_class_for_filename(infn)
|
| 288 |
+
if lexer is None:
|
| 289 |
+
lexer = TextLexer
|
| 290 |
+
|
| 291 |
+
print(lexer.aliases[0])
|
| 292 |
+
return 0
|
| 293 |
+
|
| 294 |
+
# handle ``pygmentize -S``
|
| 295 |
+
S_opt = opts.pop('-S', None)
|
| 296 |
+
a_opt = opts.pop('-a', None)
|
| 297 |
+
if S_opt is not None:
|
| 298 |
+
f_opt = opts.pop('-f', None)
|
| 299 |
+
if not f_opt:
|
| 300 |
+
print(usage, file=sys.stderr)
|
| 301 |
+
return 2
|
| 302 |
+
if opts or args:
|
| 303 |
+
print(usage, file=sys.stderr)
|
| 304 |
+
return 2
|
| 305 |
+
|
| 306 |
+
try:
|
| 307 |
+
parsed_opts['style'] = S_opt
|
| 308 |
+
fmter = get_formatter_by_name(f_opt, **parsed_opts)
|
| 309 |
+
except ClassNotFound as err:
|
| 310 |
+
print(err, file=sys.stderr)
|
| 311 |
+
return 1
|
| 312 |
+
|
| 313 |
+
print(fmter.get_style_defs(a_opt or ''))
|
| 314 |
+
return 0
|
| 315 |
+
|
| 316 |
+
# if no -S is given, -a is not allowed
|
| 317 |
+
if a_opt is not None:
|
| 318 |
+
print(usage, file=sys.stderr)
|
| 319 |
+
return 2
|
| 320 |
+
|
| 321 |
+
# parse -F options
|
| 322 |
+
F_opts = _parse_filters(F_opts)
|
| 323 |
+
opts.pop('-F', None)
|
| 324 |
+
|
| 325 |
+
allow_custom_lexer_formatter = False
|
| 326 |
+
# -x: allow custom (eXternal) lexers and formatters
|
| 327 |
+
if opts.pop('-x', None) is not None:
|
| 328 |
+
allow_custom_lexer_formatter = True
|
| 329 |
+
|
| 330 |
+
# select lexer
|
| 331 |
+
lexer = None
|
| 332 |
+
|
| 333 |
+
# given by name?
|
| 334 |
+
lexername = opts.pop('-l', None)
|
| 335 |
+
if lexername:
|
| 336 |
+
# custom lexer, located relative to user's cwd
|
| 337 |
+
if allow_custom_lexer_formatter and '.py' in lexername:
|
| 338 |
+
try:
|
| 339 |
+
if ':' in lexername:
|
| 340 |
+
filename, name = lexername.rsplit(':', 1)
|
| 341 |
+
lexer = load_lexer_from_file(filename, name,
|
| 342 |
+
**parsed_opts)
|
| 343 |
+
else:
|
| 344 |
+
lexer = load_lexer_from_file(lexername, **parsed_opts)
|
| 345 |
+
except ClassNotFound as err:
|
| 346 |
+
print('Error:', err, file=sys.stderr)
|
| 347 |
+
return 1
|
| 348 |
+
else:
|
| 349 |
+
try:
|
| 350 |
+
lexer = get_lexer_by_name(lexername, **parsed_opts)
|
| 351 |
+
except (OptionError, ClassNotFound) as err:
|
| 352 |
+
print('Error:', err, file=sys.stderr)
|
| 353 |
+
return 1
|
| 354 |
+
|
| 355 |
+
# read input code
|
| 356 |
+
code = None
|
| 357 |
+
|
| 358 |
+
if args:
|
| 359 |
+
if len(args) > 1:
|
| 360 |
+
print(usage, file=sys.stderr)
|
| 361 |
+
return 2
|
| 362 |
+
|
| 363 |
+
if '-s' in opts:
|
| 364 |
+
print('Error: -s option not usable when input file specified',
|
| 365 |
+
file=sys.stderr)
|
| 366 |
+
return 2
|
| 367 |
+
|
| 368 |
+
infn = args[0]
|
| 369 |
+
try:
|
| 370 |
+
with open(infn, 'rb') as infp:
|
| 371 |
+
code = infp.read()
|
| 372 |
+
except Exception as err:
|
| 373 |
+
print('Error: cannot read infile:', err, file=sys.stderr)
|
| 374 |
+
return 1
|
| 375 |
+
if not inencoding:
|
| 376 |
+
code, inencoding = guess_decode(code)
|
| 377 |
+
|
| 378 |
+
# do we have to guess the lexer?
|
| 379 |
+
if not lexer:
|
| 380 |
+
try:
|
| 381 |
+
lexer = get_lexer_for_filename(infn, code, **parsed_opts)
|
| 382 |
+
except ClassNotFound as err:
|
| 383 |
+
if '-g' in opts:
|
| 384 |
+
try:
|
| 385 |
+
lexer = guess_lexer(code, **parsed_opts)
|
| 386 |
+
except ClassNotFound:
|
| 387 |
+
lexer = TextLexer(**parsed_opts)
|
| 388 |
+
else:
|
| 389 |
+
print('Error:', err, file=sys.stderr)
|
| 390 |
+
return 1
|
| 391 |
+
except OptionError as err:
|
| 392 |
+
print('Error:', err, file=sys.stderr)
|
| 393 |
+
return 1
|
| 394 |
+
|
| 395 |
+
elif '-s' not in opts: # treat stdin as full file (-s support is later)
|
| 396 |
+
# read code from terminal, always in binary mode since we want to
|
| 397 |
+
# decode ourselves and be tolerant with it
|
| 398 |
+
if sys.version_info > (3,):
|
| 399 |
+
# Python 3: we have to use .buffer to get a binary stream
|
| 400 |
+
code = sys.stdin.buffer.read()
|
| 401 |
+
else:
|
| 402 |
+
code = sys.stdin.read()
|
| 403 |
+
if not inencoding:
|
| 404 |
+
code, inencoding = guess_decode_from_terminal(code, sys.stdin)
|
| 405 |
+
# else the lexer will do the decoding
|
| 406 |
+
if not lexer:
|
| 407 |
+
try:
|
| 408 |
+
lexer = guess_lexer(code, **parsed_opts)
|
| 409 |
+
except ClassNotFound:
|
| 410 |
+
lexer = TextLexer(**parsed_opts)
|
| 411 |
+
|
| 412 |
+
else: # -s option needs a lexer with -l
|
| 413 |
+
if not lexer:
|
| 414 |
+
print('Error: when using -s a lexer has to be selected with -l',
|
| 415 |
+
file=sys.stderr)
|
| 416 |
+
return 2
|
| 417 |
+
|
| 418 |
+
# process filters
|
| 419 |
+
for fname, fopts in F_opts:
|
| 420 |
+
try:
|
| 421 |
+
lexer.add_filter(fname, **fopts)
|
| 422 |
+
except ClassNotFound as err:
|
| 423 |
+
print('Error:', err, file=sys.stderr)
|
| 424 |
+
return 1
|
| 425 |
+
|
| 426 |
+
# select formatter
|
| 427 |
+
outfn = opts.pop('-o', None)
|
| 428 |
+
fmter = opts.pop('-f', None)
|
| 429 |
+
if fmter:
|
| 430 |
+
# custom formatter, located relative to user's cwd
|
| 431 |
+
if allow_custom_lexer_formatter and '.py' in fmter:
|
| 432 |
+
try:
|
| 433 |
+
if ':' in fmter:
|
| 434 |
+
file, fmtername = fmter.rsplit(':', 1)
|
| 435 |
+
fmter = load_formatter_from_file(file, fmtername,
|
| 436 |
+
**parsed_opts)
|
| 437 |
+
else:
|
| 438 |
+
fmter = load_formatter_from_file(fmter, **parsed_opts)
|
| 439 |
+
except ClassNotFound as err:
|
| 440 |
+
print('Error:', err, file=sys.stderr)
|
| 441 |
+
return 1
|
| 442 |
+
else:
|
| 443 |
+
try:
|
| 444 |
+
fmter = get_formatter_by_name(fmter, **parsed_opts)
|
| 445 |
+
except (OptionError, ClassNotFound) as err:
|
| 446 |
+
print('Error:', err, file=sys.stderr)
|
| 447 |
+
return 1
|
| 448 |
+
|
| 449 |
+
if outfn:
|
| 450 |
+
if not fmter:
|
| 451 |
+
try:
|
| 452 |
+
fmter = get_formatter_for_filename(outfn, **parsed_opts)
|
| 453 |
+
except (OptionError, ClassNotFound) as err:
|
| 454 |
+
print('Error:', err, file=sys.stderr)
|
| 455 |
+
return 1
|
| 456 |
+
try:
|
| 457 |
+
outfile = open(outfn, 'wb')
|
| 458 |
+
except Exception as err:
|
| 459 |
+
print('Error: cannot open outfile:', err, file=sys.stderr)
|
| 460 |
+
return 1
|
| 461 |
+
else:
|
| 462 |
+
if not fmter:
|
| 463 |
+
fmter = TerminalFormatter(**parsed_opts)
|
| 464 |
+
if sys.version_info > (3,):
|
| 465 |
+
# Python 3: we have to use .buffer to get a binary stream
|
| 466 |
+
outfile = sys.stdout.buffer
|
| 467 |
+
else:
|
| 468 |
+
outfile = sys.stdout
|
| 469 |
+
|
| 470 |
+
# determine output encoding if not explicitly selected
|
| 471 |
+
if not outencoding:
|
| 472 |
+
if outfn:
|
| 473 |
+
# output file? use lexer encoding for now (can still be None)
|
| 474 |
+
fmter.encoding = inencoding
|
| 475 |
+
else:
|
| 476 |
+
# else use terminal encoding
|
| 477 |
+
fmter.encoding = terminal_encoding(sys.stdout)
|
| 478 |
+
|
| 479 |
+
# provide coloring under Windows, if possible
|
| 480 |
+
if not outfn and sys.platform in ('win32', 'cygwin') and \
|
| 481 |
+
fmter.name in ('Terminal', 'Terminal256'): # pragma: no cover
|
| 482 |
+
# unfortunately colorama doesn't support binary streams on Py3
|
| 483 |
+
if sys.version_info > (3,):
|
| 484 |
+
from pygments.util import UnclosingTextIOWrapper
|
| 485 |
+
outfile = UnclosingTextIOWrapper(outfile, encoding=fmter.encoding)
|
| 486 |
+
fmter.encoding = None
|
| 487 |
+
try:
|
| 488 |
+
import colorama.initialise
|
| 489 |
+
except ImportError:
|
| 490 |
+
pass
|
| 491 |
+
else:
|
| 492 |
+
outfile = colorama.initialise.wrap_stream(
|
| 493 |
+
outfile, convert=None, strip=None, autoreset=False, wrap=True)
|
| 494 |
+
|
| 495 |
+
# When using the LaTeX formatter and the option `escapeinside` is
|
| 496 |
+
# specified, we need a special lexer which collects escaped text
|
| 497 |
+
# before running the chosen language lexer.
|
| 498 |
+
escapeinside = parsed_opts.get('escapeinside', '')
|
| 499 |
+
if len(escapeinside) == 2 and isinstance(fmter, LatexFormatter):
|
| 500 |
+
left = escapeinside[0]
|
| 501 |
+
right = escapeinside[1]
|
| 502 |
+
lexer = LatexEmbeddedLexer(left, right, lexer)
|
| 503 |
+
|
| 504 |
+
# ... and do it!
|
| 505 |
+
if '-s' not in opts:
|
| 506 |
+
# process whole input as per normal...
|
| 507 |
+
highlight(code, lexer, fmter, outfile)
|
| 508 |
+
return 0
|
| 509 |
+
else:
|
| 510 |
+
# line by line processing of stdin (eg: for 'tail -f')...
|
| 511 |
+
try:
|
| 512 |
+
while 1:
|
| 513 |
+
if sys.version_info > (3,):
|
| 514 |
+
# Python 3: we have to use .buffer to get a binary stream
|
| 515 |
+
line = sys.stdin.buffer.readline()
|
| 516 |
+
else:
|
| 517 |
+
line = sys.stdin.readline()
|
| 518 |
+
if not line:
|
| 519 |
+
break
|
| 520 |
+
if not inencoding:
|
| 521 |
+
line = guess_decode_from_terminal(line, sys.stdin)[0]
|
| 522 |
+
highlight(line, lexer, fmter, outfile)
|
| 523 |
+
if hasattr(outfile, 'flush'):
|
| 524 |
+
outfile.flush()
|
| 525 |
+
return 0
|
| 526 |
+
except KeyboardInterrupt: # pragma: no cover
|
| 527 |
+
return 0
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
def main(args=sys.argv):
|
| 531 |
+
"""
|
| 532 |
+
Main command line entry point.
|
| 533 |
+
"""
|
| 534 |
+
usage = USAGE % ((args[0],) * 6)
|
| 535 |
+
|
| 536 |
+
try:
|
| 537 |
+
popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:vhVHgsx")
|
| 538 |
+
except getopt.GetoptError:
|
| 539 |
+
print(usage, file=sys.stderr)
|
| 540 |
+
return 2
|
| 541 |
+
|
| 542 |
+
try:
|
| 543 |
+
return main_inner(popts, args, usage)
|
| 544 |
+
except Exception:
|
| 545 |
+
if '-v' in dict(popts):
|
| 546 |
+
print(file=sys.stderr)
|
| 547 |
+
print('*' * 65, file=sys.stderr)
|
| 548 |
+
print('An unhandled exception occurred while highlighting.',
|
| 549 |
+
file=sys.stderr)
|
| 550 |
+
print('Please report the whole traceback to the issue tracker at',
|
| 551 |
+
file=sys.stderr)
|
| 552 |
+
print('<https://bitbucket.org/birkenfeld/pygments-main/issues>.',
|
| 553 |
+
file=sys.stderr)
|
| 554 |
+
print('*' * 65, file=sys.stderr)
|
| 555 |
+
print(file=sys.stderr)
|
| 556 |
+
raise
|
| 557 |
+
import traceback
|
| 558 |
+
info = traceback.format_exception(*sys.exc_info())
|
| 559 |
+
msg = info[-1].strip()
|
| 560 |
+
if len(info) >= 3:
|
| 561 |
+
# extract relevant file and position info
|
| 562 |
+
msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
|
| 563 |
+
print(file=sys.stderr)
|
| 564 |
+
print('*** Error while highlighting:', file=sys.stderr)
|
| 565 |
+
print(msg, file=sys.stderr)
|
| 566 |
+
print('*** If this is a bug you want to report, please rerun with -v.',
|
| 567 |
+
file=sys.stderr)
|
| 568 |
+
return 1
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/console.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.console
|
| 4 |
+
~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Format colored console output.
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
esc = "\x1b["
|
| 13 |
+
|
| 14 |
+
codes = {}
|
| 15 |
+
codes[""] = ""
|
| 16 |
+
codes["reset"] = esc + "39;49;00m"
|
| 17 |
+
|
| 18 |
+
codes["bold"] = esc + "01m"
|
| 19 |
+
codes["faint"] = esc + "02m"
|
| 20 |
+
codes["standout"] = esc + "03m"
|
| 21 |
+
codes["underline"] = esc + "04m"
|
| 22 |
+
codes["blink"] = esc + "05m"
|
| 23 |
+
codes["overline"] = esc + "06m"
|
| 24 |
+
|
| 25 |
+
dark_colors = ["black", "darkred", "darkgreen", "brown", "darkblue",
|
| 26 |
+
"purple", "teal", "lightgray"]
|
| 27 |
+
light_colors = ["darkgray", "red", "green", "yellow", "blue",
|
| 28 |
+
"fuchsia", "turquoise", "white"]
|
| 29 |
+
|
| 30 |
+
x = 30
|
| 31 |
+
for d, l in zip(dark_colors, light_colors):
|
| 32 |
+
codes[d] = esc + "%im" % x
|
| 33 |
+
codes[l] = esc + "%i;01m" % x
|
| 34 |
+
x += 1
|
| 35 |
+
|
| 36 |
+
del d, l, x
|
| 37 |
+
|
| 38 |
+
codes["darkteal"] = codes["turquoise"]
|
| 39 |
+
codes["darkyellow"] = codes["brown"]
|
| 40 |
+
codes["fuscia"] = codes["fuchsia"]
|
| 41 |
+
codes["white"] = codes["bold"]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def reset_color():
|
| 45 |
+
return codes["reset"]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def colorize(color_key, text):
|
| 49 |
+
return codes[color_key] + text + codes["reset"]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def ansiformat(attr, text):
|
| 53 |
+
"""
|
| 54 |
+
Format ``text`` with a color and/or some attributes::
|
| 55 |
+
|
| 56 |
+
color normal color
|
| 57 |
+
*color* bold color
|
| 58 |
+
_color_ underlined color
|
| 59 |
+
+color+ blinking color
|
| 60 |
+
"""
|
| 61 |
+
result = []
|
| 62 |
+
if attr[:1] == attr[-1:] == '+':
|
| 63 |
+
result.append(codes['blink'])
|
| 64 |
+
attr = attr[1:-1]
|
| 65 |
+
if attr[:1] == attr[-1:] == '*':
|
| 66 |
+
result.append(codes['bold'])
|
| 67 |
+
attr = attr[1:-1]
|
| 68 |
+
if attr[:1] == attr[-1:] == '_':
|
| 69 |
+
result.append(codes['underline'])
|
| 70 |
+
attr = attr[1:-1]
|
| 71 |
+
result.append(codes[attr])
|
| 72 |
+
result.append(text)
|
| 73 |
+
result.append(codes['reset'])
|
| 74 |
+
return ''.join(result)
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/filter.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.filter
|
| 4 |
+
~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Module that implements the default filter.
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def apply_filters(stream, filters, lexer=None):
|
| 14 |
+
"""
|
| 15 |
+
Use this method to apply an iterable of filters to
|
| 16 |
+
a stream. If lexer is given it's forwarded to the
|
| 17 |
+
filter, otherwise the filter receives `None`.
|
| 18 |
+
"""
|
| 19 |
+
def _apply(filter_, stream):
|
| 20 |
+
for token in filter_.filter(lexer, stream):
|
| 21 |
+
yield token
|
| 22 |
+
for filter_ in filters:
|
| 23 |
+
stream = _apply(filter_, stream)
|
| 24 |
+
return stream
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def simplefilter(f):
|
| 28 |
+
"""
|
| 29 |
+
Decorator that converts a function into a filter::
|
| 30 |
+
|
| 31 |
+
@simplefilter
|
| 32 |
+
def lowercase(self, lexer, stream, options):
|
| 33 |
+
for ttype, value in stream:
|
| 34 |
+
yield ttype, value.lower()
|
| 35 |
+
"""
|
| 36 |
+
return type(f.__name__, (FunctionFilter,), {
|
| 37 |
+
'__module__': getattr(f, '__module__'),
|
| 38 |
+
'__doc__': f.__doc__,
|
| 39 |
+
'function': f,
|
| 40 |
+
})
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class Filter(object):
|
| 44 |
+
"""
|
| 45 |
+
Default filter. Subclass this class or use the `simplefilter`
|
| 46 |
+
decorator to create own filters.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
def __init__(self, **options):
|
| 50 |
+
self.options = options
|
| 51 |
+
|
| 52 |
+
def filter(self, lexer, stream):
|
| 53 |
+
raise NotImplementedError
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class FunctionFilter(Filter):
|
| 57 |
+
"""
|
| 58 |
+
Abstract class used by `simplefilter` to create simple
|
| 59 |
+
function filters on the fly. The `simplefilter` decorator
|
| 60 |
+
automatically creates subclasses of this class for
|
| 61 |
+
functions passed to it.
|
| 62 |
+
"""
|
| 63 |
+
function = None
|
| 64 |
+
|
| 65 |
+
def __init__(self, **options):
|
| 66 |
+
if not hasattr(self, 'function'):
|
| 67 |
+
raise TypeError('%r used without bound function' %
|
| 68 |
+
self.__class__.__name__)
|
| 69 |
+
Filter.__init__(self, **options)
|
| 70 |
+
|
| 71 |
+
def filter(self, lexer, stream):
|
| 72 |
+
# pylint: disable=not-callable
|
| 73 |
+
for ttype, value in self.function(lexer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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.filters
|
| 4 |
+
~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Module containing filter lookup functions and default
|
| 7 |
+
filters.
|
| 8 |
+
|
| 9 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 10 |
+
:license: BSD, see LICENSE for details.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import re
|
| 14 |
+
|
| 15 |
+
from pygments.token import String, Comment, Keyword, Name, Error, Whitespace, \
|
| 16 |
+
string_to_tokentype
|
| 17 |
+
from pygments.filter import Filter
|
| 18 |
+
from pygments.util import get_list_opt, get_int_opt, get_bool_opt, \
|
| 19 |
+
get_choice_opt, ClassNotFound, OptionError, text_type, string_types
|
| 20 |
+
from pygments.plugin import find_plugin_filters
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def find_filter_class(filtername):
|
| 24 |
+
"""Lookup a filter by name. Return None if not found."""
|
| 25 |
+
if filtername in FILTERS:
|
| 26 |
+
return FILTERS[filtername]
|
| 27 |
+
for name, cls in find_plugin_filters():
|
| 28 |
+
if name == filtername:
|
| 29 |
+
return cls
|
| 30 |
+
return None
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def get_filter_by_name(filtername, **options):
|
| 34 |
+
"""Return an instantiated filter.
|
| 35 |
+
|
| 36 |
+
Options are passed to the filter initializer if wanted.
|
| 37 |
+
Raise a ClassNotFound if not found.
|
| 38 |
+
"""
|
| 39 |
+
cls = find_filter_class(filtername)
|
| 40 |
+
if cls:
|
| 41 |
+
return cls(**options)
|
| 42 |
+
else:
|
| 43 |
+
raise ClassNotFound('filter %r not found' % filtername)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def get_all_filters():
|
| 47 |
+
"""Return a generator of all filter names."""
|
| 48 |
+
for name in FILTERS:
|
| 49 |
+
yield name
|
| 50 |
+
for name, _ in find_plugin_filters():
|
| 51 |
+
yield name
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _replace_special(ttype, value, regex, specialttype,
|
| 55 |
+
replacefunc=lambda x: x):
|
| 56 |
+
last = 0
|
| 57 |
+
for match in regex.finditer(value):
|
| 58 |
+
start, end = match.start(), match.end()
|
| 59 |
+
if start != last:
|
| 60 |
+
yield ttype, value[last:start]
|
| 61 |
+
yield specialttype, replacefunc(value[start:end])
|
| 62 |
+
last = end
|
| 63 |
+
if last != len(value):
|
| 64 |
+
yield ttype, value[last:]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class CodeTagFilter(Filter):
|
| 68 |
+
"""Highlight special code tags in comments and docstrings.
|
| 69 |
+
|
| 70 |
+
Options accepted:
|
| 71 |
+
|
| 72 |
+
`codetags` : list of strings
|
| 73 |
+
A list of strings that are flagged as code tags. The default is to
|
| 74 |
+
highlight ``XXX``, ``TODO``, ``BUG`` and ``NOTE``.
|
| 75 |
+
"""
|
| 76 |
+
|
| 77 |
+
def __init__(self, **options):
|
| 78 |
+
Filter.__init__(self, **options)
|
| 79 |
+
tags = get_list_opt(options, 'codetags',
|
| 80 |
+
['XXX', 'TODO', 'BUG', 'NOTE'])
|
| 81 |
+
self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([
|
| 82 |
+
re.escape(tag) for tag in tags if tag
|
| 83 |
+
]))
|
| 84 |
+
|
| 85 |
+
def filter(self, lexer, stream):
|
| 86 |
+
regex = self.tag_re
|
| 87 |
+
for ttype, value in stream:
|
| 88 |
+
if ttype in String.Doc or \
|
| 89 |
+
ttype in Comment and \
|
| 90 |
+
ttype not in Comment.Preproc:
|
| 91 |
+
for sttype, svalue in _replace_special(ttype, value, regex,
|
| 92 |
+
Comment.Special):
|
| 93 |
+
yield sttype, svalue
|
| 94 |
+
else:
|
| 95 |
+
yield ttype, value
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class KeywordCaseFilter(Filter):
|
| 99 |
+
"""Convert keywords to lowercase or uppercase or capitalize them, which
|
| 100 |
+
means first letter uppercase, rest lowercase.
|
| 101 |
+
|
| 102 |
+
This can be useful e.g. if you highlight Pascal code and want to adapt the
|
| 103 |
+
code to your styleguide.
|
| 104 |
+
|
| 105 |
+
Options accepted:
|
| 106 |
+
|
| 107 |
+
`case` : string
|
| 108 |
+
The casing to convert keywords to. Must be one of ``'lower'``,
|
| 109 |
+
``'upper'`` or ``'capitalize'``. The default is ``'lower'``.
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
def __init__(self, **options):
|
| 113 |
+
Filter.__init__(self, **options)
|
| 114 |
+
case = get_choice_opt(options, 'case',
|
| 115 |
+
['lower', 'upper', 'capitalize'], 'lower')
|
| 116 |
+
self.convert = getattr(text_type, case)
|
| 117 |
+
|
| 118 |
+
def filter(self, lexer, stream):
|
| 119 |
+
for ttype, value in stream:
|
| 120 |
+
if ttype in Keyword:
|
| 121 |
+
yield ttype, self.convert(value)
|
| 122 |
+
else:
|
| 123 |
+
yield ttype, value
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
class NameHighlightFilter(Filter):
|
| 127 |
+
"""Highlight a normal Name (and Name.*) token with a different token type.
|
| 128 |
+
|
| 129 |
+
Example::
|
| 130 |
+
|
| 131 |
+
filter = NameHighlightFilter(
|
| 132 |
+
names=['foo', 'bar', 'baz'],
|
| 133 |
+
tokentype=Name.Function,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
This would highlight the names "foo", "bar" and "baz"
|
| 137 |
+
as functions. `Name.Function` is the default token type.
|
| 138 |
+
|
| 139 |
+
Options accepted:
|
| 140 |
+
|
| 141 |
+
`names` : list of strings
|
| 142 |
+
A list of names that should be given the different token type.
|
| 143 |
+
There is no default.
|
| 144 |
+
`tokentype` : TokenType or string
|
| 145 |
+
A token type or a string containing a token type name that is
|
| 146 |
+
used for highlighting the strings in `names`. The default is
|
| 147 |
+
`Name.Function`.
|
| 148 |
+
"""
|
| 149 |
+
|
| 150 |
+
def __init__(self, **options):
|
| 151 |
+
Filter.__init__(self, **options)
|
| 152 |
+
self.names = set(get_list_opt(options, 'names', []))
|
| 153 |
+
tokentype = options.get('tokentype')
|
| 154 |
+
if tokentype:
|
| 155 |
+
self.tokentype = string_to_tokentype(tokentype)
|
| 156 |
+
else:
|
| 157 |
+
self.tokentype = Name.Function
|
| 158 |
+
|
| 159 |
+
def filter(self, lexer, stream):
|
| 160 |
+
for ttype, value in stream:
|
| 161 |
+
if ttype in Name and value in self.names:
|
| 162 |
+
yield self.tokentype, value
|
| 163 |
+
else:
|
| 164 |
+
yield ttype, value
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
class ErrorToken(Exception):
|
| 168 |
+
pass
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class RaiseOnErrorTokenFilter(Filter):
|
| 172 |
+
"""Raise an exception when the lexer generates an error token.
|
| 173 |
+
|
| 174 |
+
Options accepted:
|
| 175 |
+
|
| 176 |
+
`excclass` : Exception class
|
| 177 |
+
The exception class to raise.
|
| 178 |
+
The default is `pygments.filters.ErrorToken`.
|
| 179 |
+
|
| 180 |
+
.. versionadded:: 0.8
|
| 181 |
+
"""
|
| 182 |
+
|
| 183 |
+
def __init__(self, **options):
|
| 184 |
+
Filter.__init__(self, **options)
|
| 185 |
+
self.exception = options.get('excclass', ErrorToken)
|
| 186 |
+
try:
|
| 187 |
+
# issubclass() will raise TypeError if first argument is not a class
|
| 188 |
+
if not issubclass(self.exception, Exception):
|
| 189 |
+
raise TypeError
|
| 190 |
+
except TypeError:
|
| 191 |
+
raise OptionError('excclass option is not an exception class')
|
| 192 |
+
|
| 193 |
+
def filter(self, lexer, stream):
|
| 194 |
+
for ttype, value in stream:
|
| 195 |
+
if ttype is Error:
|
| 196 |
+
raise self.exception(value)
|
| 197 |
+
yield ttype, value
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
class VisibleWhitespaceFilter(Filter):
|
| 201 |
+
"""Convert tabs, newlines and/or spaces to visible characters.
|
| 202 |
+
|
| 203 |
+
Options accepted:
|
| 204 |
+
|
| 205 |
+
`spaces` : string or bool
|
| 206 |
+
If this is a one-character string, spaces will be replaces by this string.
|
| 207 |
+
If it is another true value, spaces will be replaced by ``·`` (unicode
|
| 208 |
+
MIDDLE DOT). If it is a false value, spaces will not be replaced. The
|
| 209 |
+
default is ``False``.
|
| 210 |
+
`tabs` : string or bool
|
| 211 |
+
The same as for `spaces`, but the default replacement character is ``»``
|
| 212 |
+
(unicode RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK). The default value
|
| 213 |
+
is ``False``. Note: this will not work if the `tabsize` option for the
|
| 214 |
+
lexer is nonzero, as tabs will already have been expanded then.
|
| 215 |
+
`tabsize` : int
|
| 216 |
+
If tabs are to be replaced by this filter (see the `tabs` option), this
|
| 217 |
+
is the total number of characters that a tab should be expanded to.
|
| 218 |
+
The default is ``8``.
|
| 219 |
+
`newlines` : string or bool
|
| 220 |
+
The same as for `spaces`, but the default replacement character is ``¶``
|
| 221 |
+
(unicode PILCROW SIGN). The default value is ``False``.
|
| 222 |
+
`wstokentype` : bool
|
| 223 |
+
If true, give whitespace the special `Whitespace` token type. This allows
|
| 224 |
+
styling the visible whitespace differently (e.g. greyed out), but it can
|
| 225 |
+
disrupt background colors. The default is ``True``.
|
| 226 |
+
|
| 227 |
+
.. versionadded:: 0.8
|
| 228 |
+
"""
|
| 229 |
+
|
| 230 |
+
def __init__(self, **options):
|
| 231 |
+
Filter.__init__(self, **options)
|
| 232 |
+
for name, default in [('spaces', u'·'),
|
| 233 |
+
('tabs', u'»'),
|
| 234 |
+
('newlines', u'¶')]:
|
| 235 |
+
opt = options.get(name, False)
|
| 236 |
+
if isinstance(opt, string_types) and len(opt) == 1:
|
| 237 |
+
setattr(self, name, opt)
|
| 238 |
+
else:
|
| 239 |
+
setattr(self, name, (opt and default or ''))
|
| 240 |
+
tabsize = get_int_opt(options, 'tabsize', 8)
|
| 241 |
+
if self.tabs:
|
| 242 |
+
self.tabs += ' ' * (tabsize - 1)
|
| 243 |
+
if self.newlines:
|
| 244 |
+
self.newlines += '\n'
|
| 245 |
+
self.wstt = get_bool_opt(options, 'wstokentype', True)
|
| 246 |
+
|
| 247 |
+
def filter(self, lexer, stream):
|
| 248 |
+
if self.wstt:
|
| 249 |
+
spaces = self.spaces or u' '
|
| 250 |
+
tabs = self.tabs or u'\t'
|
| 251 |
+
newlines = self.newlines or u'\n'
|
| 252 |
+
regex = re.compile(r'\s')
|
| 253 |
+
def replacefunc(wschar):
|
| 254 |
+
if wschar == ' ':
|
| 255 |
+
return spaces
|
| 256 |
+
elif wschar == '\t':
|
| 257 |
+
return tabs
|
| 258 |
+
elif wschar == '\n':
|
| 259 |
+
return newlines
|
| 260 |
+
return wschar
|
| 261 |
+
|
| 262 |
+
for ttype, value in stream:
|
| 263 |
+
for sttype, svalue in _replace_special(ttype, value, regex,
|
| 264 |
+
Whitespace, replacefunc):
|
| 265 |
+
yield sttype, svalue
|
| 266 |
+
else:
|
| 267 |
+
spaces, tabs, newlines = self.spaces, self.tabs, self.newlines
|
| 268 |
+
# simpler processing
|
| 269 |
+
for ttype, value in stream:
|
| 270 |
+
if spaces:
|
| 271 |
+
value = value.replace(' ', spaces)
|
| 272 |
+
if tabs:
|
| 273 |
+
value = value.replace('\t', tabs)
|
| 274 |
+
if newlines:
|
| 275 |
+
value = value.replace('\n', newlines)
|
| 276 |
+
yield ttype, value
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
class GobbleFilter(Filter):
|
| 280 |
+
"""Gobbles source code lines (eats initial characters).
|
| 281 |
+
|
| 282 |
+
This filter drops the first ``n`` characters off every line of code. This
|
| 283 |
+
may be useful when the source code fed to the lexer is indented by a fixed
|
| 284 |
+
amount of space that isn't desired in the output.
|
| 285 |
+
|
| 286 |
+
Options accepted:
|
| 287 |
+
|
| 288 |
+
`n` : int
|
| 289 |
+
The number of characters to gobble.
|
| 290 |
+
|
| 291 |
+
.. versionadded:: 1.2
|
| 292 |
+
"""
|
| 293 |
+
def __init__(self, **options):
|
| 294 |
+
Filter.__init__(self, **options)
|
| 295 |
+
self.n = get_int_opt(options, 'n', 0)
|
| 296 |
+
|
| 297 |
+
def gobble(self, value, left):
|
| 298 |
+
if left < len(value):
|
| 299 |
+
return value[left:], 0
|
| 300 |
+
else:
|
| 301 |
+
return u'', left - len(value)
|
| 302 |
+
|
| 303 |
+
def filter(self, lexer, stream):
|
| 304 |
+
n = self.n
|
| 305 |
+
left = n # How many characters left to gobble.
|
| 306 |
+
for ttype, value in stream:
|
| 307 |
+
# Remove ``left`` tokens from first line, ``n`` from all others.
|
| 308 |
+
parts = value.split('\n')
|
| 309 |
+
(parts[0], left) = self.gobble(parts[0], left)
|
| 310 |
+
for i in range(1, len(parts)):
|
| 311 |
+
(parts[i], left) = self.gobble(parts[i], n)
|
| 312 |
+
value = u'\n'.join(parts)
|
| 313 |
+
|
| 314 |
+
if value != '':
|
| 315 |
+
yield ttype, value
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
class TokenMergeFilter(Filter):
|
| 319 |
+
"""Merges consecutive tokens with the same token type in the output
|
| 320 |
+
stream of a lexer.
|
| 321 |
+
|
| 322 |
+
.. versionadded:: 1.2
|
| 323 |
+
"""
|
| 324 |
+
def __init__(self, **options):
|
| 325 |
+
Filter.__init__(self, **options)
|
| 326 |
+
|
| 327 |
+
def filter(self, lexer, stream):
|
| 328 |
+
current_type = None
|
| 329 |
+
current_value = None
|
| 330 |
+
for ttype, value in stream:
|
| 331 |
+
if ttype is current_type:
|
| 332 |
+
current_value += value
|
| 333 |
+
else:
|
| 334 |
+
if current_type is not None:
|
| 335 |
+
yield current_type, current_value
|
| 336 |
+
current_type = ttype
|
| 337 |
+
current_value = value
|
| 338 |
+
if current_type is not None:
|
| 339 |
+
yield current_type, current_value
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
FILTERS = {
|
| 343 |
+
'codetagify': CodeTagFilter,
|
| 344 |
+
'keywordcase': KeywordCaseFilter,
|
| 345 |
+
'highlight': NameHighlightFilter,
|
| 346 |
+
'raiseonerror': RaiseOnErrorTokenFilter,
|
| 347 |
+
'whitespace': VisibleWhitespaceFilter,
|
| 348 |
+
'gobble': GobbleFilter,
|
| 349 |
+
'tokenmerge': TokenMergeFilter,
|
| 350 |
+
}
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/filters/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatter.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.formatter
|
| 4 |
+
~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Base formatter class.
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import codecs
|
| 13 |
+
|
| 14 |
+
from pygments.util import get_bool_opt, string_types
|
| 15 |
+
from pygments.styles import get_style_by_name
|
| 16 |
+
|
| 17 |
+
__all__ = ['Formatter']
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _lookup_style(style):
|
| 21 |
+
if isinstance(style, string_types):
|
| 22 |
+
return get_style_by_name(style)
|
| 23 |
+
return style
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class Formatter(object):
|
| 27 |
+
"""
|
| 28 |
+
Converts a token stream to text.
|
| 29 |
+
|
| 30 |
+
Options accepted:
|
| 31 |
+
|
| 32 |
+
``style``
|
| 33 |
+
The style to use, can be a string or a Style subclass
|
| 34 |
+
(default: "default"). Not used by e.g. the
|
| 35 |
+
TerminalFormatter.
|
| 36 |
+
``full``
|
| 37 |
+
Tells the formatter to output a "full" document, i.e.
|
| 38 |
+
a complete self-contained document. This doesn't have
|
| 39 |
+
any effect for some formatters (default: false).
|
| 40 |
+
``title``
|
| 41 |
+
If ``full`` is true, the title that should be used to
|
| 42 |
+
caption the document (default: '').
|
| 43 |
+
``encoding``
|
| 44 |
+
If given, must be an encoding name. This will be used to
|
| 45 |
+
convert the Unicode token strings to byte strings in the
|
| 46 |
+
output. If it is "" or None, Unicode strings will be written
|
| 47 |
+
to the output file, which most file-like objects do not
|
| 48 |
+
support (default: None).
|
| 49 |
+
``outencoding``
|
| 50 |
+
Overrides ``encoding`` if given.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
#: Name of the formatter
|
| 54 |
+
name = None
|
| 55 |
+
|
| 56 |
+
#: Shortcuts for the formatter
|
| 57 |
+
aliases = []
|
| 58 |
+
|
| 59 |
+
#: fn match rules
|
| 60 |
+
filenames = []
|
| 61 |
+
|
| 62 |
+
#: If True, this formatter outputs Unicode strings when no encoding
|
| 63 |
+
#: option is given.
|
| 64 |
+
unicodeoutput = True
|
| 65 |
+
|
| 66 |
+
def __init__(self, **options):
|
| 67 |
+
self.style = _lookup_style(options.get('style', 'default'))
|
| 68 |
+
self.full = get_bool_opt(options, 'full', False)
|
| 69 |
+
self.title = options.get('title', '')
|
| 70 |
+
self.encoding = options.get('encoding', None) or None
|
| 71 |
+
if self.encoding in ('guess', 'chardet'):
|
| 72 |
+
# can happen for e.g. pygmentize -O encoding=guess
|
| 73 |
+
self.encoding = 'utf-8'
|
| 74 |
+
self.encoding = options.get('outencoding') or self.encoding
|
| 75 |
+
self.options = options
|
| 76 |
+
|
| 77 |
+
def get_style_defs(self, arg=''):
|
| 78 |
+
"""
|
| 79 |
+
Return the style definitions for the current style as a string.
|
| 80 |
+
|
| 81 |
+
``arg`` is an additional argument whose meaning depends on the
|
| 82 |
+
formatter used. Note that ``arg`` can also be a list or tuple
|
| 83 |
+
for some formatters like the html formatter.
|
| 84 |
+
"""
|
| 85 |
+
return ''
|
| 86 |
+
|
| 87 |
+
def format(self, tokensource, outfile):
|
| 88 |
+
"""
|
| 89 |
+
Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
|
| 90 |
+
tuples and write it into ``outfile``.
|
| 91 |
+
"""
|
| 92 |
+
if self.encoding:
|
| 93 |
+
# wrap the outfile in a StreamWriter
|
| 94 |
+
outfile = codecs.lookup(self.encoding)[3](outfile)
|
| 95 |
+
return self.format_unencoded(tokensource, outfile)
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__init__.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 11 |
+
|
| 12 |
+
import re
|
| 13 |
+
import sys
|
| 14 |
+
import types
|
| 15 |
+
import fnmatch
|
| 16 |
+
from os.path import basename
|
| 17 |
+
|
| 18 |
+
from pygments.formatters._mapping import FORMATTERS
|
| 19 |
+
from pygments.plugin import find_plugin_formatters
|
| 20 |
+
from pygments.util import ClassNotFound, itervalues
|
| 21 |
+
|
| 22 |
+
__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
|
| 23 |
+
'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS)
|
| 24 |
+
|
| 25 |
+
_formatter_cache = {} # classes by name
|
| 26 |
+
_pattern_cache = {}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _fn_matches(fn, glob):
|
| 30 |
+
"""Return whether the supplied file name fn matches pattern filename."""
|
| 31 |
+
if glob not in _pattern_cache:
|
| 32 |
+
pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
|
| 33 |
+
return pattern.match(fn)
|
| 34 |
+
return _pattern_cache[glob].match(fn)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _load_formatters(module_name):
|
| 38 |
+
"""Load a formatter (and all others in the module too)."""
|
| 39 |
+
mod = __import__(module_name, None, None, ['__all__'])
|
| 40 |
+
for formatter_name in mod.__all__:
|
| 41 |
+
cls = getattr(mod, formatter_name)
|
| 42 |
+
_formatter_cache[cls.name] = cls
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def get_all_formatters():
|
| 46 |
+
"""Return a generator for all formatter classes."""
|
| 47 |
+
# NB: this returns formatter classes, not info like get_all_lexers().
|
| 48 |
+
for info in itervalues(FORMATTERS):
|
| 49 |
+
if info[1] not in _formatter_cache:
|
| 50 |
+
_load_formatters(info[0])
|
| 51 |
+
yield _formatter_cache[info[1]]
|
| 52 |
+
for _, formatter in find_plugin_formatters():
|
| 53 |
+
yield formatter
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def find_formatter_class(alias):
|
| 57 |
+
"""Lookup a formatter by alias.
|
| 58 |
+
|
| 59 |
+
Returns None if not found.
|
| 60 |
+
"""
|
| 61 |
+
for module_name, name, aliases, _, _ in itervalues(FORMATTERS):
|
| 62 |
+
if alias in aliases:
|
| 63 |
+
if name not in _formatter_cache:
|
| 64 |
+
_load_formatters(module_name)
|
| 65 |
+
return _formatter_cache[name]
|
| 66 |
+
for _, cls in find_plugin_formatters():
|
| 67 |
+
if alias in cls.aliases:
|
| 68 |
+
return cls
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def get_formatter_by_name(_alias, **options):
|
| 72 |
+
"""Lookup and instantiate a formatter by alias.
|
| 73 |
+
|
| 74 |
+
Raises ClassNotFound if not found.
|
| 75 |
+
"""
|
| 76 |
+
cls = find_formatter_class(_alias)
|
| 77 |
+
if cls is None:
|
| 78 |
+
raise ClassNotFound("no formatter found for name %r" % _alias)
|
| 79 |
+
return cls(**options)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def load_formatter_from_file(filename, formattername="CustomFormatter",
|
| 83 |
+
**options):
|
| 84 |
+
"""Load a formatter from a file.
|
| 85 |
+
|
| 86 |
+
This method expects a file located relative to the current working
|
| 87 |
+
directory, which contains a class named CustomFormatter. By default,
|
| 88 |
+
it expects the Formatter to be named CustomFormatter; you can specify
|
| 89 |
+
your own class name as the second argument to this function.
|
| 90 |
+
|
| 91 |
+
Users should be very careful with the input, because this method
|
| 92 |
+
is equivalent to running eval on the input file.
|
| 93 |
+
|
| 94 |
+
Raises ClassNotFound if there are any problems importing the Formatter.
|
| 95 |
+
|
| 96 |
+
.. versionadded:: 2.2
|
| 97 |
+
"""
|
| 98 |
+
try:
|
| 99 |
+
# This empty dict will contain the namespace for the exec'd file
|
| 100 |
+
custom_namespace = {}
|
| 101 |
+
exec(open(filename, 'rb').read(), custom_namespace)
|
| 102 |
+
# Retrieve the class `formattername` from that namespace
|
| 103 |
+
if formattername not in custom_namespace:
|
| 104 |
+
raise ClassNotFound('no valid %s class found in %s' %
|
| 105 |
+
(formattername, filename))
|
| 106 |
+
formatter_class = custom_namespace[formattername]
|
| 107 |
+
# And finally instantiate it with the options
|
| 108 |
+
return formatter_class(**options)
|
| 109 |
+
except IOError as err:
|
| 110 |
+
raise ClassNotFound('cannot read %s' % filename)
|
| 111 |
+
except ClassNotFound as err:
|
| 112 |
+
raise
|
| 113 |
+
except Exception as err:
|
| 114 |
+
raise ClassNotFound('error when loading custom formatter: %s' % err)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def get_formatter_for_filename(fn, **options):
|
| 118 |
+
"""Lookup and instantiate a formatter by filename pattern.
|
| 119 |
+
|
| 120 |
+
Raises ClassNotFound if not found.
|
| 121 |
+
"""
|
| 122 |
+
fn = basename(fn)
|
| 123 |
+
for modname, name, _, filenames, _ in itervalues(FORMATTERS):
|
| 124 |
+
for filename in filenames:
|
| 125 |
+
if _fn_matches(fn, filename):
|
| 126 |
+
if name not in _formatter_cache:
|
| 127 |
+
_load_formatters(modname)
|
| 128 |
+
return _formatter_cache[name](**options)
|
| 129 |
+
for cls in find_plugin_formatters():
|
| 130 |
+
for filename in cls.filenames:
|
| 131 |
+
if _fn_matches(fn, filename):
|
| 132 |
+
return cls(**options)
|
| 133 |
+
raise ClassNotFound("no formatter found for file name %r" % fn)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class _automodule(types.ModuleType):
|
| 137 |
+
"""Automatically import formatters."""
|
| 138 |
+
|
| 139 |
+
def __getattr__(self, name):
|
| 140 |
+
info = FORMATTERS.get(name)
|
| 141 |
+
if info:
|
| 142 |
+
_load_formatters(info[0])
|
| 143 |
+
cls = _formatter_cache[info[1]]
|
| 144 |
+
setattr(self, name, cls)
|
| 145 |
+
return cls
|
| 146 |
+
raise AttributeError(name)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
oldmod = sys.modules[__name__]
|
| 150 |
+
newmod = _automodule(__name__)
|
| 151 |
+
newmod.__dict__.update(oldmod.__dict__)
|
| 152 |
+
sys.modules[__name__] = newmod
|
| 153 |
+
del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (4.59 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/_mapping.cpython-310.pyc
ADDED
|
Binary file (5.21 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/bbcode.cpython-310.pyc
ADDED
|
Binary file (3.04 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/html.cpython-310.pyc
ADDED
|
Binary file (25.7 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/img.cpython-310.pyc
ADDED
|
Binary file (16.5 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/irc.cpython-310.pyc
ADDED
|
Binary file (4.51 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/latex.cpython-310.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/other.cpython-310.pyc
ADDED
|
Binary file (4.96 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/rtf.cpython-310.pyc
ADDED
|
Binary file (4.09 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/svg.cpython-310.pyc
ADDED
|
Binary file (5.31 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/terminal.cpython-310.pyc
ADDED
|
Binary file (4.04 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/__pycache__/terminal256.cpython-310.pyc
ADDED
|
Binary file (8.36 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/_mapping.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.formatters._mapping
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Formatter mapping definitions. This file is generated by itself. Everytime
|
| 7 |
+
you change something on a builtin formatter definition, run this script from
|
| 8 |
+
the formatters folder to update it.
|
| 9 |
+
|
| 10 |
+
Do not alter the FORMATTERS dictionary by hand.
|
| 11 |
+
|
| 12 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 13 |
+
:license: BSD, see LICENSE for details.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from __future__ import print_function
|
| 17 |
+
|
| 18 |
+
FORMATTERS = {
|
| 19 |
+
'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'),
|
| 20 |
+
'BmpImageFormatter': ('pygments.formatters.img', 'img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
| 21 |
+
'GifImageFormatter': ('pygments.formatters.img', 'img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
| 22 |
+
'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` option."),
|
| 23 |
+
'IRCFormatter': ('pygments.formatters.irc', 'IRC', ('irc', 'IRC'), (), 'Format tokens with IRC color sequences'),
|
| 24 |
+
'ImageFormatter': ('pygments.formatters.img', 'img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
| 25 |
+
'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
| 26 |
+
'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
|
| 27 |
+
'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
|
| 28 |
+
'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
|
| 29 |
+
'RtfFormatter': ('pygments.formatters.rtf', 'RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.'),
|
| 30 |
+
'SvgFormatter': ('pygments.formatters.svg', 'SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'),
|
| 31 |
+
'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
|
| 32 |
+
'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'),
|
| 33 |
+
'TerminalTrueColorFormatter': ('pygments.formatters.terminal256', 'TerminalTrueColor', ('terminal16m', 'console16m', '16m'), (), 'Format tokens with ANSI color sequences, for output in a true-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
|
| 34 |
+
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if __name__ == '__main__': # pragma: no cover
|
| 38 |
+
import sys
|
| 39 |
+
import os
|
| 40 |
+
|
| 41 |
+
# lookup formatters
|
| 42 |
+
found_formatters = []
|
| 43 |
+
imports = []
|
| 44 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
| 45 |
+
from pygments.util import docstring_headline
|
| 46 |
+
|
| 47 |
+
for root, dirs, files in os.walk('.'):
|
| 48 |
+
for filename in files:
|
| 49 |
+
if filename.endswith('.py') and not filename.startswith('_'):
|
| 50 |
+
module_name = 'pygments.formatters%s.%s' % (
|
| 51 |
+
root[1:].replace('/', '.'), filename[:-3])
|
| 52 |
+
print(module_name)
|
| 53 |
+
module = __import__(module_name, None, None, [''])
|
| 54 |
+
for formatter_name in module.__all__:
|
| 55 |
+
formatter = getattr(module, formatter_name)
|
| 56 |
+
found_formatters.append(
|
| 57 |
+
'%r: %r' % (formatter_name,
|
| 58 |
+
(module_name,
|
| 59 |
+
formatter.name,
|
| 60 |
+
tuple(formatter.aliases),
|
| 61 |
+
tuple(formatter.filenames),
|
| 62 |
+
docstring_headline(formatter))))
|
| 63 |
+
# sort them to make the diff minimal
|
| 64 |
+
found_formatters.sort()
|
| 65 |
+
|
| 66 |
+
# extract useful sourcecode from this file
|
| 67 |
+
with open(__file__) as fp:
|
| 68 |
+
content = fp.read()
|
| 69 |
+
# replace crnl to nl for Windows.
|
| 70 |
+
#
|
| 71 |
+
# Note that, originally, contributers should keep nl of master
|
| 72 |
+
# repository, for example by using some kind of automatic
|
| 73 |
+
# management EOL, like `EolExtension
|
| 74 |
+
# <https://www.mercurial-scm.org/wiki/EolExtension>`.
|
| 75 |
+
content = content.replace("\r\n", "\n")
|
| 76 |
+
header = content[:content.find('FORMATTERS = {')]
|
| 77 |
+
footer = content[content.find("if __name__ == '__main__':"):]
|
| 78 |
+
|
| 79 |
+
# write new file
|
| 80 |
+
with open(__file__, 'w') as fp:
|
| 81 |
+
fp.write(header)
|
| 82 |
+
fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
|
| 83 |
+
fp.write(footer)
|
| 84 |
+
|
| 85 |
+
print ('=== %d formatters processed.' % len(found_formatters))
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/bbcode.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.formatters.bbcode
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
BBcode formatter.
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
from pygments.formatter import Formatter
|
| 14 |
+
from pygments.util import get_bool_opt
|
| 15 |
+
|
| 16 |
+
__all__ = ['BBCodeFormatter']
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class BBCodeFormatter(Formatter):
|
| 20 |
+
"""
|
| 21 |
+
Format tokens with BBcodes. These formatting codes are used by many
|
| 22 |
+
bulletin boards, so you can highlight your sourcecode with pygments before
|
| 23 |
+
posting it there.
|
| 24 |
+
|
| 25 |
+
This formatter has no support for background colors and borders, as there
|
| 26 |
+
are no common BBcode tags for that.
|
| 27 |
+
|
| 28 |
+
Some board systems (e.g. phpBB) don't support colors in their [code] tag,
|
| 29 |
+
so you can't use the highlighting together with that tag.
|
| 30 |
+
Text in a [code] tag usually is shown with a monospace font (which this
|
| 31 |
+
formatter can do with the ``monofont`` option) and no spaces (which you
|
| 32 |
+
need for indentation) are removed.
|
| 33 |
+
|
| 34 |
+
Additional options accepted:
|
| 35 |
+
|
| 36 |
+
`style`
|
| 37 |
+
The style to use, can be a string or a Style subclass (default:
|
| 38 |
+
``'default'``).
|
| 39 |
+
|
| 40 |
+
`codetag`
|
| 41 |
+
If set to true, put the output into ``[code]`` tags (default:
|
| 42 |
+
``false``)
|
| 43 |
+
|
| 44 |
+
`monofont`
|
| 45 |
+
If set to true, add a tag to show the code with a monospace font
|
| 46 |
+
(default: ``false``).
|
| 47 |
+
"""
|
| 48 |
+
name = 'BBCode'
|
| 49 |
+
aliases = ['bbcode', 'bb']
|
| 50 |
+
filenames = []
|
| 51 |
+
|
| 52 |
+
def __init__(self, **options):
|
| 53 |
+
Formatter.__init__(self, **options)
|
| 54 |
+
self._code = get_bool_opt(options, 'codetag', False)
|
| 55 |
+
self._mono = get_bool_opt(options, 'monofont', False)
|
| 56 |
+
|
| 57 |
+
self.styles = {}
|
| 58 |
+
self._make_styles()
|
| 59 |
+
|
| 60 |
+
def _make_styles(self):
|
| 61 |
+
for ttype, ndef in self.style:
|
| 62 |
+
start = end = ''
|
| 63 |
+
if ndef['color']:
|
| 64 |
+
start += '[color=#%s]' % ndef['color']
|
| 65 |
+
end = '[/color]' + end
|
| 66 |
+
if ndef['bold']:
|
| 67 |
+
start += '[b]'
|
| 68 |
+
end = '[/b]' + end
|
| 69 |
+
if ndef['italic']:
|
| 70 |
+
start += '[i]'
|
| 71 |
+
end = '[/i]' + end
|
| 72 |
+
if ndef['underline']:
|
| 73 |
+
start += '[u]'
|
| 74 |
+
end = '[/u]' + end
|
| 75 |
+
# there are no common BBcodes for background-color and border
|
| 76 |
+
|
| 77 |
+
self.styles[ttype] = start, end
|
| 78 |
+
|
| 79 |
+
def format_unencoded(self, tokensource, outfile):
|
| 80 |
+
if self._code:
|
| 81 |
+
outfile.write('[code]')
|
| 82 |
+
if self._mono:
|
| 83 |
+
outfile.write('[font=monospace]')
|
| 84 |
+
|
| 85 |
+
lastval = ''
|
| 86 |
+
lasttype = None
|
| 87 |
+
|
| 88 |
+
for ttype, value in tokensource:
|
| 89 |
+
while ttype not in self.styles:
|
| 90 |
+
ttype = ttype.parent
|
| 91 |
+
if ttype == lasttype:
|
| 92 |
+
lastval += value
|
| 93 |
+
else:
|
| 94 |
+
if lastval:
|
| 95 |
+
start, end = self.styles[lasttype]
|
| 96 |
+
outfile.write(''.join((start, lastval, end)))
|
| 97 |
+
lastval = value
|
| 98 |
+
lasttype = ttype
|
| 99 |
+
|
| 100 |
+
if lastval:
|
| 101 |
+
start, end = self.styles[lasttype]
|
| 102 |
+
outfile.write(''.join((start, lastval, end)))
|
| 103 |
+
|
| 104 |
+
if self._mono:
|
| 105 |
+
outfile.write('[/font]')
|
| 106 |
+
if self._code:
|
| 107 |
+
outfile.write('[/code]')
|
| 108 |
+
if self._code or self._mono:
|
| 109 |
+
outfile.write('\n')
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/html.py
ADDED
|
@@ -0,0 +1,851 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.formatters.html
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Formatter for HTML output.
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import print_function
|
| 13 |
+
|
| 14 |
+
import os
|
| 15 |
+
import sys
|
| 16 |
+
import os.path
|
| 17 |
+
|
| 18 |
+
from pygments.formatter import Formatter
|
| 19 |
+
from pygments.token import Token, Text, STANDARD_TYPES
|
| 20 |
+
from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
|
| 21 |
+
StringIO, string_types, iteritems
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
import ctags
|
| 25 |
+
except ImportError:
|
| 26 |
+
ctags = None
|
| 27 |
+
|
| 28 |
+
__all__ = ['HtmlFormatter']
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
_escape_html_table = {
|
| 32 |
+
ord('&'): u'&',
|
| 33 |
+
ord('<'): u'<',
|
| 34 |
+
ord('>'): u'>',
|
| 35 |
+
ord('"'): u'"',
|
| 36 |
+
ord("'"): u''',
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def escape_html(text, table=_escape_html_table):
|
| 41 |
+
"""Escape &, <, > as well as single and double quotes for HTML."""
|
| 42 |
+
return text.translate(table)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def _get_ttype_class(ttype):
|
| 46 |
+
fname = STANDARD_TYPES.get(ttype)
|
| 47 |
+
if fname:
|
| 48 |
+
return fname
|
| 49 |
+
aname = ''
|
| 50 |
+
while fname is None:
|
| 51 |
+
aname = '-' + ttype[-1] + aname
|
| 52 |
+
ttype = ttype.parent
|
| 53 |
+
fname = STANDARD_TYPES.get(ttype)
|
| 54 |
+
return fname + aname
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
CSSFILE_TEMPLATE = '''\
|
| 58 |
+
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
|
| 59 |
+
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
|
| 60 |
+
pre { line-height: 125%%; }
|
| 61 |
+
%(styledefs)s
|
| 62 |
+
'''
|
| 63 |
+
|
| 64 |
+
DOC_HEADER = '''\
|
| 65 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
| 66 |
+
"http://www.w3.org/TR/html4/strict.dtd">
|
| 67 |
+
|
| 68 |
+
<html>
|
| 69 |
+
<head>
|
| 70 |
+
<title>%(title)s</title>
|
| 71 |
+
<meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
|
| 72 |
+
<style type="text/css">
|
| 73 |
+
''' + CSSFILE_TEMPLATE + '''
|
| 74 |
+
</style>
|
| 75 |
+
</head>
|
| 76 |
+
<body>
|
| 77 |
+
<h2>%(title)s</h2>
|
| 78 |
+
|
| 79 |
+
'''
|
| 80 |
+
|
| 81 |
+
DOC_HEADER_EXTERNALCSS = '''\
|
| 82 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
| 83 |
+
"http://www.w3.org/TR/html4/strict.dtd">
|
| 84 |
+
|
| 85 |
+
<html>
|
| 86 |
+
<head>
|
| 87 |
+
<title>%(title)s</title>
|
| 88 |
+
<meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
|
| 89 |
+
<link rel="stylesheet" href="%(cssfile)s" type="text/css">
|
| 90 |
+
</head>
|
| 91 |
+
<body>
|
| 92 |
+
<h2>%(title)s</h2>
|
| 93 |
+
|
| 94 |
+
'''
|
| 95 |
+
|
| 96 |
+
DOC_FOOTER = '''\
|
| 97 |
+
</body>
|
| 98 |
+
</html>
|
| 99 |
+
'''
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class HtmlFormatter(Formatter):
|
| 103 |
+
r"""
|
| 104 |
+
Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped
|
| 105 |
+
in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass`
|
| 106 |
+
option.
|
| 107 |
+
|
| 108 |
+
If the `linenos` option is set to ``"table"``, the ``<pre>`` is
|
| 109 |
+
additionally wrapped inside a ``<table>`` which has one row and two
|
| 110 |
+
cells: one containing the line numbers and one containing the code.
|
| 111 |
+
Example:
|
| 112 |
+
|
| 113 |
+
.. sourcecode:: html
|
| 114 |
+
|
| 115 |
+
<div class="highlight" >
|
| 116 |
+
<table><tr>
|
| 117 |
+
<td class="linenos" title="click to toggle"
|
| 118 |
+
onclick="with (this.firstChild.style)
|
| 119 |
+
{ display = (display == '') ? 'none' : '' }">
|
| 120 |
+
<pre>1
|
| 121 |
+
2</pre>
|
| 122 |
+
</td>
|
| 123 |
+
<td class="code">
|
| 124 |
+
<pre><span class="Ke">def </span><span class="NaFu">foo</span>(bar):
|
| 125 |
+
<span class="Ke">pass</span>
|
| 126 |
+
</pre>
|
| 127 |
+
</td>
|
| 128 |
+
</tr></table></div>
|
| 129 |
+
|
| 130 |
+
(whitespace added to improve clarity).
|
| 131 |
+
|
| 132 |
+
Wrapping can be disabled using the `nowrap` option.
|
| 133 |
+
|
| 134 |
+
A list of lines can be specified using the `hl_lines` option to make these
|
| 135 |
+
lines highlighted (as of Pygments 0.11).
|
| 136 |
+
|
| 137 |
+
With the `full` option, a complete HTML 4 document is output, including
|
| 138 |
+
the style definitions inside a ``<style>`` tag, or in a separate file if
|
| 139 |
+
the `cssfile` option is given.
|
| 140 |
+
|
| 141 |
+
When `tagsfile` is set to the path of a ctags index file, it is used to
|
| 142 |
+
generate hyperlinks from names to their definition. You must enable
|
| 143 |
+
`lineanchors` and run ctags with the `-n` option for this to work. The
|
| 144 |
+
`python-ctags` module from PyPI must be installed to use this feature;
|
| 145 |
+
otherwise a `RuntimeError` will be raised.
|
| 146 |
+
|
| 147 |
+
The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string
|
| 148 |
+
containing CSS rules for the CSS classes used by the formatter. The
|
| 149 |
+
argument `arg` can be used to specify additional CSS selectors that
|
| 150 |
+
are prepended to the classes. A call `fmter.get_style_defs('td .code')`
|
| 151 |
+
would result in the following CSS classes:
|
| 152 |
+
|
| 153 |
+
.. sourcecode:: css
|
| 154 |
+
|
| 155 |
+
td .code .kw { font-weight: bold; color: #00FF00 }
|
| 156 |
+
td .code .cm { color: #999999 }
|
| 157 |
+
...
|
| 158 |
+
|
| 159 |
+
If you have Pygments 0.6 or higher, you can also pass a list or tuple to the
|
| 160 |
+
`get_style_defs()` method to request multiple prefixes for the tokens:
|
| 161 |
+
|
| 162 |
+
.. sourcecode:: python
|
| 163 |
+
|
| 164 |
+
formatter.get_style_defs(['div.syntax pre', 'pre.syntax'])
|
| 165 |
+
|
| 166 |
+
The output would then look like this:
|
| 167 |
+
|
| 168 |
+
.. sourcecode:: css
|
| 169 |
+
|
| 170 |
+
div.syntax pre .kw,
|
| 171 |
+
pre.syntax .kw { font-weight: bold; color: #00FF00 }
|
| 172 |
+
div.syntax pre .cm,
|
| 173 |
+
pre.syntax .cm { color: #999999 }
|
| 174 |
+
...
|
| 175 |
+
|
| 176 |
+
Additional options accepted:
|
| 177 |
+
|
| 178 |
+
`nowrap`
|
| 179 |
+
If set to ``True``, don't wrap the tokens at all, not even inside a ``<pre>``
|
| 180 |
+
tag. This disables most other options (default: ``False``).
|
| 181 |
+
|
| 182 |
+
`full`
|
| 183 |
+
Tells the formatter to output a "full" document, i.e. a complete
|
| 184 |
+
self-contained document (default: ``False``).
|
| 185 |
+
|
| 186 |
+
`title`
|
| 187 |
+
If `full` is true, the title that should be used to caption the
|
| 188 |
+
document (default: ``''``).
|
| 189 |
+
|
| 190 |
+
`style`
|
| 191 |
+
The style to use, can be a string or a Style subclass (default:
|
| 192 |
+
``'default'``). This option has no effect if the `cssfile`
|
| 193 |
+
and `noclobber_cssfile` option are given and the file specified in
|
| 194 |
+
`cssfile` exists.
|
| 195 |
+
|
| 196 |
+
`noclasses`
|
| 197 |
+
If set to true, token ``<span>`` tags will not use CSS classes, but
|
| 198 |
+
inline styles. This is not recommended for larger pieces of code since
|
| 199 |
+
it increases output size by quite a bit (default: ``False``).
|
| 200 |
+
|
| 201 |
+
`classprefix`
|
| 202 |
+
Since the token types use relatively short class names, they may clash
|
| 203 |
+
with some of your own class names. In this case you can use the
|
| 204 |
+
`classprefix` option to give a string to prepend to all Pygments-generated
|
| 205 |
+
CSS class names for token types.
|
| 206 |
+
Note that this option also affects the output of `get_style_defs()`.
|
| 207 |
+
|
| 208 |
+
`cssclass`
|
| 209 |
+
CSS class for the wrapping ``<div>`` tag (default: ``'highlight'``).
|
| 210 |
+
If you set this option, the default selector for `get_style_defs()`
|
| 211 |
+
will be this class.
|
| 212 |
+
|
| 213 |
+
.. versionadded:: 0.9
|
| 214 |
+
If you select the ``'table'`` line numbers, the wrapping table will
|
| 215 |
+
have a CSS class of this string plus ``'table'``, the default is
|
| 216 |
+
accordingly ``'highlighttable'``.
|
| 217 |
+
|
| 218 |
+
`cssstyles`
|
| 219 |
+
Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
|
| 220 |
+
|
| 221 |
+
`prestyles`
|
| 222 |
+
Inline CSS styles for the ``<pre>`` tag (default: ``''``).
|
| 223 |
+
|
| 224 |
+
.. versionadded:: 0.11
|
| 225 |
+
|
| 226 |
+
`cssfile`
|
| 227 |
+
If the `full` option is true and this option is given, it must be the
|
| 228 |
+
name of an external file. If the filename does not include an absolute
|
| 229 |
+
path, the file's path will be assumed to be relative to the main output
|
| 230 |
+
file's path, if the latter can be found. The stylesheet is then written
|
| 231 |
+
to this file instead of the HTML file.
|
| 232 |
+
|
| 233 |
+
.. versionadded:: 0.6
|
| 234 |
+
|
| 235 |
+
`noclobber_cssfile`
|
| 236 |
+
If `cssfile` is given and the specified file exists, the css file will
|
| 237 |
+
not be overwritten. This allows the use of the `full` option in
|
| 238 |
+
combination with a user specified css file. Default is ``False``.
|
| 239 |
+
|
| 240 |
+
.. versionadded:: 1.1
|
| 241 |
+
|
| 242 |
+
`linenos`
|
| 243 |
+
If set to ``'table'``, output line numbers as a table with two cells,
|
| 244 |
+
one containing the line numbers, the other the whole code. This is
|
| 245 |
+
copy-and-paste-friendly, but may cause alignment problems with some
|
| 246 |
+
browsers or fonts. If set to ``'inline'``, the line numbers will be
|
| 247 |
+
integrated in the ``<pre>`` tag that contains the code (that setting
|
| 248 |
+
is *new in Pygments 0.8*).
|
| 249 |
+
|
| 250 |
+
For compatibility with Pygments 0.7 and earlier, every true value
|
| 251 |
+
except ``'inline'`` means the same as ``'table'`` (in particular, that
|
| 252 |
+
means also ``True``).
|
| 253 |
+
|
| 254 |
+
The default value is ``False``, which means no line numbers at all.
|
| 255 |
+
|
| 256 |
+
**Note:** with the default ("table") line number mechanism, the line
|
| 257 |
+
numbers and code can have different line heights in Internet Explorer
|
| 258 |
+
unless you give the enclosing ``<pre>`` tags an explicit ``line-height``
|
| 259 |
+
CSS property (you get the default line spacing with ``line-height:
|
| 260 |
+
125%``).
|
| 261 |
+
|
| 262 |
+
`hl_lines`
|
| 263 |
+
Specify a list of lines to be highlighted.
|
| 264 |
+
|
| 265 |
+
.. versionadded:: 0.11
|
| 266 |
+
|
| 267 |
+
`linenostart`
|
| 268 |
+
The line number for the first line (default: ``1``).
|
| 269 |
+
|
| 270 |
+
`linenostep`
|
| 271 |
+
If set to a number n > 1, only every nth line number is printed.
|
| 272 |
+
|
| 273 |
+
`linenospecial`
|
| 274 |
+
If set to a number n > 0, every nth line number is given the CSS
|
| 275 |
+
class ``"special"`` (default: ``0``).
|
| 276 |
+
|
| 277 |
+
`nobackground`
|
| 278 |
+
If set to ``True``, the formatter won't output the background color
|
| 279 |
+
for the wrapping element (this automatically defaults to ``False``
|
| 280 |
+
when there is no wrapping element [eg: no argument for the
|
| 281 |
+
`get_syntax_defs` method given]) (default: ``False``).
|
| 282 |
+
|
| 283 |
+
.. versionadded:: 0.6
|
| 284 |
+
|
| 285 |
+
`lineseparator`
|
| 286 |
+
This string is output between lines of code. It defaults to ``"\n"``,
|
| 287 |
+
which is enough to break a line inside ``<pre>`` tags, but you can
|
| 288 |
+
e.g. set it to ``"<br>"`` to get HTML line breaks.
|
| 289 |
+
|
| 290 |
+
.. versionadded:: 0.7
|
| 291 |
+
|
| 292 |
+
`lineanchors`
|
| 293 |
+
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
|
| 294 |
+
output line in an anchor tag with a ``name`` of ``foo-linenumber``.
|
| 295 |
+
This allows easy linking to certain lines.
|
| 296 |
+
|
| 297 |
+
.. versionadded:: 0.9
|
| 298 |
+
|
| 299 |
+
`linespans`
|
| 300 |
+
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
|
| 301 |
+
output line in a span tag with an ``id`` of ``foo-linenumber``.
|
| 302 |
+
This allows easy access to lines via javascript.
|
| 303 |
+
|
| 304 |
+
.. versionadded:: 1.6
|
| 305 |
+
|
| 306 |
+
`anchorlinenos`
|
| 307 |
+
If set to `True`, will wrap line numbers in <a> tags. Used in
|
| 308 |
+
combination with `linenos` and `lineanchors`.
|
| 309 |
+
|
| 310 |
+
`tagsfile`
|
| 311 |
+
If set to the path of a ctags file, wrap names in anchor tags that
|
| 312 |
+
link to their definitions. `lineanchors` should be used, and the
|
| 313 |
+
tags file should specify line numbers (see the `-n` option to ctags).
|
| 314 |
+
|
| 315 |
+
.. versionadded:: 1.6
|
| 316 |
+
|
| 317 |
+
`tagurlformat`
|
| 318 |
+
A string formatting pattern used to generate links to ctags definitions.
|
| 319 |
+
Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
|
| 320 |
+
Defaults to an empty string, resulting in just `#prefix-number` links.
|
| 321 |
+
|
| 322 |
+
.. versionadded:: 1.6
|
| 323 |
+
|
| 324 |
+
`filename`
|
| 325 |
+
A string used to generate a filename when rendering <pre> blocks,
|
| 326 |
+
for example if displaying source code.
|
| 327 |
+
|
| 328 |
+
.. versionadded:: 2.1
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
**Subclassing the HTML formatter**
|
| 332 |
+
|
| 333 |
+
.. versionadded:: 0.7
|
| 334 |
+
|
| 335 |
+
The HTML formatter is now built in a way that allows easy subclassing, thus
|
| 336 |
+
customizing the output HTML code. The `format()` method calls
|
| 337 |
+
`self._format_lines()` which returns a generator that yields tuples of ``(1,
|
| 338 |
+
line)``, where the ``1`` indicates that the ``line`` is a line of the
|
| 339 |
+
formatted source code.
|
| 340 |
+
|
| 341 |
+
If the `nowrap` option is set, the generator is the iterated over and the
|
| 342 |
+
resulting HTML is output.
|
| 343 |
+
|
| 344 |
+
Otherwise, `format()` calls `self.wrap()`, which wraps the generator with
|
| 345 |
+
other generators. These may add some HTML code to the one generated by
|
| 346 |
+
`_format_lines()`, either by modifying the lines generated by the latter,
|
| 347 |
+
then yielding them again with ``(1, line)``, and/or by yielding other HTML
|
| 348 |
+
code before or after the lines, with ``(0, html)``. The distinction between
|
| 349 |
+
source lines and other code makes it possible to wrap the generator multiple
|
| 350 |
+
times.
|
| 351 |
+
|
| 352 |
+
The default `wrap()` implementation adds a ``<div>`` and a ``<pre>`` tag.
|
| 353 |
+
|
| 354 |
+
A custom `HtmlFormatter` subclass could look like this:
|
| 355 |
+
|
| 356 |
+
.. sourcecode:: python
|
| 357 |
+
|
| 358 |
+
class CodeHtmlFormatter(HtmlFormatter):
|
| 359 |
+
|
| 360 |
+
def wrap(self, source, outfile):
|
| 361 |
+
return self._wrap_code(source)
|
| 362 |
+
|
| 363 |
+
def _wrap_code(self, source):
|
| 364 |
+
yield 0, '<code>'
|
| 365 |
+
for i, t in source:
|
| 366 |
+
if i == 1:
|
| 367 |
+
# it's a line of formatted code
|
| 368 |
+
t += '<br>'
|
| 369 |
+
yield i, t
|
| 370 |
+
yield 0, '</code>'
|
| 371 |
+
|
| 372 |
+
This results in wrapping the formatted lines with a ``<code>`` tag, where the
|
| 373 |
+
source lines are broken using ``<br>`` tags.
|
| 374 |
+
|
| 375 |
+
After calling `wrap()`, the `format()` method also adds the "line numbers"
|
| 376 |
+
and/or "full document" wrappers if the respective options are set. Then, all
|
| 377 |
+
HTML yielded by the wrapped generator is output.
|
| 378 |
+
"""
|
| 379 |
+
|
| 380 |
+
name = 'HTML'
|
| 381 |
+
aliases = ['html']
|
| 382 |
+
filenames = ['*.html', '*.htm']
|
| 383 |
+
|
| 384 |
+
def __init__(self, **options):
|
| 385 |
+
Formatter.__init__(self, **options)
|
| 386 |
+
self.title = self._decodeifneeded(self.title)
|
| 387 |
+
self.nowrap = get_bool_opt(options, 'nowrap', False)
|
| 388 |
+
self.noclasses = get_bool_opt(options, 'noclasses', False)
|
| 389 |
+
self.classprefix = options.get('classprefix', '')
|
| 390 |
+
self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
|
| 391 |
+
self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
|
| 392 |
+
self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
|
| 393 |
+
self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
|
| 394 |
+
self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
|
| 395 |
+
self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
|
| 396 |
+
self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
|
| 397 |
+
self.filename = self._decodeifneeded(options.get('filename', ''))
|
| 398 |
+
|
| 399 |
+
if self.tagsfile:
|
| 400 |
+
if not ctags:
|
| 401 |
+
raise RuntimeError('The "ctags" package must to be installed '
|
| 402 |
+
'to be able to use the "tagsfile" feature.')
|
| 403 |
+
self._ctags = ctags.CTags(self.tagsfile)
|
| 404 |
+
|
| 405 |
+
linenos = options.get('linenos', False)
|
| 406 |
+
if linenos == 'inline':
|
| 407 |
+
self.linenos = 2
|
| 408 |
+
elif linenos:
|
| 409 |
+
# compatibility with <= 0.7
|
| 410 |
+
self.linenos = 1
|
| 411 |
+
else:
|
| 412 |
+
self.linenos = 0
|
| 413 |
+
self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
|
| 414 |
+
self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
|
| 415 |
+
self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
|
| 416 |
+
self.nobackground = get_bool_opt(options, 'nobackground', False)
|
| 417 |
+
self.lineseparator = options.get('lineseparator', '\n')
|
| 418 |
+
self.lineanchors = options.get('lineanchors', '')
|
| 419 |
+
self.linespans = options.get('linespans', '')
|
| 420 |
+
self.anchorlinenos = options.get('anchorlinenos', False)
|
| 421 |
+
self.hl_lines = set()
|
| 422 |
+
for lineno in get_list_opt(options, 'hl_lines', []):
|
| 423 |
+
try:
|
| 424 |
+
self.hl_lines.add(int(lineno))
|
| 425 |
+
except ValueError:
|
| 426 |
+
pass
|
| 427 |
+
|
| 428 |
+
self._create_stylesheet()
|
| 429 |
+
|
| 430 |
+
def _get_css_class(self, ttype):
|
| 431 |
+
"""Return the css class of this token type prefixed with
|
| 432 |
+
the classprefix option."""
|
| 433 |
+
ttypeclass = _get_ttype_class(ttype)
|
| 434 |
+
if ttypeclass:
|
| 435 |
+
return self.classprefix + ttypeclass
|
| 436 |
+
return ''
|
| 437 |
+
|
| 438 |
+
def _get_css_classes(self, ttype):
|
| 439 |
+
"""Return the css classes of this token type prefixed with
|
| 440 |
+
the classprefix option."""
|
| 441 |
+
cls = self._get_css_class(ttype)
|
| 442 |
+
while ttype not in STANDARD_TYPES:
|
| 443 |
+
ttype = ttype.parent
|
| 444 |
+
cls = self._get_css_class(ttype) + ' ' + cls
|
| 445 |
+
return cls
|
| 446 |
+
|
| 447 |
+
def _create_stylesheet(self):
|
| 448 |
+
t2c = self.ttype2class = {Token: ''}
|
| 449 |
+
c2s = self.class2style = {}
|
| 450 |
+
for ttype, ndef in self.style:
|
| 451 |
+
name = self._get_css_class(ttype)
|
| 452 |
+
style = ''
|
| 453 |
+
if ndef['color']:
|
| 454 |
+
style += 'color: #%s; ' % ndef['color']
|
| 455 |
+
if ndef['bold']:
|
| 456 |
+
style += 'font-weight: bold; '
|
| 457 |
+
if ndef['italic']:
|
| 458 |
+
style += 'font-style: italic; '
|
| 459 |
+
if ndef['underline']:
|
| 460 |
+
style += 'text-decoration: underline; '
|
| 461 |
+
if ndef['bgcolor']:
|
| 462 |
+
style += 'background-color: #%s; ' % ndef['bgcolor']
|
| 463 |
+
if ndef['border']:
|
| 464 |
+
style += 'border: 1px solid #%s; ' % ndef['border']
|
| 465 |
+
if style:
|
| 466 |
+
t2c[ttype] = name
|
| 467 |
+
# save len(ttype) to enable ordering the styles by
|
| 468 |
+
# hierarchy (necessary for CSS cascading rules!)
|
| 469 |
+
c2s[name] = (style[:-2], ttype, len(ttype))
|
| 470 |
+
|
| 471 |
+
def get_style_defs(self, arg=None):
|
| 472 |
+
"""
|
| 473 |
+
Return CSS style definitions for the classes produced by the current
|
| 474 |
+
highlighting style. ``arg`` can be a string or list of selectors to
|
| 475 |
+
insert before the token type classes.
|
| 476 |
+
"""
|
| 477 |
+
if arg is None:
|
| 478 |
+
arg = ('cssclass' in self.options and '.'+self.cssclass or '')
|
| 479 |
+
if isinstance(arg, string_types):
|
| 480 |
+
args = [arg]
|
| 481 |
+
else:
|
| 482 |
+
args = list(arg)
|
| 483 |
+
|
| 484 |
+
def prefix(cls):
|
| 485 |
+
if cls:
|
| 486 |
+
cls = '.' + cls
|
| 487 |
+
tmp = []
|
| 488 |
+
for arg in args:
|
| 489 |
+
tmp.append((arg and arg + ' ' or '') + cls)
|
| 490 |
+
return ', '.join(tmp)
|
| 491 |
+
|
| 492 |
+
styles = [(level, ttype, cls, style)
|
| 493 |
+
for cls, (style, ttype, level) in iteritems(self.class2style)
|
| 494 |
+
if cls and style]
|
| 495 |
+
styles.sort()
|
| 496 |
+
lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
|
| 497 |
+
for (level, ttype, cls, style) in styles]
|
| 498 |
+
if arg and not self.nobackground and \
|
| 499 |
+
self.style.background_color is not None:
|
| 500 |
+
text_style = ''
|
| 501 |
+
if Text in self.ttype2class:
|
| 502 |
+
text_style = ' ' + self.class2style[self.ttype2class[Text]][0]
|
| 503 |
+
lines.insert(0, '%s { background: %s;%s }' %
|
| 504 |
+
(prefix(''), self.style.background_color, text_style))
|
| 505 |
+
if self.style.highlight_color is not None:
|
| 506 |
+
lines.insert(0, '%s.hll { background-color: %s }' %
|
| 507 |
+
(prefix(''), self.style.highlight_color))
|
| 508 |
+
return '\n'.join(lines)
|
| 509 |
+
|
| 510 |
+
def _decodeifneeded(self, value):
|
| 511 |
+
if isinstance(value, bytes):
|
| 512 |
+
if self.encoding:
|
| 513 |
+
return value.decode(self.encoding)
|
| 514 |
+
return value.decode()
|
| 515 |
+
return value
|
| 516 |
+
|
| 517 |
+
def _wrap_full(self, inner, outfile):
|
| 518 |
+
if self.cssfile:
|
| 519 |
+
if os.path.isabs(self.cssfile):
|
| 520 |
+
# it's an absolute filename
|
| 521 |
+
cssfilename = self.cssfile
|
| 522 |
+
else:
|
| 523 |
+
try:
|
| 524 |
+
filename = outfile.name
|
| 525 |
+
if not filename or filename[0] == '<':
|
| 526 |
+
# pseudo files, e.g. name == '<fdopen>'
|
| 527 |
+
raise AttributeError
|
| 528 |
+
cssfilename = os.path.join(os.path.dirname(filename),
|
| 529 |
+
self.cssfile)
|
| 530 |
+
except AttributeError:
|
| 531 |
+
print('Note: Cannot determine output file name, '
|
| 532 |
+
'using current directory as base for the CSS file name',
|
| 533 |
+
file=sys.stderr)
|
| 534 |
+
cssfilename = self.cssfile
|
| 535 |
+
# write CSS file only if noclobber_cssfile isn't given as an option.
|
| 536 |
+
try:
|
| 537 |
+
if not os.path.exists(cssfilename) or not self.noclobber_cssfile:
|
| 538 |
+
cf = open(cssfilename, "w")
|
| 539 |
+
cf.write(CSSFILE_TEMPLATE %
|
| 540 |
+
{'styledefs': self.get_style_defs('body')})
|
| 541 |
+
cf.close()
|
| 542 |
+
except IOError as err:
|
| 543 |
+
err.strerror = 'Error writing CSS file: ' + err.strerror
|
| 544 |
+
raise
|
| 545 |
+
|
| 546 |
+
yield 0, (DOC_HEADER_EXTERNALCSS %
|
| 547 |
+
dict(title=self.title,
|
| 548 |
+
cssfile=self.cssfile,
|
| 549 |
+
encoding=self.encoding))
|
| 550 |
+
else:
|
| 551 |
+
yield 0, (DOC_HEADER %
|
| 552 |
+
dict(title=self.title,
|
| 553 |
+
styledefs=self.get_style_defs('body'),
|
| 554 |
+
encoding=self.encoding))
|
| 555 |
+
|
| 556 |
+
for t, line in inner:
|
| 557 |
+
yield t, line
|
| 558 |
+
yield 0, DOC_FOOTER
|
| 559 |
+
|
| 560 |
+
def _wrap_tablelinenos(self, inner):
|
| 561 |
+
dummyoutfile = StringIO()
|
| 562 |
+
lncount = 0
|
| 563 |
+
for t, line in inner:
|
| 564 |
+
if t:
|
| 565 |
+
lncount += 1
|
| 566 |
+
dummyoutfile.write(line)
|
| 567 |
+
|
| 568 |
+
fl = self.linenostart
|
| 569 |
+
mw = len(str(lncount + fl - 1))
|
| 570 |
+
sp = self.linenospecial
|
| 571 |
+
st = self.linenostep
|
| 572 |
+
la = self.lineanchors
|
| 573 |
+
aln = self.anchorlinenos
|
| 574 |
+
nocls = self.noclasses
|
| 575 |
+
if sp:
|
| 576 |
+
lines = []
|
| 577 |
+
|
| 578 |
+
for i in range(fl, fl+lncount):
|
| 579 |
+
if i % st == 0:
|
| 580 |
+
if i % sp == 0:
|
| 581 |
+
if aln:
|
| 582 |
+
lines.append('<a href="#%s-%d" class="special">%*d</a>' %
|
| 583 |
+
(la, i, mw, i))
|
| 584 |
+
else:
|
| 585 |
+
lines.append('<span class="special">%*d</span>' % (mw, i))
|
| 586 |
+
else:
|
| 587 |
+
if aln:
|
| 588 |
+
lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
|
| 589 |
+
else:
|
| 590 |
+
lines.append('%*d' % (mw, i))
|
| 591 |
+
else:
|
| 592 |
+
lines.append('')
|
| 593 |
+
ls = '\n'.join(lines)
|
| 594 |
+
else:
|
| 595 |
+
lines = []
|
| 596 |
+
for i in range(fl, fl+lncount):
|
| 597 |
+
if i % st == 0:
|
| 598 |
+
if aln:
|
| 599 |
+
lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
|
| 600 |
+
else:
|
| 601 |
+
lines.append('%*d' % (mw, i))
|
| 602 |
+
else:
|
| 603 |
+
lines.append('')
|
| 604 |
+
ls = '\n'.join(lines)
|
| 605 |
+
|
| 606 |
+
# in case you wonder about the seemingly redundant <div> here: since the
|
| 607 |
+
# content in the other cell also is wrapped in a div, some browsers in
|
| 608 |
+
# some configurations seem to mess up the formatting...
|
| 609 |
+
if nocls:
|
| 610 |
+
yield 0, ('<table class="%stable">' % self.cssclass +
|
| 611 |
+
'<tr><td><div class="linenodiv" '
|
| 612 |
+
'style="background-color: #f0f0f0; padding-right: 10px">'
|
| 613 |
+
'<pre style="line-height: 125%">' +
|
| 614 |
+
ls + '</pre></div></td><td class="code">')
|
| 615 |
+
else:
|
| 616 |
+
yield 0, ('<table class="%stable">' % self.cssclass +
|
| 617 |
+
'<tr><td class="linenos"><div class="linenodiv"><pre>' +
|
| 618 |
+
ls + '</pre></div></td><td class="code">')
|
| 619 |
+
yield 0, dummyoutfile.getvalue()
|
| 620 |
+
yield 0, '</td></tr></table>'
|
| 621 |
+
|
| 622 |
+
def _wrap_inlinelinenos(self, inner):
|
| 623 |
+
# need a list of lines since we need the width of a single number :(
|
| 624 |
+
lines = list(inner)
|
| 625 |
+
sp = self.linenospecial
|
| 626 |
+
st = self.linenostep
|
| 627 |
+
num = self.linenostart
|
| 628 |
+
mw = len(str(len(lines) + num - 1))
|
| 629 |
+
|
| 630 |
+
if self.noclasses:
|
| 631 |
+
if sp:
|
| 632 |
+
for t, line in lines:
|
| 633 |
+
if num % sp == 0:
|
| 634 |
+
style = 'background-color: #ffffc0; padding: 0 5px 0 5px'
|
| 635 |
+
else:
|
| 636 |
+
style = 'background-color: #f0f0f0; padding: 0 5px 0 5px'
|
| 637 |
+
yield 1, '<span style="%s">%*s </span>' % (
|
| 638 |
+
style, mw, (num % st and ' ' or num)) + line
|
| 639 |
+
num += 1
|
| 640 |
+
else:
|
| 641 |
+
for t, line in lines:
|
| 642 |
+
yield 1, ('<span style="background-color: #f0f0f0; '
|
| 643 |
+
'padding: 0 5px 0 5px">%*s </span>' % (
|
| 644 |
+
mw, (num % st and ' ' or num)) + line)
|
| 645 |
+
num += 1
|
| 646 |
+
elif sp:
|
| 647 |
+
for t, line in lines:
|
| 648 |
+
yield 1, '<span class="lineno%s">%*s </span>' % (
|
| 649 |
+
num % sp == 0 and ' special' or '', mw,
|
| 650 |
+
(num % st and ' ' or num)) + line
|
| 651 |
+
num += 1
|
| 652 |
+
else:
|
| 653 |
+
for t, line in lines:
|
| 654 |
+
yield 1, '<span class="lineno">%*s </span>' % (
|
| 655 |
+
mw, (num % st and ' ' or num)) + line
|
| 656 |
+
num += 1
|
| 657 |
+
|
| 658 |
+
def _wrap_lineanchors(self, inner):
|
| 659 |
+
s = self.lineanchors
|
| 660 |
+
# subtract 1 since we have to increment i *before* yielding
|
| 661 |
+
i = self.linenostart - 1
|
| 662 |
+
for t, line in inner:
|
| 663 |
+
if t:
|
| 664 |
+
i += 1
|
| 665 |
+
yield 1, '<a name="%s-%d"></a>' % (s, i) + line
|
| 666 |
+
else:
|
| 667 |
+
yield 0, line
|
| 668 |
+
|
| 669 |
+
def _wrap_linespans(self, inner):
|
| 670 |
+
s = self.linespans
|
| 671 |
+
i = self.linenostart - 1
|
| 672 |
+
for t, line in inner:
|
| 673 |
+
if t:
|
| 674 |
+
i += 1
|
| 675 |
+
yield 1, '<span id="%s-%d">%s</span>' % (s, i, line)
|
| 676 |
+
else:
|
| 677 |
+
yield 0, line
|
| 678 |
+
|
| 679 |
+
def _wrap_div(self, inner):
|
| 680 |
+
style = []
|
| 681 |
+
if (self.noclasses and not self.nobackground and
|
| 682 |
+
self.style.background_color is not None):
|
| 683 |
+
style.append('background: %s' % (self.style.background_color,))
|
| 684 |
+
if self.cssstyles:
|
| 685 |
+
style.append(self.cssstyles)
|
| 686 |
+
style = '; '.join(style)
|
| 687 |
+
|
| 688 |
+
yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) +
|
| 689 |
+
(style and (' style="%s"' % style)) + '>')
|
| 690 |
+
for tup in inner:
|
| 691 |
+
yield tup
|
| 692 |
+
yield 0, '</div>\n'
|
| 693 |
+
|
| 694 |
+
def _wrap_pre(self, inner):
|
| 695 |
+
style = []
|
| 696 |
+
if self.prestyles:
|
| 697 |
+
style.append(self.prestyles)
|
| 698 |
+
if self.noclasses:
|
| 699 |
+
style.append('line-height: 125%')
|
| 700 |
+
style = '; '.join(style)
|
| 701 |
+
|
| 702 |
+
if self.filename:
|
| 703 |
+
yield 0, ('<span class="filename">' + self.filename + '</span>')
|
| 704 |
+
|
| 705 |
+
# the empty span here is to keep leading empty lines from being
|
| 706 |
+
# ignored by HTML parsers
|
| 707 |
+
yield 0, ('<pre' + (style and ' style="%s"' % style) + '><span></span>')
|
| 708 |
+
for tup in inner:
|
| 709 |
+
yield tup
|
| 710 |
+
yield 0, '</pre>'
|
| 711 |
+
|
| 712 |
+
def _format_lines(self, tokensource):
|
| 713 |
+
"""
|
| 714 |
+
Just format the tokens, without any wrapping tags.
|
| 715 |
+
Yield individual lines.
|
| 716 |
+
"""
|
| 717 |
+
nocls = self.noclasses
|
| 718 |
+
lsep = self.lineseparator
|
| 719 |
+
# for <span style=""> lookup only
|
| 720 |
+
getcls = self.ttype2class.get
|
| 721 |
+
c2s = self.class2style
|
| 722 |
+
escape_table = _escape_html_table
|
| 723 |
+
tagsfile = self.tagsfile
|
| 724 |
+
|
| 725 |
+
lspan = ''
|
| 726 |
+
line = []
|
| 727 |
+
for ttype, value in tokensource:
|
| 728 |
+
if nocls:
|
| 729 |
+
cclass = getcls(ttype)
|
| 730 |
+
while cclass is None:
|
| 731 |
+
ttype = ttype.parent
|
| 732 |
+
cclass = getcls(ttype)
|
| 733 |
+
cspan = cclass and '<span style="%s">' % c2s[cclass][0] or ''
|
| 734 |
+
else:
|
| 735 |
+
cls = self._get_css_classes(ttype)
|
| 736 |
+
cspan = cls and '<span class="%s">' % cls or ''
|
| 737 |
+
|
| 738 |
+
parts = value.translate(escape_table).split('\n')
|
| 739 |
+
|
| 740 |
+
if tagsfile and ttype in Token.Name:
|
| 741 |
+
filename, linenumber = self._lookup_ctag(value)
|
| 742 |
+
if linenumber:
|
| 743 |
+
base, filename = os.path.split(filename)
|
| 744 |
+
if base:
|
| 745 |
+
base += '/'
|
| 746 |
+
filename, extension = os.path.splitext(filename)
|
| 747 |
+
url = self.tagurlformat % {'path': base, 'fname': filename,
|
| 748 |
+
'fext': extension}
|
| 749 |
+
parts[0] = "<a href=\"%s#%s-%d\">%s" % \
|
| 750 |
+
(url, self.lineanchors, linenumber, parts[0])
|
| 751 |
+
parts[-1] = parts[-1] + "</a>"
|
| 752 |
+
|
| 753 |
+
# for all but the last line
|
| 754 |
+
for part in parts[:-1]:
|
| 755 |
+
if line:
|
| 756 |
+
if lspan != cspan:
|
| 757 |
+
line.extend(((lspan and '</span>'), cspan, part,
|
| 758 |
+
(cspan and '</span>'), lsep))
|
| 759 |
+
else: # both are the same
|
| 760 |
+
line.extend((part, (lspan and '</span>'), lsep))
|
| 761 |
+
yield 1, ''.join(line)
|
| 762 |
+
line = []
|
| 763 |
+
elif part:
|
| 764 |
+
yield 1, ''.join((cspan, part, (cspan and '</span>'), lsep))
|
| 765 |
+
else:
|
| 766 |
+
yield 1, lsep
|
| 767 |
+
# for the last line
|
| 768 |
+
if line and parts[-1]:
|
| 769 |
+
if lspan != cspan:
|
| 770 |
+
line.extend(((lspan and '</span>'), cspan, parts[-1]))
|
| 771 |
+
lspan = cspan
|
| 772 |
+
else:
|
| 773 |
+
line.append(parts[-1])
|
| 774 |
+
elif parts[-1]:
|
| 775 |
+
line = [cspan, parts[-1]]
|
| 776 |
+
lspan = cspan
|
| 777 |
+
# else we neither have to open a new span nor set lspan
|
| 778 |
+
|
| 779 |
+
if line:
|
| 780 |
+
line.extend(((lspan and '</span>'), lsep))
|
| 781 |
+
yield 1, ''.join(line)
|
| 782 |
+
|
| 783 |
+
def _lookup_ctag(self, token):
|
| 784 |
+
entry = ctags.TagEntry()
|
| 785 |
+
if self._ctags.find(entry, token, 0):
|
| 786 |
+
return entry['file'], entry['lineNumber']
|
| 787 |
+
else:
|
| 788 |
+
return None, None
|
| 789 |
+
|
| 790 |
+
def _highlight_lines(self, tokensource):
|
| 791 |
+
"""
|
| 792 |
+
Highlighted the lines specified in the `hl_lines` option by
|
| 793 |
+
post-processing the token stream coming from `_format_lines`.
|
| 794 |
+
"""
|
| 795 |
+
hls = self.hl_lines
|
| 796 |
+
|
| 797 |
+
for i, (t, value) in enumerate(tokensource):
|
| 798 |
+
if t != 1:
|
| 799 |
+
yield t, value
|
| 800 |
+
if i + 1 in hls: # i + 1 because Python indexes start at 0
|
| 801 |
+
if self.noclasses:
|
| 802 |
+
style = ''
|
| 803 |
+
if self.style.highlight_color is not None:
|
| 804 |
+
style = (' style="background-color: %s"' %
|
| 805 |
+
(self.style.highlight_color,))
|
| 806 |
+
yield 1, '<span%s>%s</span>' % (style, value)
|
| 807 |
+
else:
|
| 808 |
+
yield 1, '<span class="hll">%s</span>' % value
|
| 809 |
+
else:
|
| 810 |
+
yield 1, value
|
| 811 |
+
|
| 812 |
+
def wrap(self, source, outfile):
|
| 813 |
+
"""
|
| 814 |
+
Wrap the ``source``, which is a generator yielding
|
| 815 |
+
individual lines, in custom generators. See docstring
|
| 816 |
+
for `format`. Can be overridden.
|
| 817 |
+
"""
|
| 818 |
+
return self._wrap_div(self._wrap_pre(source))
|
| 819 |
+
|
| 820 |
+
def format_unencoded(self, tokensource, outfile):
|
| 821 |
+
"""
|
| 822 |
+
The formatting process uses several nested generators; which of
|
| 823 |
+
them are used is determined by the user's options.
|
| 824 |
+
|
| 825 |
+
Each generator should take at least one argument, ``inner``,
|
| 826 |
+
and wrap the pieces of text generated by this.
|
| 827 |
+
|
| 828 |
+
Always yield 2-tuples: (code, text). If "code" is 1, the text
|
| 829 |
+
is part of the original tokensource being highlighted, if it's
|
| 830 |
+
0, the text is some piece of wrapping. This makes it possible to
|
| 831 |
+
use several different wrappers that process the original source
|
| 832 |
+
linewise, e.g. line number generators.
|
| 833 |
+
"""
|
| 834 |
+
source = self._format_lines(tokensource)
|
| 835 |
+
if self.hl_lines:
|
| 836 |
+
source = self._highlight_lines(source)
|
| 837 |
+
if not self.nowrap:
|
| 838 |
+
if self.linenos == 2:
|
| 839 |
+
source = self._wrap_inlinelinenos(source)
|
| 840 |
+
if self.lineanchors:
|
| 841 |
+
source = self._wrap_lineanchors(source)
|
| 842 |
+
if self.linespans:
|
| 843 |
+
source = self._wrap_linespans(source)
|
| 844 |
+
source = self.wrap(source, outfile)
|
| 845 |
+
if self.linenos == 1:
|
| 846 |
+
source = self._wrap_tablelinenos(source)
|
| 847 |
+
if self.full:
|
| 848 |
+
source = self._wrap_full(source, outfile)
|
| 849 |
+
|
| 850 |
+
for t, piece in source:
|
| 851 |
+
outfile.write(piece)
|
vllm/lib/python3.10/site-packages/wandb/vendor/pygments/formatters/img.py
ADDED
|
@@ -0,0 +1,600 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.formatters.img
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Formatter for Pixmap output.
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
from pygments.formatter import Formatter
|
| 16 |
+
from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
|
| 17 |
+
get_choice_opt, xrange
|
| 18 |
+
|
| 19 |
+
import subprocess
|
| 20 |
+
|
| 21 |
+
# Import this carefully
|
| 22 |
+
try:
|
| 23 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 24 |
+
pil_available = True
|
| 25 |
+
except ImportError:
|
| 26 |
+
pil_available = False
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
import _winreg
|
| 30 |
+
except ImportError:
|
| 31 |
+
try:
|
| 32 |
+
import winreg as _winreg
|
| 33 |
+
except ImportError:
|
| 34 |
+
_winreg = None
|
| 35 |
+
|
| 36 |
+
__all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
|
| 37 |
+
'BmpImageFormatter']
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# For some unknown reason every font calls it something different
|
| 41 |
+
STYLES = {
|
| 42 |
+
'NORMAL': ['', 'Roman', 'Book', 'Normal', 'Regular', 'Medium'],
|
| 43 |
+
'ITALIC': ['Oblique', 'Italic'],
|
| 44 |
+
'BOLD': ['Bold'],
|
| 45 |
+
'BOLDITALIC': ['Bold Oblique', 'Bold Italic'],
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# A sane default for modern systems
|
| 49 |
+
DEFAULT_FONT_NAME_NIX = 'Bitstream Vera Sans Mono'
|
| 50 |
+
DEFAULT_FONT_NAME_WIN = 'Courier New'
|
| 51 |
+
DEFAULT_FONT_NAME_MAC = 'Courier New'
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class PilNotAvailable(ImportError):
|
| 55 |
+
"""When Python imaging library is not available"""
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class FontNotFound(Exception):
|
| 59 |
+
"""When there are no usable fonts specified"""
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class FontManager(object):
|
| 63 |
+
"""
|
| 64 |
+
Manages a set of fonts: normal, italic, bold, etc...
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
def __init__(self, font_name, font_size=14):
|
| 68 |
+
self.font_name = font_name
|
| 69 |
+
self.font_size = font_size
|
| 70 |
+
self.fonts = {}
|
| 71 |
+
self.encoding = None
|
| 72 |
+
if sys.platform.startswith('win'):
|
| 73 |
+
if not font_name:
|
| 74 |
+
self.font_name = DEFAULT_FONT_NAME_WIN
|
| 75 |
+
self._create_win()
|
| 76 |
+
elif sys.platform.startswith('darwin'):
|
| 77 |
+
if not font_name:
|
| 78 |
+
self.font_name = DEFAULT_FONT_NAME_MAC
|
| 79 |
+
self._create_mac()
|
| 80 |
+
else:
|
| 81 |
+
if not font_name:
|
| 82 |
+
self.font_name = DEFAULT_FONT_NAME_NIX
|
| 83 |
+
self._create_nix()
|
| 84 |
+
|
| 85 |
+
def _get_nix_font_path(self, name, style):
|
| 86 |
+
proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'],
|
| 87 |
+
stdout=subprocess.PIPE, stderr=None)
|
| 88 |
+
stdout, _ = proc.communicate()
|
| 89 |
+
if proc.returncode == 0:
|
| 90 |
+
lines = stdout.splitlines()
|
| 91 |
+
for line in lines:
|
| 92 |
+
if line.startswith(b'Fontconfig warning:'):
|
| 93 |
+
continue
|
| 94 |
+
path = line.decode().strip().strip(':')
|
| 95 |
+
if path:
|
| 96 |
+
return path
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
def _create_nix(self):
|
| 100 |
+
for name in STYLES['NORMAL']:
|
| 101 |
+
path = self._get_nix_font_path(self.font_name, name)
|
| 102 |
+
if path is not None:
|
| 103 |
+
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
| 104 |
+
break
|
| 105 |
+
else:
|
| 106 |
+
raise FontNotFound('No usable fonts named: "%s"' %
|
| 107 |
+
self.font_name)
|
| 108 |
+
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
| 109 |
+
for stylename in STYLES[style]:
|
| 110 |
+
path = self._get_nix_font_path(self.font_name, stylename)
|
| 111 |
+
if path is not None:
|
| 112 |
+
self.fonts[style] = ImageFont.truetype(path, self.font_size)
|
| 113 |
+
break
|
| 114 |
+
else:
|
| 115 |
+
if style == 'BOLDITALIC':
|
| 116 |
+
self.fonts[style] = self.fonts['BOLD']
|
| 117 |
+
else:
|
| 118 |
+
self.fonts[style] = self.fonts['NORMAL']
|
| 119 |
+
|
| 120 |
+
def _get_mac_font_path(self, font_map, name, style):
|
| 121 |
+
return font_map.get((name + ' ' + style).strip().lower())
|
| 122 |
+
|
| 123 |
+
def _create_mac(self):
|
| 124 |
+
font_map = {}
|
| 125 |
+
for font_dir in (os.path.join(os.getenv("HOME"), 'Library/Fonts/'),
|
| 126 |
+
'/Library/Fonts/', '/System/Library/Fonts/'):
|
| 127 |
+
font_map.update(
|
| 128 |
+
((os.path.splitext(f)[0].lower(), os.path.join(font_dir, f))
|
| 129 |
+
for f in os.listdir(font_dir) if f.lower().endswith('ttf')))
|
| 130 |
+
|
| 131 |
+
for name in STYLES['NORMAL']:
|
| 132 |
+
path = self._get_mac_font_path(font_map, self.font_name, name)
|
| 133 |
+
if path is not None:
|
| 134 |
+
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
| 135 |
+
break
|
| 136 |
+
else:
|
| 137 |
+
raise FontNotFound('No usable fonts named: "%s"' %
|
| 138 |
+
self.font_name)
|
| 139 |
+
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
| 140 |
+
for stylename in STYLES[style]:
|
| 141 |
+
path = self._get_mac_font_path(font_map, self.font_name, stylename)
|
| 142 |
+
if path is not None:
|
| 143 |
+
self.fonts[style] = ImageFont.truetype(path, self.font_size)
|
| 144 |
+
break
|
| 145 |
+
else:
|
| 146 |
+
if style == 'BOLDITALIC':
|
| 147 |
+
self.fonts[style] = self.fonts['BOLD']
|
| 148 |
+
else:
|
| 149 |
+
self.fonts[style] = self.fonts['NORMAL']
|
| 150 |
+
|
| 151 |
+
def _lookup_win(self, key, basename, styles, fail=False):
|
| 152 |
+
for suffix in ('', ' (TrueType)'):
|
| 153 |
+
for style in styles:
|
| 154 |
+
try:
|
| 155 |
+
valname = '%s%s%s' % (basename, style and ' '+style, suffix)
|
| 156 |
+
val, _ = _winreg.QueryValueEx(key, valname)
|
| 157 |
+
return val
|
| 158 |
+
except EnvironmentError:
|
| 159 |
+
continue
|
| 160 |
+
else:
|
| 161 |
+
if fail:
|
| 162 |
+
raise FontNotFound('Font %s (%s) not found in registry' %
|
| 163 |
+
(basename, styles[0]))
|
| 164 |
+
return None
|
| 165 |
+
|
| 166 |
+
def _create_win(self):
|
| 167 |
+
try:
|
| 168 |
+
key = _winreg.OpenKey(
|
| 169 |
+
_winreg.HKEY_LOCAL_MACHINE,
|
| 170 |
+
r'Software\Microsoft\Windows NT\CurrentVersion\Fonts')
|
| 171 |
+
except EnvironmentError:
|
| 172 |
+
try:
|
| 173 |
+
key = _winreg.OpenKey(
|
| 174 |
+
_winreg.HKEY_LOCAL_MACHINE,
|
| 175 |
+
r'Software\Microsoft\Windows\CurrentVersion\Fonts')
|
| 176 |
+
except EnvironmentError:
|
| 177 |
+
raise FontNotFound('Can\'t open Windows font registry key')
|
| 178 |
+
try:
|
| 179 |
+
path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
|
| 180 |
+
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
| 181 |
+
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
| 182 |
+
path = self._lookup_win(key, self.font_name, STYLES[style])
|
| 183 |
+
if path:
|
| 184 |
+
self.fonts[style] = ImageFont.truetype(path, self.font_size)
|
| 185 |
+
else:
|
| 186 |
+
if style == 'BOLDITALIC':
|
| 187 |
+
self.fonts[style] = self.fonts['BOLD']
|
| 188 |
+
else:
|
| 189 |
+
self.fonts[style] = self.fonts['NORMAL']
|
| 190 |
+
finally:
|
| 191 |
+
_winreg.CloseKey(key)
|
| 192 |
+
|
| 193 |
+
def get_char_size(self):
|
| 194 |
+
"""
|
| 195 |
+
Get the character size.
|
| 196 |
+
"""
|
| 197 |
+
return self.fonts['NORMAL'].getsize('M')
|
| 198 |
+
|
| 199 |
+
def get_font(self, bold, oblique):
|
| 200 |
+
"""
|
| 201 |
+
Get the font based on bold and italic flags.
|
| 202 |
+
"""
|
| 203 |
+
if bold and oblique:
|
| 204 |
+
return self.fonts['BOLDITALIC']
|
| 205 |
+
elif bold:
|
| 206 |
+
return self.fonts['BOLD']
|
| 207 |
+
elif oblique:
|
| 208 |
+
return self.fonts['ITALIC']
|
| 209 |
+
else:
|
| 210 |
+
return self.fonts['NORMAL']
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
class ImageFormatter(Formatter):
|
| 214 |
+
"""
|
| 215 |
+
Create a PNG image from source code. This uses the Python Imaging Library to
|
| 216 |
+
generate a pixmap from the source code.
|
| 217 |
+
|
| 218 |
+
.. versionadded:: 0.10
|
| 219 |
+
|
| 220 |
+
Additional options accepted:
|
| 221 |
+
|
| 222 |
+
`image_format`
|
| 223 |
+
An image format to output to that is recognised by PIL, these include:
|
| 224 |
+
|
| 225 |
+
* "PNG" (default)
|
| 226 |
+
* "JPEG"
|
| 227 |
+
* "BMP"
|
| 228 |
+
* "GIF"
|
| 229 |
+
|
| 230 |
+
`line_pad`
|
| 231 |
+
The extra spacing (in pixels) between each line of text.
|
| 232 |
+
|
| 233 |
+
Default: 2
|
| 234 |
+
|
| 235 |
+
`font_name`
|
| 236 |
+
The font name to be used as the base font from which others, such as
|
| 237 |
+
bold and italic fonts will be generated. This really should be a
|
| 238 |
+
monospace font to look sane.
|
| 239 |
+
|
| 240 |
+
Default: "Bitstream Vera Sans Mono" on Windows, Courier New on \*nix
|
| 241 |
+
|
| 242 |
+
`font_size`
|
| 243 |
+
The font size in points to be used.
|
| 244 |
+
|
| 245 |
+
Default: 14
|
| 246 |
+
|
| 247 |
+
`image_pad`
|
| 248 |
+
The padding, in pixels to be used at each edge of the resulting image.
|
| 249 |
+
|
| 250 |
+
Default: 10
|
| 251 |
+
|
| 252 |
+
`line_numbers`
|
| 253 |
+
Whether line numbers should be shown: True/False
|
| 254 |
+
|
| 255 |
+
Default: True
|
| 256 |
+
|
| 257 |
+
`line_number_start`
|
| 258 |
+
The line number of the first line.
|
| 259 |
+
|
| 260 |
+
Default: 1
|
| 261 |
+
|
| 262 |
+
`line_number_step`
|
| 263 |
+
The step used when printing line numbers.
|
| 264 |
+
|
| 265 |
+
Default: 1
|
| 266 |
+
|
| 267 |
+
`line_number_bg`
|
| 268 |
+
The background colour (in "#123456" format) of the line number bar, or
|
| 269 |
+
None to use the style background color.
|
| 270 |
+
|
| 271 |
+
Default: "#eed"
|
| 272 |
+
|
| 273 |
+
`line_number_fg`
|
| 274 |
+
The text color of the line numbers (in "#123456"-like format).
|
| 275 |
+
|
| 276 |
+
Default: "#886"
|
| 277 |
+
|
| 278 |
+
`line_number_chars`
|
| 279 |
+
The number of columns of line numbers allowable in the line number
|
| 280 |
+
margin.
|
| 281 |
+
|
| 282 |
+
Default: 2
|
| 283 |
+
|
| 284 |
+
`line_number_bold`
|
| 285 |
+
Whether line numbers will be bold: True/False
|
| 286 |
+
|
| 287 |
+
Default: False
|
| 288 |
+
|
| 289 |
+
`line_number_italic`
|
| 290 |
+
Whether line numbers will be italicized: True/False
|
| 291 |
+
|
| 292 |
+
Default: False
|
| 293 |
+
|
| 294 |
+
`line_number_separator`
|
| 295 |
+
Whether a line will be drawn between the line number area and the
|
| 296 |
+
source code area: True/False
|
| 297 |
+
|
| 298 |
+
Default: True
|
| 299 |
+
|
| 300 |
+
`line_number_pad`
|
| 301 |
+
The horizontal padding (in pixels) between the line number margin, and
|
| 302 |
+
the source code area.
|
| 303 |
+
|
| 304 |
+
Default: 6
|
| 305 |
+
|
| 306 |
+
`hl_lines`
|
| 307 |
+
Specify a list of lines to be highlighted.
|
| 308 |
+
|
| 309 |
+
.. versionadded:: 1.2
|
| 310 |
+
|
| 311 |
+
Default: empty list
|
| 312 |
+
|
| 313 |
+
`hl_color`
|
| 314 |
+
Specify the color for highlighting lines.
|
| 315 |
+
|
| 316 |
+
.. versionadded:: 1.2
|
| 317 |
+
|
| 318 |
+
Default: highlight color of the selected style
|
| 319 |
+
"""
|
| 320 |
+
|
| 321 |
+
# Required by the pygments mapper
|
| 322 |
+
name = 'img'
|
| 323 |
+
aliases = ['img', 'IMG', 'png']
|
| 324 |
+
filenames = ['*.png']
|
| 325 |
+
|
| 326 |
+
unicodeoutput = False
|
| 327 |
+
|
| 328 |
+
default_image_format = 'png'
|
| 329 |
+
|
| 330 |
+
def __init__(self, **options):
|
| 331 |
+
"""
|
| 332 |
+
See the class docstring for explanation of options.
|
| 333 |
+
"""
|
| 334 |
+
if not pil_available:
|
| 335 |
+
raise PilNotAvailable(
|
| 336 |
+
'Python Imaging Library is required for this formatter')
|
| 337 |
+
Formatter.__init__(self, **options)
|
| 338 |
+
self.encoding = 'latin1' # let pygments.format() do the right thing
|
| 339 |
+
# Read the style
|
| 340 |
+
self.styles = dict(self.style)
|
| 341 |
+
if self.style.background_color is None:
|
| 342 |
+
self.background_color = '#fff'
|
| 343 |
+
else:
|
| 344 |
+
self.background_color = self.style.background_color
|
| 345 |
+
# Image options
|
| 346 |
+
self.image_format = get_choice_opt(
|
| 347 |
+
options, 'image_format', ['png', 'jpeg', 'gif', 'bmp'],
|
| 348 |
+
self.default_image_format, normcase=True)
|
| 349 |
+
self.image_pad = get_int_opt(options, 'image_pad', 10)
|
| 350 |
+
self.line_pad = get_int_opt(options, 'line_pad', 2)
|
| 351 |
+
# The fonts
|
| 352 |
+
fontsize = get_int_opt(options, 'font_size', 14)
|
| 353 |
+
self.fonts = FontManager(options.get('font_name', ''), fontsize)
|
| 354 |
+
self.fontw, self.fonth = self.fonts.get_char_size()
|
| 355 |
+
# Line number options
|
| 356 |
+
self.line_number_fg = options.get('line_number_fg', '#886')
|
| 357 |
+
self.line_number_bg = options.get('line_number_bg', '#eed')
|
| 358 |
+
self.line_number_chars = get_int_opt(options,
|
| 359 |
+
'line_number_chars', 2)
|
| 360 |
+
self.line_number_bold = get_bool_opt(options,
|
| 361 |
+
'line_number_bold', False)
|
| 362 |
+
self.line_number_italic = get_bool_opt(options,
|
| 363 |
+
'line_number_italic', False)
|
| 364 |
+
self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
|
| 365 |
+
self.line_numbers = get_bool_opt(options, 'line_numbers', True)
|
| 366 |
+
self.line_number_separator = get_bool_opt(options,
|
| 367 |
+
'line_number_separator', True)
|
| 368 |
+
self.line_number_step = get_int_opt(options, 'line_number_step', 1)
|
| 369 |
+
self.line_number_start = get_int_opt(options, 'line_number_start', 1)
|
| 370 |
+
if self.line_numbers:
|
| 371 |
+
self.line_number_width = (self.fontw * self.line_number_chars +
|
| 372 |
+
self.line_number_pad * 2)
|
| 373 |
+
else:
|
| 374 |
+
self.line_number_width = 0
|
| 375 |
+
self.hl_lines = []
|
| 376 |
+
hl_lines_str = get_list_opt(options, 'hl_lines', [])
|
| 377 |
+
for line in hl_lines_str:
|
| 378 |
+
try:
|
| 379 |
+
self.hl_lines.append(int(line))
|
| 380 |
+
except ValueError:
|
| 381 |
+
pass
|
| 382 |
+
self.hl_color = options.get('hl_color',
|
| 383 |
+
self.style.highlight_color) or '#f90'
|
| 384 |
+
self.drawables = []
|
| 385 |
+
|
| 386 |
+
def get_style_defs(self, arg=''):
|
| 387 |
+
raise NotImplementedError('The -S option is meaningless for the image '
|
| 388 |
+
'formatter. Use -O style=<stylename> instead.')
|
| 389 |
+
|
| 390 |
+
def _get_line_height(self):
|
| 391 |
+
"""
|
| 392 |
+
Get the height of a line.
|
| 393 |
+
"""
|
| 394 |
+
return self.fonth + self.line_pad
|
| 395 |
+
|
| 396 |
+
def _get_line_y(self, lineno):
|
| 397 |
+
"""
|
| 398 |
+
Get the Y coordinate of a line number.
|
| 399 |
+
"""
|
| 400 |
+
return lineno * self._get_line_height() + self.image_pad
|
| 401 |
+
|
| 402 |
+
def _get_char_width(self):
|
| 403 |
+
"""
|
| 404 |
+
Get the width of a character.
|
| 405 |
+
"""
|
| 406 |
+
return self.fontw
|
| 407 |
+
|
| 408 |
+
def _get_char_x(self, charno):
|
| 409 |
+
"""
|
| 410 |
+
Get the X coordinate of a character position.
|
| 411 |
+
"""
|
| 412 |
+
return charno * self.fontw + self.image_pad + self.line_number_width
|
| 413 |
+
|
| 414 |
+
def _get_text_pos(self, charno, lineno):
|
| 415 |
+
"""
|
| 416 |
+
Get the actual position for a character and line position.
|
| 417 |
+
"""
|
| 418 |
+
return self._get_char_x(charno), self._get_line_y(lineno)
|
| 419 |
+
|
| 420 |
+
def _get_linenumber_pos(self, lineno):
|
| 421 |
+
"""
|
| 422 |
+
Get the actual position for the start of a line number.
|
| 423 |
+
"""
|
| 424 |
+
return (self.image_pad, self._get_line_y(lineno))
|
| 425 |
+
|
| 426 |
+
def _get_text_color(self, style):
|
| 427 |
+
"""
|
| 428 |
+
Get the correct color for the token from the style.
|
| 429 |
+
"""
|
| 430 |
+
if style['color'] is not None:
|
| 431 |
+
fill = '#' + style['color']
|
| 432 |
+
else:
|
| 433 |
+
fill = '#000'
|
| 434 |
+
return fill
|
| 435 |
+
|
| 436 |
+
def _get_style_font(self, style):
|
| 437 |
+
"""
|
| 438 |
+
Get the correct font for the style.
|
| 439 |
+
"""
|
| 440 |
+
return self.fonts.get_font(style['bold'], style['italic'])
|
| 441 |
+
|
| 442 |
+
def _get_image_size(self, maxcharno, maxlineno):
|
| 443 |
+
"""
|
| 444 |
+
Get the required image size.
|
| 445 |
+
"""
|
| 446 |
+
return (self._get_char_x(maxcharno) + self.image_pad,
|
| 447 |
+
self._get_line_y(maxlineno + 0) + self.image_pad)
|
| 448 |
+
|
| 449 |
+
def _draw_linenumber(self, posno, lineno):
|
| 450 |
+
"""
|
| 451 |
+
Remember a line number drawable to paint later.
|
| 452 |
+
"""
|
| 453 |
+
self._draw_text(
|
| 454 |
+
self._get_linenumber_pos(posno),
|
| 455 |
+
str(lineno).rjust(self.line_number_chars),
|
| 456 |
+
font=self.fonts.get_font(self.line_number_bold,
|
| 457 |
+
self.line_number_italic),
|
| 458 |
+
fill=self.line_number_fg,
|
| 459 |
+
)
|
| 460 |
+
|
| 461 |
+
def _draw_text(self, pos, text, font, **kw):
|
| 462 |
+
"""
|
| 463 |
+
Remember a single drawable tuple to paint later.
|
| 464 |
+
"""
|
| 465 |
+
self.drawables.append((pos, text, font, kw))
|
| 466 |
+
|
| 467 |
+
def _create_drawables(self, tokensource):
|
| 468 |
+
"""
|
| 469 |
+
Create drawables for the token content.
|
| 470 |
+
"""
|
| 471 |
+
lineno = charno = maxcharno = 0
|
| 472 |
+
for ttype, value in tokensource:
|
| 473 |
+
while ttype not in self.styles:
|
| 474 |
+
ttype = ttype.parent
|
| 475 |
+
style = self.styles[ttype]
|
| 476 |
+
# TODO: make sure tab expansion happens earlier in the chain. It
|
| 477 |
+
# really ought to be done on the input, as to do it right here is
|
| 478 |
+
# quite complex.
|
| 479 |
+
value = value.expandtabs(4)
|
| 480 |
+
lines = value.splitlines(True)
|
| 481 |
+
# print lines
|
| 482 |
+
for i, line in enumerate(lines):
|
| 483 |
+
temp = line.rstrip('\n')
|
| 484 |
+
if temp:
|
| 485 |
+
self._draw_text(
|
| 486 |
+
self._get_text_pos(charno, lineno),
|
| 487 |
+
temp,
|
| 488 |
+
font = self._get_style_font(style),
|
| 489 |
+
fill = self._get_text_color(style)
|
| 490 |
+
)
|
| 491 |
+
charno += len(temp)
|
| 492 |
+
maxcharno = max(maxcharno, charno)
|
| 493 |
+
if line.endswith('\n'):
|
| 494 |
+
# add a line for each extra line in the value
|
| 495 |
+
charno = 0
|
| 496 |
+
lineno += 1
|
| 497 |
+
self.maxcharno = maxcharno
|
| 498 |
+
self.maxlineno = lineno
|
| 499 |
+
|
| 500 |
+
def _draw_line_numbers(self):
|
| 501 |
+
"""
|
| 502 |
+
Create drawables for the line numbers.
|
| 503 |
+
"""
|
| 504 |
+
if not self.line_numbers:
|
| 505 |
+
return
|
| 506 |
+
for p in xrange(self.maxlineno):
|
| 507 |
+
n = p + self.line_number_start
|
| 508 |
+
if (n % self.line_number_step) == 0:
|
| 509 |
+
self._draw_linenumber(p, n)
|
| 510 |
+
|
| 511 |
+
def _paint_line_number_bg(self, im):
|
| 512 |
+
"""
|
| 513 |
+
Paint the line number background on the image.
|
| 514 |
+
"""
|
| 515 |
+
if not self.line_numbers:
|
| 516 |
+
return
|
| 517 |
+
if self.line_number_fg is None:
|
| 518 |
+
return
|
| 519 |
+
draw = ImageDraw.Draw(im)
|
| 520 |
+
recth = im.size[-1]
|
| 521 |
+
rectw = self.image_pad + self.line_number_width - self.line_number_pad
|
| 522 |
+
draw.rectangle([(0, 0), (rectw, recth)],
|
| 523 |
+
fill=self.line_number_bg)
|
| 524 |
+
draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg)
|
| 525 |
+
del draw
|
| 526 |
+
|
| 527 |
+
def format(self, tokensource, outfile):
|
| 528 |
+
"""
|
| 529 |
+
Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
|
| 530 |
+
tuples and write it into ``outfile``.
|
| 531 |
+
|
| 532 |
+
This implementation calculates where it should draw each token on the
|
| 533 |
+
pixmap, then calculates the required pixmap size and draws the items.
|
| 534 |
+
"""
|
| 535 |
+
self._create_drawables(tokensource)
|
| 536 |
+
self._draw_line_numbers()
|
| 537 |
+
im = Image.new(
|
| 538 |
+
'RGB',
|
| 539 |
+
self._get_image_size(self.maxcharno, self.maxlineno),
|
| 540 |
+
self.background_color
|
| 541 |
+
)
|
| 542 |
+
self._paint_line_number_bg(im)
|
| 543 |
+
draw = ImageDraw.Draw(im)
|
| 544 |
+
# Highlight
|
| 545 |
+
if self.hl_lines:
|
| 546 |
+
x = self.image_pad + self.line_number_width - self.line_number_pad + 1
|
| 547 |
+
recth = self._get_line_height()
|
| 548 |
+
rectw = im.size[0] - x
|
| 549 |
+
for linenumber in self.hl_lines:
|
| 550 |
+
y = self._get_line_y(linenumber - 1)
|
| 551 |
+
draw.rectangle([(x, y), (x + rectw, y + recth)],
|
| 552 |
+
fill=self.hl_color)
|
| 553 |
+
for pos, value, font, kw in self.drawables:
|
| 554 |
+
draw.text(pos, value, font=font, **kw)
|
| 555 |
+
im.save(outfile, self.image_format.upper())
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
# Add one formatter per format, so that the "-f gif" option gives the correct result
|
| 559 |
+
# when used in pygmentize.
|
| 560 |
+
|
| 561 |
+
class GifImageFormatter(ImageFormatter):
|
| 562 |
+
"""
|
| 563 |
+
Create a GIF image from source code. This uses the Python Imaging Library to
|
| 564 |
+
generate a pixmap from the source code.
|
| 565 |
+
|
| 566 |
+
.. versionadded:: 1.0
|
| 567 |
+
"""
|
| 568 |
+
|
| 569 |
+
name = 'img_gif'
|
| 570 |
+
aliases = ['gif']
|
| 571 |
+
filenames = ['*.gif']
|
| 572 |
+
default_image_format = 'gif'
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
class JpgImageFormatter(ImageFormatter):
|
| 576 |
+
"""
|
| 577 |
+
Create a JPEG image from source code. This uses the Python Imaging Library to
|
| 578 |
+
generate a pixmap from the source code.
|
| 579 |
+
|
| 580 |
+
.. versionadded:: 1.0
|
| 581 |
+
"""
|
| 582 |
+
|
| 583 |
+
name = 'img_jpg'
|
| 584 |
+
aliases = ['jpg', 'jpeg']
|
| 585 |
+
filenames = ['*.jpg']
|
| 586 |
+
default_image_format = 'jpeg'
|
| 587 |
+
|
| 588 |
+
|
| 589 |
+
class BmpImageFormatter(ImageFormatter):
|
| 590 |
+
"""
|
| 591 |
+
Create a bitmap image from source code. This uses the Python Imaging Library to
|
| 592 |
+
generate a pixmap from the source code.
|
| 593 |
+
|
| 594 |
+
.. versionadded:: 1.0
|
| 595 |
+
"""
|
| 596 |
+
|
| 597 |
+
name = 'img_bmp'
|
| 598 |
+
aliases = ['bmp', 'bitmap']
|
| 599 |
+
filenames = ['*.bmp']
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
pygments.formatters.irc
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
Formatter for IRC output
|
| 7 |
+
|
| 8 |
+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
| 9 |
+
:license: BSD, see LICENSE for details.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
from pygments.formatter import Formatter
|
| 15 |
+
from pygments.token import Keyword, Name, Comment, String, Error, \
|
| 16 |
+
Number, Operator, Generic, Token, Whitespace
|
| 17 |
+
from pygments.util import get_choice_opt
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
__all__ = ['IRCFormatter']
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
#: Map token types to a tuple of color values for light and dark
|
| 24 |
+
#: backgrounds.
|
| 25 |
+
IRC_COLORS = {
|
| 26 |
+
Token: ('', ''),
|
| 27 |
+
|
| 28 |
+
Whitespace: ('lightgray', 'darkgray'),
|
| 29 |
+
Comment: ('lightgray', 'darkgray'),
|
| 30 |
+
Comment.Preproc: ('teal', 'turquoise'),
|
| 31 |
+
Keyword: ('darkblue', 'blue'),
|
| 32 |
+
Keyword.Type: ('teal', 'turquoise'),
|
| 33 |
+
Operator.Word: ('purple', 'fuchsia'),
|
| 34 |
+
Name.Builtin: ('teal', 'turquoise'),
|
| 35 |
+
Name.Function: ('darkgreen', 'green'),
|
| 36 |
+
Name.Namespace: ('_teal_', '_turquoise_'),
|
| 37 |
+
Name.Class: ('_darkgreen_', '_green_'),
|
| 38 |
+
Name.Exception: ('teal', 'turquoise'),
|
| 39 |
+
Name.Decorator: ('darkgray', 'lightgray'),
|
| 40 |
+
Name.Variable: ('darkred', 'red'),
|
| 41 |
+
Name.Constant: ('darkred', 'red'),
|
| 42 |
+
Name.Attribute: ('teal', 'turquoise'),
|
| 43 |
+
Name.Tag: ('blue', 'blue'),
|
| 44 |
+
String: ('brown', 'brown'),
|
| 45 |
+
Number: ('darkblue', 'blue'),
|
| 46 |
+
|
| 47 |
+
Generic.Deleted: ('red', 'red'),
|
| 48 |
+
Generic.Inserted: ('darkgreen', 'green'),
|
| 49 |
+
Generic.Heading: ('**', '**'),
|
| 50 |
+
Generic.Subheading: ('*purple*', '*fuchsia*'),
|
| 51 |
+
Generic.Error: ('red', 'red'),
|
| 52 |
+
|
| 53 |
+
Error: ('_red_', '_red_'),
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
IRC_COLOR_MAP = {
|
| 58 |
+
'white': 0,
|
| 59 |
+
'black': 1,
|
| 60 |
+
'darkblue': 2,
|
| 61 |
+
'green': 3,
|
| 62 |
+
'red': 4,
|
| 63 |
+
'brown': 5,
|
| 64 |
+
'purple': 6,
|
| 65 |
+
'orange': 7,
|
| 66 |
+
'darkgreen': 7, #compat w/ ansi
|
| 67 |
+
'yellow': 8,
|
| 68 |
+
'lightgreen': 9,
|
| 69 |
+
'turquoise': 9, # compat w/ ansi
|
| 70 |
+
'teal': 10,
|
| 71 |
+
'lightblue': 11,
|
| 72 |
+
'darkred': 11, # compat w/ ansi
|
| 73 |
+
'blue': 12,
|
| 74 |
+
'fuchsia': 13,
|
| 75 |
+
'darkgray': 14,
|
| 76 |
+
'lightgray': 15,
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
def ircformat(color, text):
|
| 80 |
+
if len(color) < 1:
|
| 81 |
+
return text
|
| 82 |
+
add = sub = ''
|
| 83 |
+
if '_' in color: # italic
|
| 84 |
+
add += '\x1D'
|
| 85 |
+
sub = '\x1D' + sub
|
| 86 |
+
color = color.strip('_')
|
| 87 |
+
if '*' in color: # bold
|
| 88 |
+
add += '\x02'
|
| 89 |
+
sub = '\x02' + sub
|
| 90 |
+
color = color.strip('*')
|
| 91 |
+
# underline (\x1F) not supported
|
| 92 |
+
# backgrounds (\x03FF,BB) not supported
|
| 93 |
+
if len(color) > 0: # actual color - may have issues with ircformat("red", "blah")+"10" type stuff
|
| 94 |
+
add += '\x03' + str(IRC_COLOR_MAP[color]).zfill(2)
|
| 95 |
+
sub = '\x03' + sub
|
| 96 |
+
return add + text + sub
|
| 97 |
+
return '<'+add+'>'+text+'</'+sub+'>'
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class IRCFormatter(Formatter):
|
| 101 |
+
r"""
|
| 102 |
+
Format tokens with IRC color sequences
|
| 103 |
+
|
| 104 |
+
The `get_style_defs()` method doesn't do anything special since there is
|
| 105 |
+
no support for common styles.
|
| 106 |
+
|
| 107 |
+
Options accepted:
|
| 108 |
+
|
| 109 |
+
`bg`
|
| 110 |
+
Set to ``"light"`` or ``"dark"`` depending on the terminal's background
|
| 111 |
+
(default: ``"light"``).
|
| 112 |
+
|
| 113 |
+
`colorscheme`
|
| 114 |
+
A dictionary mapping token types to (lightbg, darkbg) color names or
|
| 115 |
+
``None`` (default: ``None`` = use builtin colorscheme).
|
| 116 |
+
|
| 117 |
+
`linenos`
|
| 118 |
+
Set to ``True`` to have line numbers in the output as well
|
| 119 |
+
(default: ``False`` = no line numbers).
|
| 120 |
+
"""
|
| 121 |
+
name = 'IRC'
|
| 122 |
+
aliases = ['irc', 'IRC']
|
| 123 |
+
filenames = []
|
| 124 |
+
|
| 125 |
+
def __init__(self, **options):
|
| 126 |
+
Formatter.__init__(self, **options)
|
| 127 |
+
self.darkbg = get_choice_opt(options, 'bg',
|
| 128 |
+
['light', 'dark'], 'light') == 'dark'
|
| 129 |
+
self.colorscheme = options.get('colorscheme', None) or IRC_COLORS
|
| 130 |
+
self.linenos = options.get('linenos', False)
|
| 131 |
+
self._lineno = 0
|
| 132 |
+
|
| 133 |
+
def _write_lineno(self, outfile):
|
| 134 |
+
self._lineno += 1
|
| 135 |
+
outfile.write("\n%04d: " % self._lineno)
|
| 136 |
+
|
| 137 |
+
def _format_unencoded_with_lineno(self, tokensource, outfile):
|
| 138 |
+
self._write_lineno(outfile)
|
| 139 |
+
|
| 140 |
+
for ttype, value in tokensource:
|
| 141 |
+
if value.endswith("\n"):
|
| 142 |
+
self._write_lineno(outfile)
|
| 143 |
+
value = value[:-1]
|
| 144 |
+
color = self.colorscheme.get(ttype)
|
| 145 |
+
while color is None:
|
| 146 |
+
ttype = ttype[:-1]
|
| 147 |
+
color = self.colorscheme.get(ttype)
|
| 148 |
+
if color:
|
| 149 |
+
color = color[self.darkbg]
|
| 150 |
+
spl = value.split('\n')
|
| 151 |
+
for line in spl[:-1]:
|
| 152 |
+
self._write_lineno(outfile)
|
| 153 |
+
if line:
|
| 154 |
+
outfile.write(ircformat(color, line[:-1]))
|
| 155 |
+
if spl[-1]:
|
| 156 |
+
outfile.write(ircformat(color, spl[-1]))
|
| 157 |
+
else:
|
| 158 |
+
outfile.write(value)
|
| 159 |
+
|
| 160 |
+
outfile.write("\n")
|
| 161 |
+
|
| 162 |
+
def format_unencoded(self, tokensource, outfile):
|
| 163 |
+
if self.linenos:
|
| 164 |
+
self._format_unencoded_with_lineno(tokensource, outfile)
|
| 165 |
+
return
|
| 166 |
+
|
| 167 |
+
for ttype, value in tokensource:
|
| 168 |
+
color = self.colorscheme.get(ttype)
|
| 169 |
+
while color is None:
|
| 170 |
+
ttype = ttype[:-1]
|
| 171 |
+
color = self.colorscheme.get(ttype)
|
| 172 |
+
if color:
|
| 173 |
+
color = color[self.darkbg]
|
| 174 |
+
spl = value.split('\n')
|
| 175 |
+
for line in spl[:-1]:
|
| 176 |
+
if line:
|
| 177 |
+
outfile.write(ircformat(color, line))
|
| 178 |
+
outfile.write('\n')
|
| 179 |
+
if spl[-1]:
|
| 180 |
+
outfile.write(ircformat(color, spl[-1]))
|
| 181 |
+
else:
|
| 182 |
+
outfile.write(value)
|