Path: blob/master/sage/matrix/matrix_complex_double_dense.pyx
4057 views
"""1Dense matrices over the Complex Double Field using NumPy23EXAMPLES::45sage: b=Mat(CDF,2,3).basis()6sage: b[0]7[1.0 0.0 0.0]8[0.0 0.0 0.0]910We deal with the case of zero rows or zero columns::1112sage: m = MatrixSpace(CDF,0,3)13sage: m.zero_matrix()14[]1516TESTS::1718sage: a = matrix(CDF,2,[i+(4-i)*I for i in range(4)], sparse=False)19sage: TestSuite(a).run()20sage: Mat(CDF,0,0).zero_matrix().inverse()21[]2223AUTHORS:2425- Jason Grout (2008-09): switch to NumPy backend2627- Josh Kantor2829- William Stein: many bug fixes and touch ups.30"""3132##############################################################################33# Copyright (C) 2004,2005,2006 Joshua Kantor <[email protected]>34# Distributed under the terms of the GNU General Public License (GPL)35# The full text of the GPL is available at:36# http://www.gnu.org/licenses/37##############################################################################3839import matrix_double_dense4041from sage.rings.complex_double import CDF4243cimport numpy as cnumpy4445numpy=None4647cdef class Matrix_complex_double_dense(matrix_double_dense.Matrix_double_dense):48"""49Class that implements matrices over the real double field. These50are supposed to be fast matrix operations using C doubles. Most51operations are implemented using numpy which will call the52underlying BLAS on the system.5354EXAMPLES::5556sage: m = Matrix(CDF, [[1,2*I],[3+I,4]])57sage: m**258[-1.0 + 6.0*I 10.0*I]59[15.0 + 5.0*I 14.0 + 6.0*I]60sage: n= m^(-1); n61[ 0.333333333333 + 0.333333333333*I 0.166666666667 - 0.166666666667*I]62[ -0.166666666667 - 0.333333333333*I 0.0833333333333 + 0.0833333333333*I]6364To compute eigenvalues the use the functions left_eigenvectors or65right_eigenvectors6667::6869sage: p,e = m.right_eigenvectors()7071the result of eigen is a pair (p,e), where p is a list of72eigenvalues and the e is a matrix whose columns are the73eigenvectors.7475To solve a linear system Ax = b where A = [[1,2] and b = [5,6]76[3,4]]7778::7980sage: b = vector(CDF,[5,6])81sage: m.solve_right(b)82(2.66666666667 + 0.666666666667*I, -0.333333333333 - 1.16666666667*I)8384See the commands qr, lu, and svd for QR, LU, and singular value85decomposition.86"""878889########################################################################90# LEVEL 1 functionality91# * __cinit__92# * __dealloc__93# * __init__94# * set_unsafe95# * get_unsafe96# * __richcmp__ -- always the same97# * __hash__ -- always simple98########################################################################99def __cinit__(self, parent, entries, copy, coerce):100global numpy101if numpy is None:102import numpy103self._numpy_dtype = numpy.dtype('complex128')104self._python_dtype = complex105self._numpy_dtypeint = cnumpy.NPY_CDOUBLE106# TODO: Make ComplexDoubleElement instead of CDF for speed107self._sage_dtype = CDF108self.__create_matrix__()109return110111112