~inkscape.dev/inkscape-devlibs64/trunk

« back to all changes in this revision

Viewing changes to python/Lib/site-packages/numpy/polynomial/tests/test_hermite_e.py

  • Committer: Eduard Braun
  • Date: 2016-10-22 16:51:19 UTC
  • Revision ID: eduard.braun2@gmx.de-20161022165119-9eosgy6lp8j1kzli
Update Python to version 2.7.12

Included modules:
  coverage 4.2
  lxml 3.6.4
  numpy 1.11.2
  scour 0.35
  six 1.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
388
388
        def f(x):
389
389
            return x*(x - 1)*(x - 2)
390
390
 
 
391
        def f2(x):
 
392
            return x**4 + x**2 + 1
 
393
 
391
394
        # Test exceptions
392
395
        assert_raises(ValueError, herme.hermefit, [1], [1], -1)
393
396
        assert_raises(TypeError, herme.hermefit, [[1]], [1], 0)
397
400
        assert_raises(TypeError, herme.hermefit, [1], [1, 2], 0)
398
401
        assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[[1]])
399
402
        assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[1, 1])
 
403
        assert_raises(ValueError, herme.hermefit, [1], [1], [-1,])
 
404
        assert_raises(ValueError, herme.hermefit, [1], [1], [2, -1, 6])
 
405
        assert_raises(TypeError, herme.hermefit, [1], [1], [])
400
406
 
401
407
        # Test fit
402
408
        x = np.linspace(0, 2)
405
411
        coef3 = herme.hermefit(x, y, 3)
406
412
        assert_equal(len(coef3), 4)
407
413
        assert_almost_equal(herme.hermeval(x, coef3), y)
 
414
        coef3 = herme.hermefit(x, y, [0, 1, 2, 3])
 
415
        assert_equal(len(coef3), 4)
 
416
        assert_almost_equal(herme.hermeval(x, coef3), y)
408
417
        #
409
418
        coef4 = herme.hermefit(x, y, 4)
410
419
        assert_equal(len(coef4), 5)
411
420
        assert_almost_equal(herme.hermeval(x, coef4), y)
 
421
        coef4 = herme.hermefit(x, y, [0, 1, 2, 3, 4])
 
422
        assert_equal(len(coef4), 5)
 
423
        assert_almost_equal(herme.hermeval(x, coef4), y)
 
424
        # check things still work if deg is not in strict increasing
 
425
        coef4 = herme.hermefit(x, y, [2, 3, 4, 1, 0])
 
426
        assert_equal(len(coef4), 5)
 
427
        assert_almost_equal(herme.hermeval(x, coef4), y)
412
428
        #
413
429
        coef2d = herme.hermefit(x, np.array([y, y]).T, 3)
414
430
        assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
 
431
        coef2d = herme.hermefit(x, np.array([y, y]).T, [0, 1, 2, 3])
 
432
        assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
415
433
        # test weighting
416
434
        w = np.zeros_like(x)
417
435
        yw = y.copy()
419
437
        y[0::2] = 0
420
438
        wcoef3 = herme.hermefit(x, yw, 3, w=w)
421
439
        assert_almost_equal(wcoef3, coef3)
 
440
        wcoef3 = herme.hermefit(x, yw, [0, 1, 2, 3], w=w)
 
441
        assert_almost_equal(wcoef3, coef3)
422
442
        #
423
443
        wcoef2d = herme.hermefit(x, np.array([yw, yw]).T, 3, w=w)
424
444
        assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
 
445
        wcoef2d = herme.hermefit(x, np.array([yw, yw]).T, [0, 1, 2, 3], w=w)
 
446
        assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
425
447
        # test scaling with complex values x points whose square
426
448
        # is zero when summed.
427
449
        x = [1, 1j, -1, -1j]
428
450
        assert_almost_equal(herme.hermefit(x, x, 1), [0, 1])
 
451
        assert_almost_equal(herme.hermefit(x, x, [0, 1]), [0, 1])
 
452
        # test fitting only even Legendre polynomials
 
453
        x = np.linspace(-1, 1)
 
454
        y = f2(x)
 
455
        coef1 = herme.hermefit(x, y, 4)
 
456
        assert_almost_equal(herme.hermeval(x, coef1), y)
 
457
        coef2 = herme.hermefit(x, y, [0, 2, 4])
 
458
        assert_almost_equal(herme.hermeval(x, coef2), y)
 
459
        assert_almost_equal(coef1, coef2)
429
460
 
430
461
 
431
462
class TestCompanion(TestCase):