How can I tell Eigensystem that a matrix $M$, which I would like to diagonalize, is a numerical matrix of complex numbers? My idea is that this information could speed up the calculation, since Mathematica would not need to determine the type of the matrix.
Asked
Active
Viewed 235 times
0
m_goldberg
- 107,779
- 16
- 103
- 257
lagoa
- 835
- 1
- 7
- 10
1 Answers
2
Eigensystem is already informed
A = RandomReal[1, {1000, 1000}];
A += Transpose[A];
Eigensystem[A]; // AbsoluteTiming
(* {1.034878, Null} *)
Eigensystem[A + 0. I]; // AbsoluteTiming
(* {2.645509, Null} *)
Update: type detection timings:
Needs["GeneralUtilities`"];
r = RandomReal[1, {100, 100}];
c = RandomComplex[1 + I, {100, 100}];
MatrixQ[r, Internal`RealValuedNumericQ] // AccurateTiming
MatrixQ[c, Internal`RealValuedNumericQ] // AccurateTiming
(* 8.60352*10^-7 *)
(* 8.61328*10^-7 *)
r = RandomReal[1, {1000, 1000}];
c = RandomComplex[1 + I, {1000, 1000}];
MatrixQ[r, Internal`RealValuedNumericQ] // AccurateTiming
MatrixQ[c, Internal`RealValuedNumericQ] // AccurateTiming
(* 8.4375*10^-7 *)
(* 8.92578*10^-7 *)
0.9 microsecond is fast enough to forget about it. Moreover, the timing doesn't depend on the matrix size because matrices are packed with the proper information about the type
r // Developer`PackedArrayForm
c // Developer`PackedArrayForm
(* PackedArray[Real, <1000, 1000>] *)
(* PackedArray[Complex, <1000, 1000>] *)
ybeltukov
- 43,673
- 5
- 108
- 212
-
Not really. For sure Eigensystem spends some time figuring out what type of matrix you provided. – lagoa Oct 18 '14 at 22:36
-
1@lagoa But that time is negligible compared to the computation of the eigensystem. – Jens Oct 18 '14 at 23:08
-
What @Jens said. Especially if dimension is in the several hundreds or more. – Daniel Lichtblau Oct 19 '14 at 19:09
-
Eigensystem, or isMalready numerical but written in terms of arbitrary-precision numbers, or something else? Please include a minimum example to clarify what you're trying to do. – Jens Oct 18 '14 at 21:06Eigenvaluesis not a compilable function, since it is outsourced to a backend LAPACK/BLAS solver that operates independently of Mathematica. Likewise, you can't tell it to useCompilationTarget -> "C"because the computations are not being done in C, but are done by LAPACK. For more information, seetutorial/SomeNotesOnInternalImplementationand the section "Approximate Numerical Linear Algebra". – DumpsterDoofus Oct 18 '14 at 21:29Eigenvaluesis called: for example, callingEigenvalueson an approximate complex Hermitian matrix returns a list of purely-real floating point numbers, with no machine-precision-size complex parts present. Other than that, I can't say what sort of auto-detection is or isn't occurring. Perhaps someone else with more knowledge can chime in with more info. – DumpsterDoofus Oct 18 '14 at 21:31