How to use q3 method in pytest-benchmark

Best Python code snippet using pytest-benchmark

test_functions.py

Source:test_functions.py Github

copy

Full Screen

1from sympy.vector.vector import Vector2from sympy.vector.coordsysrect import CoordSys3D3from sympy.vector.functions import express, matrix_to_vector, orthogonalize4from sympy import symbols, S, sqrt, sin, cos, ImmutableMatrix as Matrix, Rational5from sympy.testing.pytest import raises6N = CoordSys3D('N')7q1, q2, q3, q4, q5 = symbols('q1 q2 q3 q4 q5')8A = N.orient_new_axis('A', q1, N.k) # type: ignore9B = A.orient_new_axis('B', q2, A.i)10C = B.orient_new_axis('C', q3, B.j)11def test_express():12 assert express(Vector.zero, N) == Vector.zero13 assert express(S.Zero, N) is S.Zero14 assert express(A.i, C) == cos(q3)*C.i + sin(q3)*C.k15 assert express(A.j, C) == sin(q2)*sin(q3)*C.i + cos(q2)*C.j - \16 sin(q2)*cos(q3)*C.k17 assert express(A.k, C) == -sin(q3)*cos(q2)*C.i + sin(q2)*C.j + \18 cos(q2)*cos(q3)*C.k19 assert express(A.i, N) == cos(q1)*N.i + sin(q1)*N.j20 assert express(A.j, N) == -sin(q1)*N.i + cos(q1)*N.j21 assert express(A.k, N) == N.k22 assert express(A.i, A) == A.i23 assert express(A.j, A) == A.j24 assert express(A.k, A) == A.k25 assert express(A.i, B) == B.i26 assert express(A.j, B) == cos(q2)*B.j - sin(q2)*B.k27 assert express(A.k, B) == sin(q2)*B.j + cos(q2)*B.k28 assert express(A.i, C) == cos(q3)*C.i + sin(q3)*C.k29 assert express(A.j, C) == sin(q2)*sin(q3)*C.i + cos(q2)*C.j - \30 sin(q2)*cos(q3)*C.k31 assert express(A.k, C) == -sin(q3)*cos(q2)*C.i + sin(q2)*C.j + \32 cos(q2)*cos(q3)*C.k33 # Check to make sure UnitVectors get converted properly34 assert express(N.i, N) == N.i35 assert express(N.j, N) == N.j36 assert express(N.k, N) == N.k37 assert express(N.i, A) == (cos(q1)*A.i - sin(q1)*A.j)38 assert express(N.j, A) == (sin(q1)*A.i + cos(q1)*A.j)39 assert express(N.k, A) == A.k40 assert express(N.i, B) == (cos(q1)*B.i - sin(q1)*cos(q2)*B.j +41 sin(q1)*sin(q2)*B.k)42 assert express(N.j, B) == (sin(q1)*B.i + cos(q1)*cos(q2)*B.j -43 sin(q2)*cos(q1)*B.k)44 assert express(N.k, B) == (sin(q2)*B.j + cos(q2)*B.k)45 assert express(N.i, C) == (46 (cos(q1)*cos(q3) - sin(q1)*sin(q2)*sin(q3))*C.i -47 sin(q1)*cos(q2)*C.j +48 (sin(q3)*cos(q1) + sin(q1)*sin(q2)*cos(q3))*C.k)49 assert express(N.j, C) == (50 (sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1))*C.i +51 cos(q1)*cos(q2)*C.j +52 (sin(q1)*sin(q3) - sin(q2)*cos(q1)*cos(q3))*C.k)53 assert express(N.k, C) == (-sin(q3)*cos(q2)*C.i + sin(q2)*C.j +54 cos(q2)*cos(q3)*C.k)55 assert express(A.i, N) == (cos(q1)*N.i + sin(q1)*N.j)56 assert express(A.j, N) == (-sin(q1)*N.i + cos(q1)*N.j)57 assert express(A.k, N) == N.k58 assert express(A.i, A) == A.i59 assert express(A.j, A) == A.j60 assert express(A.k, A) == A.k61 assert express(A.i, B) == B.i62 assert express(A.j, B) == (cos(q2)*B.j - sin(q2)*B.k)63 assert express(A.k, B) == (sin(q2)*B.j + cos(q2)*B.k)64 assert express(A.i, C) == (cos(q3)*C.i + sin(q3)*C.k)65 assert express(A.j, C) == (sin(q2)*sin(q3)*C.i + cos(q2)*C.j -66 sin(q2)*cos(q3)*C.k)67 assert express(A.k, C) == (-sin(q3)*cos(q2)*C.i + sin(q2)*C.j +68 cos(q2)*cos(q3)*C.k)69 assert express(B.i, N) == (cos(q1)*N.i + sin(q1)*N.j)70 assert express(B.j, N) == (-sin(q1)*cos(q2)*N.i +71 cos(q1)*cos(q2)*N.j + sin(q2)*N.k)72 assert express(B.k, N) == (sin(q1)*sin(q2)*N.i -73 sin(q2)*cos(q1)*N.j + cos(q2)*N.k)74 assert express(B.i, A) == A.i75 assert express(B.j, A) == (cos(q2)*A.j + sin(q2)*A.k)76 assert express(B.k, A) == (-sin(q2)*A.j + cos(q2)*A.k)77 assert express(B.i, B) == B.i78 assert express(B.j, B) == B.j79 assert express(B.k, B) == B.k80 assert express(B.i, C) == (cos(q3)*C.i + sin(q3)*C.k)81 assert express(B.j, C) == C.j82 assert express(B.k, C) == (-sin(q3)*C.i + cos(q3)*C.k)83 assert express(C.i, N) == (84 (cos(q1)*cos(q3) - sin(q1)*sin(q2)*sin(q3))*N.i +85 (sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1))*N.j -86 sin(q3)*cos(q2)*N.k)87 assert express(C.j, N) == (88 -sin(q1)*cos(q2)*N.i + cos(q1)*cos(q2)*N.j + sin(q2)*N.k)89 assert express(C.k, N) == (90 (sin(q3)*cos(q1) + sin(q1)*sin(q2)*cos(q3))*N.i +91 (sin(q1)*sin(q3) - sin(q2)*cos(q1)*cos(q3))*N.j +92 cos(q2)*cos(q3)*N.k)93 assert express(C.i, A) == (cos(q3)*A.i + sin(q2)*sin(q3)*A.j -94 sin(q3)*cos(q2)*A.k)95 assert express(C.j, A) == (cos(q2)*A.j + sin(q2)*A.k)96 assert express(C.k, A) == (sin(q3)*A.i - sin(q2)*cos(q3)*A.j +97 cos(q2)*cos(q3)*A.k)98 assert express(C.i, B) == (cos(q3)*B.i - sin(q3)*B.k)99 assert express(C.j, B) == B.j100 assert express(C.k, B) == (sin(q3)*B.i + cos(q3)*B.k)101 assert express(C.i, C) == C.i102 assert express(C.j, C) == C.j103 assert express(C.k, C) == C.k == (C.k)104 # Check to make sure Vectors get converted back to UnitVectors105 assert N.i == express((cos(q1)*A.i - sin(q1)*A.j), N).simplify()106 assert N.j == express((sin(q1)*A.i + cos(q1)*A.j), N).simplify()107 assert N.i == express((cos(q1)*B.i - sin(q1)*cos(q2)*B.j +108 sin(q1)*sin(q2)*B.k), N).simplify()109 assert N.j == express((sin(q1)*B.i + cos(q1)*cos(q2)*B.j -110 sin(q2)*cos(q1)*B.k), N).simplify()111 assert N.k == express((sin(q2)*B.j + cos(q2)*B.k), N).simplify()112 assert A.i == express((cos(q1)*N.i + sin(q1)*N.j), A).simplify()113 assert A.j == express((-sin(q1)*N.i + cos(q1)*N.j), A).simplify()114 assert A.j == express((cos(q2)*B.j - sin(q2)*B.k), A).simplify()115 assert A.k == express((sin(q2)*B.j + cos(q2)*B.k), A).simplify()116 assert A.i == express((cos(q3)*C.i + sin(q3)*C.k), A).simplify()117 assert A.j == express((sin(q2)*sin(q3)*C.i + cos(q2)*C.j -118 sin(q2)*cos(q3)*C.k), A).simplify()119 assert A.k == express((-sin(q3)*cos(q2)*C.i + sin(q2)*C.j +120 cos(q2)*cos(q3)*C.k), A).simplify()121 assert B.i == express((cos(q1)*N.i + sin(q1)*N.j), B).simplify()122 assert B.j == express((-sin(q1)*cos(q2)*N.i +123 cos(q1)*cos(q2)*N.j + sin(q2)*N.k), B).simplify()124 assert B.k == express((sin(q1)*sin(q2)*N.i -125 sin(q2)*cos(q1)*N.j + cos(q2)*N.k), B).simplify()126 assert B.j == express((cos(q2)*A.j + sin(q2)*A.k), B).simplify()127 assert B.k == express((-sin(q2)*A.j + cos(q2)*A.k), B).simplify()128 assert B.i == express((cos(q3)*C.i + sin(q3)*C.k), B).simplify()129 assert B.k == express((-sin(q3)*C.i + cos(q3)*C.k), B).simplify()130 assert C.i == express((cos(q3)*A.i + sin(q2)*sin(q3)*A.j -131 sin(q3)*cos(q2)*A.k), C).simplify()132 assert C.j == express((cos(q2)*A.j + sin(q2)*A.k), C).simplify()133 assert C.k == express((sin(q3)*A.i - sin(q2)*cos(q3)*A.j +134 cos(q2)*cos(q3)*A.k), C).simplify()135 assert C.i == express((cos(q3)*B.i - sin(q3)*B.k), C).simplify()136 assert C.k == express((sin(q3)*B.i + cos(q3)*B.k), C).simplify()137def test_matrix_to_vector():138 m = Matrix([[1], [2], [3]])139 assert matrix_to_vector(m, C) == C.i + 2*C.j + 3*C.k140 m = Matrix([[0], [0], [0]])141 assert matrix_to_vector(m, N) == matrix_to_vector(m, C) == \142 Vector.zero143 m = Matrix([[q1], [q2], [q3]])144 assert matrix_to_vector(m, N) == q1*N.i + q2*N.j + q3*N.k145def test_orthogonalize():146 C = CoordSys3D('C')147 a, b = symbols('a b', integer=True)148 i, j, k = C.base_vectors()149 v1 = i + 2*j150 v2 = 2*i + 3*j151 v3 = 3*i + 5*j152 v4 = 3*i + j153 v5 = 2*i + 2*j154 v6 = a*i + b*j155 v7 = 4*a*i + 4*b*j156 assert orthogonalize(v1, v2) == [C.i + 2*C.j, C.i*Rational(2, 5) + -C.j/5]157 # from wikipedia158 assert orthogonalize(v4, v5, orthonormal=True) == \159 [(3*sqrt(10))*C.i/10 + (sqrt(10))*C.j/10, (-sqrt(10))*C.i/10 + (3*sqrt(10))*C.j/10]160 raises(ValueError, lambda: orthogonalize(v1, v2, v3))...

Full Screen

Full Screen

test_vector.py

Source:test_vector.py Github

copy

Full Screen

1from sympy import symbols, pi, sin, cos, ImmutableMatrix as Matrix2from sympy.physics.vector import ReferenceFrame, Vector, dynamicsymbols, dot3from sympy.abc import x, y, z4from sympy.testing.pytest import raises5Vector.simp = True6A = ReferenceFrame('A')7def test_Vector():8 assert A.x != A.y9 assert A.y != A.z10 assert A.z != A.x11 assert A.x + 0 == A.x12 v1 = x*A.x + y*A.y + z*A.z13 v2 = x**2*A.x + y**2*A.y + z**2*A.z14 v3 = v1 + v215 v4 = v1 - v216 assert isinstance(v1, Vector)17 assert dot(v1, A.x) == x18 assert dot(v1, A.y) == y19 assert dot(v1, A.z) == z20 assert isinstance(v2, Vector)21 assert dot(v2, A.x) == x**222 assert dot(v2, A.y) == y**223 assert dot(v2, A.z) == z**224 assert isinstance(v3, Vector)25 # We probably shouldn't be using simplify in dot...26 assert dot(v3, A.x) == x**2 + x27 assert dot(v3, A.y) == y**2 + y28 assert dot(v3, A.z) == z**2 + z29 assert isinstance(v4, Vector)30 # We probably shouldn't be using simplify in dot...31 assert dot(v4, A.x) == x - x**232 assert dot(v4, A.y) == y - y**233 assert dot(v4, A.z) == z - z**234 assert v1.to_matrix(A) == Matrix([[x], [y], [z]])35 q = symbols('q')36 B = A.orientnew('B', 'Axis', (q, A.x))37 assert v1.to_matrix(B) == Matrix([[x],38 [ y * cos(q) + z * sin(q)],39 [-y * sin(q) + z * cos(q)]])40 #Test the separate method41 B = ReferenceFrame('B')42 v5 = x*A.x + y*A.y + z*B.z43 assert Vector(0).separate() == {}44 assert v1.separate() == {A: v1}45 assert v5.separate() == {A: x*A.x + y*A.y, B: z*B.z}46 #Test the free_symbols property47 v6 = x*A.x + y*A.y + z*A.z48 assert v6.free_symbols(A) == {x,y,z}49 raises(TypeError, lambda: v3.applyfunc(v1))50def test_Vector_diffs():51 q1, q2, q3, q4 = dynamicsymbols('q1 q2 q3 q4')52 q1d, q2d, q3d, q4d = dynamicsymbols('q1 q2 q3 q4', 1)53 q1dd, q2dd, q3dd, q4dd = dynamicsymbols('q1 q2 q3 q4', 2)54 N = ReferenceFrame('N')55 A = N.orientnew('A', 'Axis', [q3, N.z])56 B = A.orientnew('B', 'Axis', [q2, A.x])57 v1 = q2 * A.x + q3 * N.y58 v2 = q3 * B.x + v159 v3 = v1.dt(B)60 v4 = v2.dt(B)61 v5 = q1*A.x + q2*A.y + q3*A.z62 assert v1.dt(N) == q2d * A.x + q2 * q3d * A.y + q3d * N.y63 assert v1.dt(A) == q2d * A.x + q3 * q3d * N.x + q3d * N.y64 assert v1.dt(B) == (q2d * A.x + q3 * q3d * N.x + q3d *\65 N.y - q3 * cos(q3) * q2d * N.z)66 assert v2.dt(N) == (q2d * A.x + (q2 + q3) * q3d * A.y + q3d * B.x + q3d *67 N.y)68 assert v2.dt(A) == q2d * A.x + q3d * B.x + q3 * q3d * N.x + q3d * N.y69 assert v2.dt(B) == (q2d * A.x + q3d * B.x + q3 * q3d * N.x + q3d * N.y -70 q3 * cos(q3) * q2d * N.z)71 assert v3.dt(N) == (q2dd * A.x + q2d * q3d * A.y + (q3d**2 + q3 * q3dd) *72 N.x + q3dd * N.y + (q3 * sin(q3) * q2d * q3d -73 cos(q3) * q2d * q3d - q3 * cos(q3) * q2dd) * N.z)74 assert v3.dt(A) == (q2dd * A.x + (2 * q3d**2 + q3 * q3dd) * N.x + (q3dd -75 q3 * q3d**2) * N.y + (q3 * sin(q3) * q2d * q3d -76 cos(q3) * q2d * q3d - q3 * cos(q3) * q2dd) * N.z)77 assert v3.dt(B) == (q2dd * A.x - q3 * cos(q3) * q2d**2 * A.y + (2 *78 q3d**2 + q3 * q3dd) * N.x + (q3dd - q3 * q3d**2) *79 N.y + (2 * q3 * sin(q3) * q2d * q3d - 2 * cos(q3) *80 q2d * q3d - q3 * cos(q3) * q2dd) * N.z)81 assert v4.dt(N) == (q2dd * A.x + q3d * (q2d + q3d) * A.y + q3dd * B.x +82 (q3d**2 + q3 * q3dd) * N.x + q3dd * N.y + (q3 *83 sin(q3) * q2d * q3d - cos(q3) * q2d * q3d - q3 *84 cos(q3) * q2dd) * N.z)85 assert v4.dt(A) == (q2dd * A.x + q3dd * B.x + (2 * q3d**2 + q3 * q3dd) *86 N.x + (q3dd - q3 * q3d**2) * N.y + (q3 * sin(q3) *87 q2d * q3d - cos(q3) * q2d * q3d - q3 * cos(q3) *88 q2dd) * N.z)89 assert v4.dt(B) == (q2dd * A.x - q3 * cos(q3) * q2d**2 * A.y + q3dd * B.x +90 (2 * q3d**2 + q3 * q3dd) * N.x + (q3dd - q3 * q3d**2) *91 N.y + (2 * q3 * sin(q3) * q2d * q3d - 2 * cos(q3) *92 q2d * q3d - q3 * cos(q3) * q2dd) * N.z)93 assert v5.dt(B) == q1d*A.x + (q3*q2d + q2d)*A.y + (-q2*q2d + q3d)*A.z94 assert v5.dt(A) == q1d*A.x + q2d*A.y + q3d*A.z95 assert v5.dt(N) == (-q2*q3d + q1d)*A.x + (q1*q3d + q2d)*A.y + q3d*A.z96 assert v3.diff(q1d, N) == 097 assert v3.diff(q2d, N) == A.x - q3 * cos(q3) * N.z98 assert v3.diff(q3d, N) == q3 * N.x + N.y99 assert v3.diff(q1d, A) == 0100 assert v3.diff(q2d, A) == A.x - q3 * cos(q3) * N.z101 assert v3.diff(q3d, A) == q3 * N.x + N.y102 assert v3.diff(q1d, B) == 0103 assert v3.diff(q2d, B) == A.x - q3 * cos(q3) * N.z104 assert v3.diff(q3d, B) == q3 * N.x + N.y105 assert v4.diff(q1d, N) == 0106 assert v4.diff(q2d, N) == A.x - q3 * cos(q3) * N.z107 assert v4.diff(q3d, N) == B.x + q3 * N.x + N.y108 assert v4.diff(q1d, A) == 0109 assert v4.diff(q2d, A) == A.x - q3 * cos(q3) * N.z110 assert v4.diff(q3d, A) == B.x + q3 * N.x + N.y111 assert v4.diff(q1d, B) == 0112 assert v4.diff(q2d, B) == A.x - q3 * cos(q3) * N.z113 assert v4.diff(q3d, B) == B.x + q3 * N.x + N.y114def test_vector_var_in_dcm():115 N = ReferenceFrame('N')116 A = ReferenceFrame('A')117 B = ReferenceFrame('B')118 u1, u2, u3, u4 = dynamicsymbols('u1 u2 u3 u4')119 v = u1 * u2 * A.x + u3 * N.y + u4**2 * N.z120 assert v.diff(u1, N, var_in_dcm=False) == u2 * A.x121 assert v.diff(u1, A, var_in_dcm=False) == u2 * A.x122 assert v.diff(u3, N, var_in_dcm=False) == N.y123 assert v.diff(u3, A, var_in_dcm=False) == N.y124 assert v.diff(u3, B, var_in_dcm=False) == N.y125 assert v.diff(u4, N, var_in_dcm=False) == 2 * u4 * N.z126 raises(ValueError, lambda: v.diff(u1, N))127def test_vector_simplify():128 x, y, z, k, n, m, w, f, s, A = symbols('x, y, z, k, n, m, w, f, s, A')129 N = ReferenceFrame('N')130 test1 = (1 / x + 1 / y) * N.x131 assert (test1 & N.x) != (x + y) / (x * y)132 test1 = test1.simplify()133 assert (test1 & N.x) == (x + y) / (x * y)134 test2 = (A**2 * s**4 / (4 * pi * k * m**3)) * N.x135 test2 = test2.simplify()136 assert (test2 & N.x) == (A**2 * s**4 / (4 * pi * k * m**3))137 test3 = ((4 + 4 * x - 2 * (2 + 2 * x)) / (2 + 2 * x)) * N.x138 test3 = test3.simplify()139 assert (test3 & N.x) == 0140 test4 = ((-4 * x * y**2 - 2 * y**3 - 2 * x**2 * y) / (x + y)**2) * N.x141 test4 = test4.simplify()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful