Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/matrix/matrix_complex_double_dense.pyx
4057 views
1
"""
2
Dense matrices over the Complex Double Field using NumPy
3
4
EXAMPLES::
5
6
sage: b=Mat(CDF,2,3).basis()
7
sage: b[0]
8
[1.0 0.0 0.0]
9
[0.0 0.0 0.0]
10
11
We deal with the case of zero rows or zero columns::
12
13
sage: m = MatrixSpace(CDF,0,3)
14
sage: m.zero_matrix()
15
[]
16
17
TESTS::
18
19
sage: a = matrix(CDF,2,[i+(4-i)*I for i in range(4)], sparse=False)
20
sage: TestSuite(a).run()
21
sage: Mat(CDF,0,0).zero_matrix().inverse()
22
[]
23
24
AUTHORS:
25
26
- Jason Grout (2008-09): switch to NumPy backend
27
28
- Josh Kantor
29
30
- William Stein: many bug fixes and touch ups.
31
"""
32
33
##############################################################################
34
# Copyright (C) 2004,2005,2006 Joshua Kantor <[email protected]>
35
# Distributed under the terms of the GNU General Public License (GPL)
36
# The full text of the GPL is available at:
37
# http://www.gnu.org/licenses/
38
##############################################################################
39
40
import matrix_double_dense
41
42
from sage.rings.complex_double import CDF
43
44
cimport numpy as cnumpy
45
46
numpy=None
47
48
cdef class Matrix_complex_double_dense(matrix_double_dense.Matrix_double_dense):
49
"""
50
Class that implements matrices over the real double field. These
51
are supposed to be fast matrix operations using C doubles. Most
52
operations are implemented using numpy which will call the
53
underlying BLAS on the system.
54
55
EXAMPLES::
56
57
sage: m = Matrix(CDF, [[1,2*I],[3+I,4]])
58
sage: m**2
59
[-1.0 + 6.0*I 10.0*I]
60
[15.0 + 5.0*I 14.0 + 6.0*I]
61
sage: n= m^(-1); n
62
[ 0.333333333333 + 0.333333333333*I 0.166666666667 - 0.166666666667*I]
63
[ -0.166666666667 - 0.333333333333*I 0.0833333333333 + 0.0833333333333*I]
64
65
To compute eigenvalues the use the functions left_eigenvectors or
66
right_eigenvectors
67
68
::
69
70
sage: p,e = m.right_eigenvectors()
71
72
the result of eigen is a pair (p,e), where p is a list of
73
eigenvalues and the e is a matrix whose columns are the
74
eigenvectors.
75
76
To solve a linear system Ax = b where A = [[1,2] and b = [5,6]
77
[3,4]]
78
79
::
80
81
sage: b = vector(CDF,[5,6])
82
sage: m.solve_right(b)
83
(2.66666666667 + 0.666666666667*I, -0.333333333333 - 1.16666666667*I)
84
85
See the commands qr, lu, and svd for QR, LU, and singular value
86
decomposition.
87
"""
88
89
90
########################################################################
91
# LEVEL 1 functionality
92
# * __cinit__
93
# * __dealloc__
94
# * __init__
95
# * set_unsafe
96
# * get_unsafe
97
# * __richcmp__ -- always the same
98
# * __hash__ -- always simple
99
########################################################################
100
def __cinit__(self, parent, entries, copy, coerce):
101
global numpy
102
if numpy is None:
103
import numpy
104
self._numpy_dtype = numpy.dtype('complex128')
105
self._python_dtype = complex
106
self._numpy_dtypeint = cnumpy.NPY_CDOUBLE
107
# TODO: Make ComplexDoubleElement instead of CDF for speed
108
self._sage_dtype = CDF
109
self.__create_matrix__()
110
return
111
112