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

Class TestEvaluation

numpy/polynomial/tests/test_legendre.py:113–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111
112
113class TestEvaluation:
114 # coefficients of 1 + 2*x + 3*x**2
115 c1d = np.array([2., 2., 2.])
116 c2d = np.einsum('i,j->ij', c1d, c1d)
117 c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)
118
119 # some random values in [-1, 1)
120 x = np.random.random((3, 5))*2 - 1
121 y = polyval(x, [1., 2., 3.])
122
123 def test_legval(self):
124 #check empty input
125 assert_equal(leg.legval([], [1]).size, 0)
126
127 #check normal input)
128 x = np.linspace(-1, 1)
129 y = [polyval(x, c) for c in Llist]
130 for i in range(10):
131 msg = f"At i={i}"
132 tgt = y[i]
133 res = leg.legval(x, [0]*i + [1])
134 assert_almost_equal(res, tgt, err_msg=msg)
135
136 #check that shape is preserved
137 for i in range(3):
138 dims = [2]*i
139 x = np.zeros(dims)
140 assert_equal(leg.legval(x, [1]).shape, dims)
141 assert_equal(leg.legval(x, [1, 0]).shape, dims)
142 assert_equal(leg.legval(x, [1, 0, 0]).shape, dims)
143
144 def test_legval2d(self):
145 x1, x2, x3 = self.x
146 y1, y2, y3 = self.y
147
148 #test exceptions
149 assert_raises(ValueError, leg.legval2d, x1, x2[:2], self.c2d)
150
151 #test values
152 tgt = y1*y2
153 res = leg.legval2d(x1, x2, self.c2d)
154 assert_almost_equal(res, tgt)
155
156 #test shape
157 z = np.ones((2, 3))
158 res = leg.legval2d(z, z, self.c2d)
159 assert_(res.shape == (2, 3))
160
161 def test_legval3d(self):
162 x1, x2, x3 = self.x
163 y1, y2, y3 = self.y
164
165 #test exceptions
166 assert_raises(ValueError, leg.legval3d, x1, x2, x3[:2], self.c3d)
167
168 #test values
169 tgt = y1*y2*y3
170 res = leg.legval3d(x1, x2, x3, self.c3d)

Callers

nothing calls this directly

Calls 2

polyvalFunction · 0.90
randomMethod · 0.80

Tested by

no test coverage detected