def test_eig_dyn(): v = 0 for i in xrange(5): n = 1 + int(mp.rand() * 5) if mp.rand() > 0.5: # real A = 2 * mp.randmatrix(n, n) - 1 if mp.rand() > 0.5: A *= 10 for x in xrange(n): for y in xrange(n): A[x, y] = int(A[x, y]) else: A = (2 * mp.randmatrix(n, n) - 1) + 1j * (2 * mp.randmatrix(n, n) - 1) if mp.rand() > 0.5: A *= 10 for x in xrange(n): for y in xrange(n): A[x, y] = int(mp.re(A[x, y])) + 1j * int(mp.im(A[x, y])) run_hessenberg(A, verbose=v) run_schur(A, verbose=v) run_eig(A, verbose=v)
def test_svd_c_rand(): for i in xrange(5): full = mp.rand() > 0.5 m = 1 + int(mp.rand() * 10) n = 1 + int(mp.rand() * 10) A = (2 * mp.randmatrix(m, n) - 1) + 1j * (2 * mp.randmatrix(m, n) - 1) if mp.rand() > 0.5: A *= 10 for x in xrange(m): for y in xrange(n): A[x, y] = int(mp.re(A[x, y])) + 1j * int(mp.im(A[x, y])) run_svd_c(A, full_matrices=full, verbose=False)
def test_svd_c_rand(): for i in xrange(5): full = mp.rand() > 0.5 m = 1 + int(mp.rand() * 10) n = 1 + int(mp.rand() * 10) A = (2 * mp.randmatrix(m, n) - 1) + 1j * (2 * mp.randmatrix(m, n) - 1) if mp.rand() > 0.5: A *= 10 for x in xrange(m): for y in xrange(n): A[x,y]=int(mp.re(A[x,y])) + 1j * int(mp.im(A[x,y])) run_svd_c(A, full_matrices=full, verbose=False)
def test_svd_r_rand(): for i in xrange(5): full = mp.rand() > 0.5 m = 1 + int(mp.rand() * 10) n = 1 + int(mp.rand() * 10) A = 2 * mp.randmatrix(m, n) - 1 if mp.rand() > 0.5: A *= 10 for x in xrange(m): for y in xrange(n): A[x, y] = int(A[x, y]) run_svd_r(A, full_matrices=full, verbose=False)
def test_svd_r_rand(): for i in xrange(5): full = mp.rand() > 0.5 m = 1 + int(mp.rand() * 10) n = 1 + int(mp.rand() * 10) A = 2 * mp.randmatrix(m, n) - 1 if mp.rand() > 0.5: A *= 10 for x in xrange(m): for y in xrange(n): A[x,y]=int(A[x,y]) run_svd_r(A, full_matrices = full, verbose = False)
def irandmatrix(n, range=10): """ random matrix with integer entries """ A = mp.matrix(n, n) for i in xrange(n): for j in xrange(n): A[i, j] = int((2 * mp.rand() - 1) * range) return A
def irandmatrix(n, range = 10): """ random matrix with integer entries """ A = mp.matrix(n, n) for i in xrange(n): for j in xrange(n): A[i,j]=int( (2 * mp.rand() - 1) * range) return A
def test_eig_dyn(): v = 0 for i in xrange(5): n = 1 + int(mp.rand() * 5) if mp.rand() > 0.5: # real A = 2 * mp.randmatrix(n, n) - 1 if mp.rand() > 0.5: A *= 10 for x in xrange(n): for y in xrange(n): A[x,y] = int(A[x,y]) else: A = (2 * mp.randmatrix(n, n) - 1) + 1j * (2 * mp.randmatrix(n, n) - 1) if mp.rand() > 0.5: A *= 10 for x in xrange(n): for y in xrange(n): A[x,y] = int(mp.re(A[x,y])) + 1j * int(mp.im(A[x,y])) run_hessenberg(A, verbose = v) run_schur(A, verbose = v) run_eig(A, verbose = v)
v0 = 0 v1 = 2 duration = mp.mpf('5') vm = 2.5 am = 1.8 prevCurve = Interpolate1D(x0, x1, v0, v1, vm, am) fixedCurve = interpolation._Stretch1D(prevCurve, duration, vm, am) # Check if the interpolation preserves the displacement assert (ramp.IsEqual(prevCurve.d, 3)) assert (ramp.IsEqual(fixedCurve.d, 3)) # Check if the interpolation preserves the duration assert (ramp.IsEqual(fixedCurve.duration, duration)) x0 = 0 x1 = mp.rand() * 3 v0 = 0 v1 = mp.rand() * 2 duration = mp.mpf('5') vm = 2.5 am = 1.8 prevCurve = Interpolate1D(x0, x1, v0, v1, vm, am) fixedCurve = interpolation._Stretch1D(prevCurve, duration, vm, am) # Check if the interpolation preserves the displacement assert (ramp.IsEqual(prevCurve.d, mp.mpf(str(x1)))) assert (ramp.IsEqual(fixedCurve.d, mp.mpf(str(x1)))) # Check if the interpolation preserves the duration assert (ramp.IsEqual(fixedCurve.duration, duration)) nTrials = 0
import numpy as np import time as tmf import matplotlib.pyplot as plt #------------------------------------------------------------------------------ # mpmath: free (BSD licensed) Python library for real and complex floating-point # arithmetic with arbitrary precision. http://mpmath.org/ from mpmath import mp #------------------------------------------------------------------------------ dps = np.arange(10, 2000, 10) T = np.zeros(len(dps)) samples = 1000 for si in range(samples): for i in range(len(dps)): mp.dps = dps[i] number1, number2 = mp.rand(), mp.rand() t0 = tmf.clock() C = mp.sqrt(number1) * mp.sqrt(number2) T[i] += (tmf.clock() - t0) / samples plt.plot(dps, T)
v0 = 0 v1 = 2 duration = mp.mpf('5') vm = 2.5 am = 1.8 prevCurve = Interpolate1D(x0, x1, v0, v1, vm, am) fixedCurve = interpolation._Stretch1D(prevCurve, duration, vm, am) # Check if the interpolation preserves the displacement assert(ramp.IsEqual(prevCurve.d, 3)) assert(ramp.IsEqual(fixedCurve.d, 3)) # Check if the interpolation preserves the duration assert(ramp.IsEqual(fixedCurve.duration, duration)) x0 = 0 x1 = mp.rand()*3 v0 = 0 v1 = mp.rand()*2 duration = mp.mpf('5') vm = 2.5 am = 1.8 prevCurve = Interpolate1D(x0, x1, v0, v1, vm, am) fixedCurve = interpolation._Stretch1D(prevCurve, duration, vm, am) # Check if the interpolation preserves the displacement assert(ramp.IsEqual(prevCurve.d, mp.mpf(str(x1)))) assert(ramp.IsEqual(fixedCurve.d, mp.mpf(str(x1)))) # Check if the interpolation preserves the duration assert(ramp.IsEqual(fixedCurve.duration, duration)) nTrials = 0