def Symmetrize_from_lower_triangle_unb_var1(A):
    """
	Symmetrize_from_lower_triangle_unb_var1(matrix)	
	
	Makes square matrix A symmetric by copying the
	lower triangular part in its upper triangular part.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.copy(a01,a10t)

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Exemplo n.º 2
0
def Symmetrize_from_lower_triangle_unb_var1(A):
    """
	Symmetrize_from_lower_triangle_unb_var1(matrix)	
	
	Makes square matrix A symmetric by copying the
	lower triangular part in its upper triangular part.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.copy(a01, a10t)

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Exemplo n.º 3
0
def Set_to_diagonal_matrix_unb_var2(d, A):
    """
	Set_to_diagonal_matrix_unb_var2(vector, matrix)	
	
	Sets the diagonal elements of A to the components of vector d.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	traverses vector d from TOP to BOTTOM 
	and sets results row-wise.
    """
    
    dT, \
    dB  = flame.part_2x1(d, \
                         0, 'TOP')

    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while dT.shape[0] < d.shape[0]:

        d0,     \
        delta1, \
        d2      = flame.repart_2x1_to_3x1(dT, \
                                          dB, \
                                          1, 'BOTTOM')

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.zerov(a10t)
        laff.copy(delta1, alpha11)
        laff.zerov(a12t)

        dT, \
        dB  = flame.cont_with_3x1_to_2x1(d0,     \
                                         delta1, \
                                         d2,     \
                                         'TOP')

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x1(dT, \
                    dB, d)

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Exemplo n.º 4
0
def norm2( x ):

	"""
    Compute the 2-norm of a vector, returning alpha
    
    x can be a row or column vector.
    """
	assert type(x) is np.matrix and len(x.shape) is 2, \
		"laff.norm2: vector x must be a 2D numpy.matrix"
	
	m, n = np.shape(x)
	assert m is 1 or n is 1, \
		"laff.norm2: x is not a vector"

	#Ensure that we don't modify x in 
	#any way by copying it to a new vector, y
	y = np.matrix( np.zeros( (m,n) ) )
	laff.copy( x, y )
	
	#Initialize variables that we will use to appropriate values
	alpha = 0
	maxval = y[ 0, 0 ]
	
	if m is 1: #y is a row
		#Find a value to scale by to avoid under/overflow
		for i in range(n):
			if abs(y[ 0, i ]) > maxval:
				maxval = abs(y[ 0, i ])
		
	elif n is 1: #y is a column
		#Find a value to scale by to avoid under/overflow
		for i in range(m):
			if abs(y[ i, 0 ]) > maxval:
				maxval = abs(y[ i, 0 ])
	
	#If y is the zero vector, return 0
	if abs(maxval) < 1e-7:
		return 0
		
	#Scale all of the values by 1/maxval to prevent under/overflow
	laff.scal( 1.0/maxval, y )
	
	alpha = maxval * sqrt( laff.dot( y, y ) )
	
	return alpha
Exemplo n.º 5
0
def norm2( x ):

	"""
    Compute the 2-norm of a vector, returning alpha
    
    x can be a row or column vector.
    """
	assert type(x) is np.matrix and len(x.shape) is 2, \
		"laff.norm2: vector x must be a 2D numpy.matrix"
	
	m, n = np.shape(x)
	assert m is 1 or n is 1, \
		"laff.norm2: x is not a vector"

	#Ensure that we don't modify x in 
	#any way by copying it to a new vector, y
	y = np.matrix( np.zeros( (m,n) ) )
	laff.copy( x, y )
	
	#Initialize variables that we will use to appropriate values
	alpha = 0
	maxval = y[ 0, 0 ]
	
	if m is 1: #y is a row
		#Find a value to scale by to avoid under/overflow
		for i in range(n):
			if abs(y[ 0, i ]) > maxval:
				maxval = y[ 0, i ]
		
	elif n is 1: #y is a column
		#Find a value to scale by to avoid under/overflow
		for i in range(m):
			if abs(y[ i, 0 ]) > maxval:
				maxval = y[ i, 0 ]
	
	#If y is the zero vector, return 0
	if maxval is 0:
		return 0
		
	#Scale all of the values by 1/maxval to prevent under/overflow
	laff.scal( 1.0/maxval, y )
	
	alpha = maxval * sqrt( laff.dot( y, y ) )
	
	return alpha
Exemplo n.º 6
0
def Transpose_unb_var1(A, B):
    """
	Transpose_unb_var1(matrix, matrix)	
	
	Transposes matrix A and stores result in matrix B.

	Traverses matrix A from LEFT to RIGHT,
	matrix B from TOP to BOTTOM,
	and copies columns of A to rows of B.
    """
    AL, AR = flame.part_1x2(A, \
                            0, 'LEFT')

    BT, \
    BB  = flame.part_2x1(B, \
                         0, 'TOP')

    while AL.shape[1] < A.shape[1]:

        A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \
                                             1, 'RIGHT')

        B0,  \
        b1t, \
        B2   = flame.repart_2x1_to_3x1(BT, \
                                       BB, \
                                       1, 'BOTTOM')

        laff.copy( a1, b1t )

        AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \
                                            'LEFT')

        BT, \
        BB  = flame.cont_with_3x1_to_2x1(B0,  \
                                         b1t, \
                                         B2,  \
                                         'TOP')

    flame.merge_2x1(BT, \
                    BB, B)
Exemplo n.º 7
0
def Transpose_unb_var2(A, B):
    """
	Transpose_unb_var1(matrix, matrix)	
	
	Transposes matrix A and stores result in matrix B.

	Traverses matrix A from TOP to BOTTOM,
	matrix B from LEFT to RIGHT,
	and copies rows of A to columns of B.
    """
    AT, \
    AB  = flame.part_2x1(A, \
                         0, 'TOP')

    BL, BR = flame.part_1x2(B, \
                            0, 'LEFT')

    while AT.shape[0] < A.shape[0]:

        A0,  \
        a1t, \
        A2   = flame.repart_2x1_to_3x1(AT, \
                                       AB, \
                                       1, 'BOTTOM')

        B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, \
                                             1, 'RIGHT')

        laff.copy( a1t, b1 )
        
        AT, \
        AB  = flame.cont_with_3x1_to_2x1(A0,  \
                                         a1t, \
                                         A2,  \
                                         'TOP')

        BL, BR = flame.cont_with_1x3_to_1x2(B0, b1, B2, \
                                            'LEFT')

    flame.merge_1x2(BL, BR, B)
Exemplo n.º 8
0
def norm2(x):
    """



    """
    assert type(x) is np.matrix and len(
        x.shape) is 2, "laff.norm2: vector x must be a 2D numpy.matrix"

    m, n = np.shape(x)

    assert m is 1 or n is 1, "laff.norm2: x is not a vector"

    y = np.matrix(np.zeros((m, n)))
    laff.copy(x, y)

    alpha = 0
    maxval = y[0, 0]

    if m is 1:  #y is a row
        for i in range(n):
            if abs(y[0, i]) > maxval:
                maxval = abs(y[0, i])

    elif n is 1:  #y is a column
        for i in range(m):
            if abs(y[i, 0]) > maxval:
                maxval = abs(y[i, 0])

    if abs(maxval) < 1e-7:
        return 0

    laff.scal(1.0 / maxval, y)

    alpha = maxval * sqrt(laff.dot(y, y))

    return alpha
Exemplo n.º 9
0
def norm2( x ):
    """



    """
    assert type(x) is np.matrix and len(x.shape) is 2, "laff.norm2: vector x must be a 2D numpy.matrix"
	
    m, n = np.shape(x)
	
    assert m is 1 or n is 1, "laff.norm2: x is not a vector"

    y = np.matrix( np.zeros( (m,n) ) )
    laff.copy( x, y )
	
    alpha = 0
    maxval = y[ 0, 0 ]

    if m is 1: #y is a row
	for i in range(n):
	    if abs(y[ 0, i ]) > maxval:
		maxval = abs(y[ 0, i ])
		
    elif n is 1: #y is a column
	for i in range(m):
	    if abs(y[ i, 0 ]) > maxval:
		maxval = abs(y[ i, 0 ])

    if abs(maxval) < 1e-7:
	return 0

    laff.scal( 1.0/maxval, y )
	
    alpha = maxval * sqrt( laff.dot( y, y ) )
	
    return alpha