Exemplo n.º 1
0
 def test_input_unchanged(self):
     m1 = [[6, 6], [3, 1]]
     m2 = [[1, 2], [3, 4]]
     m1_original = deepcopy(m1)
     m2_original = deepcopy(m2)
     add(m1, m2)
     self.assertEqual(m1, m1_original)
     self.assertEqual(m2, m2_original)
Exemplo n.º 2
0
 def test_any_number_of_matrixes(self):
     m1 = [[6, 6], [3, 1]]
     m2 = [[1, 2], [3, 4]]
     m3 = [[2, 1], [3, 4]]
     m4 = [[9, 9], [9, 9]]
     m5 = [[31, 32], [27, 24]]
     self.assertEqual(add(m1, m2, m3), m4)
     self.assertEqual(add(m2, m3, m1, m1, m2, m4, m1), m5)
Exemplo n.º 3
0
 def placeWall(self, coord, direction):
     if self.stock >= 0:
         self.stock -= 1
         newWall = Wall(coord, direction)
         newWallCoord = add(coord, direction)
         wallTuple = (coord, newWallCoord)
         self.board.wallList.append(wallTuple)
Exemplo n.º 4
0
def bilin(p,om):
	import numpy as np
	#This function transforms the stable bandpass  filter obtained
    #from the Chebyschev approximation to the equivalent bandpass
    #digital filter using the bilinear transformation
    #[dignum,digden,G_bp] = bilin(p,om)
    #H_bp(s) = G_bp*num(s)/den(s) is the analog bandpass filter
    #obtained through the Chebyschev filter design
    #H(z) = G*dignum(z)/digden(z) is digital bandpass filter
    #obtained from H_bp(s) by substituting s = (z-1)/(z+1)
    #G is obtained from the condition H(om) = 1
	
	N = len(p)
	const = np.array([-1,1])
	const = const.flatten()
	v = 1
	if N > 2:
		for i in range(N-1):
			v = np.convolve(const,v)
			v = add(v,p[i+1]*polypower([1,1],i+1))
		digden  = v
	elif N == 2:
		M = len(v)
		v[M-2] = v[M-2] + p[N-1]
		v[M-1] = v[M-1] + p[N-1]
		digden = v
	else:
		digden = p
	dignum = polypower([-1,0,1],int((N-1)/2))
	G_bp = abs(np.polyval(digden,np.exp(-1j*om))/np.polyval(dignum,np.exp(-1j*om)))
	
	return dignum,digden,G_bp
Exemplo n.º 5
0
def omega(p, q, i):
    root = tk.Tk()
    root.title("Welcome Page")
    root.geometry("400x400")
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    v5 = tk.StringVar()
    v6 = tk.StringVar()
    v6.set(i)
    v2.set(str(p))
    v5.set(str(q))
    tk.Label(root, text="Welcome", fg="red", bg="yellow").grid(row=0, column=0)
    tk.Label(root, text="name", fg="red", bg="yellow",
             textvariable=v2).grid(row=0, column=1)
    tk.Label(root, text="Your ID", fg="red", bg="yellow").grid(row=1, column=0)
    tk.Label(root, text=i, fg="red", bg="yellow").grid(row=1, column=1)
    tk.Label(root, text="Balance:", fg="red", bg="yellow").grid(row=2,
                                                                column=0)
    tk.Label(root, text=q, fg="red", bg="yellow").grid(row=2, column=1)

    tk.Button(root, text="Add Money", command=lambda: add(root)).grid(row=4,
                                                                      column=2)
    tk.Button(root, text="Pay", command=lambda: pay(root)).grid(row=5,
                                                                column=2)
    tk.Button(root, text="Recharge",
              command=lambda: recharge(root)).grid(row=6, column=2)
    tk.Button(root, text="Movie Ticket",
              command=lambda: ticket(root)).grid(row=7, column=2)
    tk.Button(root, text="Electric Bill",
              command=lambda: bill(root)).grid(row=8, column=2)
    tk.Button(root, text="History",
              command=lambda: history(root)).grid(row=9, column=2)
    tk.Button(root, text="Logout", command=lambda: logout(root)).grid(row=10,
                                                                      column=2)
Exemplo n.º 6
0
Arquivo: subtr.py Projeto: psorus/f
 def __init__(s, *q):
     param2.__init__(s)
     if len(q) > 2:
         s.q1, s.q2 = q[0], add(*q[1:])
     elif len(q) < 2:
         raise InvalidInitializerException(s, q)
     else:
         s.q1, s.q2 = q
Exemplo n.º 7
0
 def diff(s, by) -> "add":
     rel = []
     for i, ac in enumerate(s.q):
         zw = [ac.diff(by)]
         for j, ac2 in enumerate(s.q):
             if j == i: continue
             zw.append(ac2.copy())
         rel.append(mult(*zw))
     return add(*rel)
Exemplo n.º 8
0
 def test_different_matrix_size(self):
     m1 = [[6, 6], [3, 1]]
     m2 = [[1, 2], [3, 4], [5, 6]]
     m3 = [[6, 6], [3, 1, 2]]
     with self.assertRaises(ValueError):
         add(m1, m2)
     with self.assertRaises(ValueError):
         add(m1, m3)
     with self.assertRaises(ValueError):
         add(m1, m1, m1, m3, m1, m1)
     with self.assertRaises(ValueError):
         add(m1, m1, m1, m2, m1, m1)
Exemplo n.º 9
0
def ppe(n, l, s):

	# Number of trials t
	t = (n+2)*s
	
	# Resources to add up all the numbers to get q
	add_res = add(m=t, n=n)
	
	# Resources to apply A^q
	shift_res = dkrs_add(n=n)
	
	resources = combine_resources(add_res, shift_res)
	
	# Add the two levels of Hadamards
	resources['depth'] += 2
	resources['single'] += (2*n)
	
	return resources
Exemplo n.º 10
0
def bilin(p,om):
    N = len(p)
    const = np.array([1,-1])
    v = np.array([1])
    if N > 2:
        
        for i in range(1,N):
            v = np.convolve(v,const)
            v = add(v,p[i]*polypower(np.array([1,1]),i))

        digden = v
    elif N==2:
        M = len(v)
        v[M-2] = v[M-2] + p[N-1]
        v[M-1] = v[M-1] + p[N-1]
        digden = v        
    else:
        digden = p
    dignum = polypower(np.array([-1,0,1]),int((N-1)/2))
    G_bp = abs(np.polyval(digden,np.exp(-1j*om))/np.polyval(dignum,np.exp(-1j*om)))
    return dignum,digden,G_bp
Exemplo n.º 11
0
def bilin(p, om):
    '''This function transforms the stable bandpass  filter obtained
    from the Chebyschev approximation to the equivalent bandpass
    digital filter using the bilinear transformation
    [dignum,digden,G_bp] = bilin(p,om)
    H_bp(s) = G_bp*num(s)/den(s) is the analog bandpass filter
    obtained through the Chebyschev filter design
    H(z) = G*dignum(z)/digden(z) is digital bandpass filter
    obtained from H_bp(s) by substituting s = (z-1)/(z+1)
    G is obtained from the condition H(om) = 1'''

    N = len(p)
    const = np.array([1, -1])
    v = np.array([1])
    if N > 2:

        for i in range(1, N):
            v = np.convolve(v, const)
            v = add(v, p[i] * polypower(np.array([1, 1]), i))

        digden = v

    elif N == 2:
        M = len(v)
        v[M - 2] = v[M - 2] + p[N - 1]
        v[M - 1] = v[M - 1] + p[N - 1]
        digden = v

    else:
        digden = p

    #alpha = polypower([1 1],(N-1)/2);
    #beta = polypower([-1 1],(N+1)/2);
    #dignum = conv(alpha,beta);
    dignum = polypower(np.array([-1, 0, 1]), int((N - 1) / 2))

    G_bp = abs(
        np.polyval(digden, np.exp(-1j * om)) /
        np.polyval(dignum, np.exp(-1j * om)))
    return dignum, digden, G_bp
Exemplo n.º 12
0
def cphase(n, L_prime):

	# Start with a clean slate
	resources = create_empty_resources()
	
	# Create the initial \ket{\psi_{n,1}}
	rps_res = rps(n=n)
	
	# Copy to create m \ket{\psi_{n,1}} via addition
	add_res = add(m = L_prime, n = n)
	
	resources = combine_resources(rps_res, add_res)
	
	# Add n Hadamards for creating \ket{\psi_{n,0}}
	resources['single'] += n
	resources['depth'] += 1

	# Add negations for L_prime * n addends, and then for the  n-bit result
	resources['single'] += ((L_prime*n) + n)
	resources['depth'] += 2
	
	# We need to load the values of l for each cphase gate w/ NOT gates
	resources['single'] += (L_prime * n)
	resources['depth'] += 1
	
	# We also need to simulate the cphase gates by adding the l values with DKRS
	# These can be done in parallel
	add_res = dkrs_add(n = n)
	#print "before multiply: " + str(add_res)

	add_res = multiply_resources_with_ancillae(add_res, L_prime)
	#print str(add_res)
	
	resources = combine_resources(resources, add_res)
	
	return resources
Exemplo n.º 13
0
def test_add():
    result = add(1, 2)
    assert result == 3,'results are wrong!!!' 
Exemplo n.º 14
0
 def test_add_integers(self):
     """Check that ``add`` task can add integers."""
     self.assertEqual(add(1, 2), 3)
Exemplo n.º 15
0
 def test_two_by_two_matrixes(self):
     m1 = [[6, 6], [3, 1]]
     m2 = [[1, 2], [3, 4]]
     m3 = [[7, 8], [6, 5]]
     self.assertEqual(add(m1, m2), m3)
Exemplo n.º 16
0
def addList(inlist,sysargs):
    print inlist
    print sysargs
    
    add(inlist[0],inlist[1],sysargs)
Exemplo n.º 17
0
 def add_1_1_should_be_2_test(self):
     self.assertEqual( add(1,1), 2)
Exemplo n.º 18
0
Arquivo: aa.py Projeto: X-H-W/xhw
import add
add()
Exemplo n.º 19
0
 def testAdd(self):
     self.assertEqual(add(1,3), add(3,1))
Exemplo n.º 20
0
 def pawnTo(self, direction) :
     """
     Returns "True" if the PlayerCell in the selected direction has a pawn on it.
     """
     dirCoord = add(self.coord, direction)
     return self.board.playerCellList[dirCoord[0]][dirCoord[1]].hasPawn
Exemplo n.º 21
0
print(add.add())
print(add.sub())
print(add.add() * add.sub())

# Module Aliasing

import add as a
print(a.add())

print()
# only specific function from the modules
from add import sub
print(sub())

from add import add
print(add())

print()
import add as a
print(a.add())
print(a.sub())

from add import *  # * --> all members present in add modules
print(add())
print(
    sub())  # dont want to give a.add() or add.add() just add() alone is enough

import add
#print(dir()) # dir() --> discreption about the modules and what are the functions are available
print(dir(add))
print('Program:', __name__)
Exemplo n.º 22
0
 def fire1(self):
     add()
Exemplo n.º 23
0
    def move(self, direction) :
        """
        The move method test if there is a pawn in the desired direction.
        If there is no pawn, it does a normal move if possible.
        If there is one, it makes (if possible) an automatic move to a legal position, diagonally, with a priority to the right of the pawn.
        """
        y, x = self.dependency.coord 
        if direction is not None:
            if canMove(self, direction): #checks if there is no wall between the pawn and the next cell
                nextCoord = add(self.dependency.coord, direction) #coordinates of forward cell to move, used to check canMove and make a move if there is no pawn

                if self.board.playerCellList[y][x].pawnTo(direction):

                    if canMove(self, direction, nextCoord): #checks if the played pawn can bypass the other pawn
                        superMoveCoord = add(nextCoord, direction) #coorinates of cell after the pawn, used to make a "super" move one more cell than normal
                        self.dependency.coord = superMoveCoord

                    else: #checks if the played pawn can otherwise move to a diagonal direction (through the other pawn cell), one direction at a time
                        if direction is self.board.UP :
                            if canMove(self, self.board.RIGHT, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.RIGHT)
                            elif canMove(self, self.board.LEFT, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.LEFT)

                        elif direction is self.board.RIGHT :
                            if canMove(self, self.board.UP, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.DOWN)
                            elif canMove(self, self.board.DOWN, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.UP)

                        elif direction is self.board.DOWN :
                            if canMove(self, self.board.LEFT, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.LEFT)
                            elif canMove(self, self.board.RIGHT, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.RIGHT)

                        elif direction is self.board.LEFT :
                            if canMove(self, self.board.UP, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.UP)
                            elif canMove(self, self.board.DOWN, nextCoord):
                                self.dependency.coord = add(self.dependency.coord, direction)
                                self.dependency.coord = add(self.dependency.coord, self.board.DOWN)
                    
                else: #if there is no pawn, just make a normal move ;3
                    self.dependency.coord = nextCoord
Exemplo n.º 24
0
from add import *

res = add(6, 5)
print("res :", res)

print("sub :", sub(5, 2))

print("div :", div(6, 3))

print("mul :", mul(2, 8))
Exemplo n.º 25
0
 def testAdd(self):
     self.assertEqual(add(1, 3), add(3, 1))
Exemplo n.º 26
0
	
		while not x.isdigit() and x!="exit":
			x=input("Input 1st operand: ")
		if x=="exit":
			break
		while "+-/*".find(math_do)==-1:
			math_do=input("Input math operation: ")
			if math_do =="":
				math_do="-1"
		if math_do=="exit":
			break	
		while not y.isdigit() and y!="exit":
			y=input("Input 2st operand: ")
		if y=="exit":
			break
	
		if math_do=="*":
			multiply(x,y)
		elif math_do=="+":
			add(x,y)
		elif math_do=="/":
			divide(x,y)
		elif math_do=="-":
			substraction (x,y)
		else:
			print("Something wrong")

		print ("")
		math_do="-1"
		x=y=""
		ch_exit=""
Exemplo n.º 27
0
 def test_add_strings(self):
     """Check that ``add`` task can add strings."""
     self.assertEqual(add('foo ', 'bar'), 'foo bar')
Exemplo n.º 28
0
 def test_two_by_three_matrixes(self):
     m1 = [[1, 2, 3], [4, 5, 6]]
     m2 = [[-1, -2, -3], [-4, -5, -6]]
     m3 = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(add(m1, m2), m3)
Exemplo n.º 29
0
import ompc
addpath('mfiles')
import add
print add(1,2)
Exemplo n.º 30
0
def mult2(n):
	resources = create_empty_resources()
	resources['ancilla'] = n*(n-1)/2
	add_res = add(m=n, n=n)
	resources = combine_resources(add_res, resources)
	return resources
Exemplo n.º 31
0
    last = args[-1]
    if last.lower() in ['-begin', '-end', '-frozen']:
        args = args[:-1]
        if last.lower() == '-begin':
            pos = 0
        elif sys.platform.startswith('win') and last.lower() == '-frozen':
            raise NotImplementedError()
    if pos is None:
        sys.path += list(args)
    else:
        sys.path.insetr(pos, list(args))


def install():
    """Install the import hook"""
    ihooks.install(ihooks.ModuleImporter(MFileLoader(MFileHooks())))


install()

# don't export anything
__all__ = ['addpath']

if __name__ == "__main__":
    addpath('mfiles')
    import add
    print add(1, 2)

    print add
    help(add)
Exemplo n.º 32
0
 def test_single_items(self):
     self.assertEqual(add([[5]], [[-2]]), [[3]])
Exemplo n.º 33
0
from add import *

n=32

print "**** Encoded Add ***"

for i in range(1,10):
	resources = encoded_add(m=i, n=n)
	print "m= " + str(i)
	print "resources= " + str(resources)

print "**** DKRS Add ***"

for i in range(6,16):
	resources = dkrs_add(n=i)
	print "n= " + str(i)
	print "resources= " + str(resources)

print "**** Combined Add ***"

for i in range(6,16):
	resources = add(m=i, n=n)
	print "n= " + str(i)
	print "resources= " + str(resources)
Exemplo n.º 34
0
 def test_add_floats(self):
     """Check that ``add`` task can add floats."""
     self.assertEqual(add(1.2, 3.4), 4.6)
Exemplo n.º 35
0
def test_add():
    assert add(2, 2) == 4
    assert add(-2, 1) == 0
    assert add(-1, -1) == 0
Exemplo n.º 36
0
 def test_add_lists(self):
     """Check that ``add`` task can add lists."""
     self.assertEqual(add([1, 2], [3, 4]), [1, 2, 3, 4])
Exemplo n.º 37
0
def test_add(self):
    self.assertEqual(add(2,3), 5, msg="The result is not equal to 5.")