<s> import numpy as np <EOL> from numpy . testing import assert_allclose <EOL> from nose . tools import raises <EOL> from menpo . transform import Rotation <EOL> def test_basic_2d_rotation ( ) : <EOL> rotation_matrix = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ - <NUM_LIT:1> , <NUM_LIT:0> ] ] ) <EOL> rotation = Rotation ( rotation_matrix ) <EOL> assert_allclose ( np . array ( [ <NUM_LIT:0> , - <NUM_LIT:1> ] ) , rotation . apply ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:0> ] ) ) ) <EOL> def test_basic_2d_rotation_axis_angle ( ) : <EOL> rotation_matrix = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ - <NUM_LIT:1> , <NUM_LIT:0> ] ] ) <EOL> rotation = Rotation ( rotation_matrix ) <EOL> axis , angle = rotation . axis_and_angle_of_rotation ( ) <EOL> assert_allclose ( axis , np . array ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> assert_allclose ( ( <NUM_LIT> * np . pi ) / <NUM_LIT> , angle ) <EOL> def test_basic_3d_rotation ( ) : <EOL> a = np . sqrt ( <NUM_LIT> ) / <NUM_LIT> <EOL> b = <NUM_LIT:0.5> <EOL> rotation_matrix = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , a , b ] , <EOL> [ <NUM_LIT:0> , - b , a ] ] ) <EOL> rotation = Rotation ( rotation_matrix ) <EOL> starting_vector = np . array ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> transformed = rotation . apply ( starting_vector ) <EOL> assert_allclose ( np . array ( [ <NUM_LIT:0> , a , - b ] ) , transformed ) <EOL> def test_basic_3d_rotation_axis_angle ( ) : <EOL> a = np . sqrt ( <NUM_LIT> ) / <NUM_LIT> <EOL> b = <NUM_LIT:0.5> <EOL> rotation_matrix = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , a , b ] , <EOL> [ <NUM_LIT:0> , - b , a ] ] ) <EOL> rotation = Rotation ( rotation_matrix ) <EOL> axis , angle = rotation . axis_and_angle_of_rotation ( ) <EOL> assert_allclose ( axis , np . array ( [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] ) ) <EOL> assert_allclose ( ( - <NUM_LIT:30> * np . pi ) / <NUM_LIT> , angle ) <EOL> def test_3d_rotation_inverse_eye ( ) : <EOL> a = np . sqrt ( <NUM_LIT> ) / <NUM_LIT> <EOL> b = <NUM_LIT:0.5> <EOL> rotation_matrix = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , a , b ] , <EOL> [ <NUM_LIT:0> , - b , a ] ] ) <EOL> rotation = Rotation ( rotation_matrix ) <EOL> transformed = rotation . compose_before ( rotation . pseudoinverse ( ) ) <EOL> assert_allclose ( np . eye ( <NUM_LIT:4> ) , transformed . h_matrix , atol = <NUM_LIT> ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_rotation3d_from_vector_raises_notimplementederror ( ) : <EOL> Rotation . init_identity ( <NUM_LIT:3> ) . from_vector ( <NUM_LIT:0> ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_rotation3d_as_vector_raises_notimplementederror ( ) : <EOL> Rotation . init_identity ( <NUM_LIT:3> ) . as_vector ( ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_rotation2d_n_parameters_raises_notimplementederror ( ) : <EOL> rot_matrix = np . eye ( <NUM_LIT:2> ) <EOL> t = Rotation ( rot_matrix ) <EOL> t . n_parameters <EOL> @ raises ( NotImplementedError ) <EOL> def test_rotation3d_n_parameters_raises_notimplementederror ( ) : <EOL> rot_matrix = np . eye ( <NUM_LIT:3> ) <EOL> t = Rotation ( rot_matrix ) <EOL> t . n_parameters <EOL> def test_rotation2d_identity ( ) : <EOL> assert_allclose ( Rotation . init_identity ( <NUM_LIT:2> ) . h_matrix , np . eye ( <NUM_LIT:3> ) ) <EOL> def test_rotation3d_identity ( ) : <EOL> assert_allclose ( Rotation . init_identity ( <NUM_LIT:3> ) . h_matrix , np . eye ( <NUM_LIT:4> ) ) </s>
