Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

import unittest 

 

import numpy as np 

from numpy.testing import assert_allclose 

 

import astshim as ast 

from astshim.test import MappingTestCase 

 

 

class TestPermMap(MappingTestCase): 

 

def test_PermMapMatched(self): 

"""Test a PermMap whose inverse is the inverse of its forward 

""" 

permmap = ast.PermMap([2, 3, 1], [3, 1, 2]) 

self.assertEqual(permmap.className, "PermMap") 

self.assertEqual(permmap.nIn, 3) 

self.assertEqual(permmap.nOut, 3) 

 

self.checkBasicSimplify(permmap) 

self.checkCopy(permmap) 

 

indata = np.array([ 

[1.1, -43.5], 

[2.2, 1309.31], 

[3.3, 0.005], 

]) 

outdata = permmap.applyForward(indata) 

pred_outdata = np.array([ 

[3.3, 0.005], 

[1.1, -43.5], 

[2.2, 1309.31], 

]) 

assert_allclose(outdata, pred_outdata) 

 

self.checkRoundTrip(permmap, indata) 

self.checkMappingPersistence(permmap, indata) 

 

def test_PermMapUnmatched(self): 

"""Test PermMap with different number of inputs and outputs 

""" 

permmap = ast.PermMap([2, 1, 3], [3, 1]) 

self.assertEqual(permmap.className, "PermMap") 

self.assertEqual(permmap.nIn, 3) 

self.assertEqual(permmap.nOut, 2) 

 

indata = np.array([1.1, 2.2, -3.3]) 

outdata = permmap.applyForward(indata) 

assert_allclose(outdata, [-3.3, 1.1]) 

 

indata2 = np.array([1.1, 2.2]) 

outdata2 = permmap.applyInverse(indata2) 

assert_allclose(outdata2, [2.2, 1.1, np.nan], equal_nan=True) 

 

self.checkMappingPersistence(permmap, indata) 

 

def test_PermMapWithConstants(self): 

"""Test a PermMap with constant values 

""" 

permmap = ast.PermMap([-2, 1, 3], [2, 1, -1], [75.3, -126.5]) 

self.assertEqual(permmap.className, "PermMap") 

self.assertEqual(permmap.nIn, 3) 

self.assertEqual(permmap.nOut, 3) 

 

indata = np.array([1.1, 2.2, 3.3]) 

outdata = permmap.applyForward(indata) 

assert_allclose(outdata, [2.2, 1.1, 75.3]) 

 

outdata2 = permmap.applyInverse(indata) 

assert_allclose(outdata2, [-126.5, 1.1, 3.3]) 

 

self.checkMappingPersistence(permmap, indata) 

 

 

75 ↛ 76line 75 didn't jump to line 76, because the condition on line 75 was never trueif __name__ == "__main__": 

unittest.main()