MCPcopy Create free account
hub / github.com/numpy/numpy / TestEvaluation

Class TestEvaluation

numpy/polynomial/tests/test_chebyshev.py:124–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122
123
124class 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)

Callers

nothing calls this directly

Calls 2

polyvalFunction · 0.90
randomMethod · 0.80

Tested by

no test coverage detected