Browse Source

Complex: use common short names for exp/log/ln extension methods

optimization-1
Christoph Ruegg 13 years ago
parent
commit
a6928107c4
  1. 8
      src/FSharp/Complex.fs
  2. 8
      src/Numerics/ComplexExtensions.cs
  3. 2
      src/Numerics/LinearAlgebra/Complex/Factorization/Cholesky.cs
  4. 28
      src/Numerics/Trigonometry.cs
  5. 4
      src/UnitTests/ComplexTests/ComplexTest.cs

8
src/FSharp/Complex.fs

@ -62,8 +62,8 @@ namespace MathNet.Numerics
let sec (x:complex) = Trig.Sec(x) let sec (x:complex) = Trig.Sec(x)
let csc (x:complex) = Trig.Csc(x) let csc (x:complex) = Trig.Csc(x)
let asin x = Complex.Asin(x) let asin (x:complex) = Trig.Asin(x) // numerically more stable than Complex.Asin
let acos x = Complex.Acos(x) let acos (x:complex) = Trig.Acos(x) // numerically more stable than Complex.Acos
let atan x = Complex.Atan(x) let atan x = Complex.Atan(x)
let acot (x:complex) = Trig.Acot(x) let acot (x:complex) = Trig.Acot(x)
let asec (x:complex) = Trig.Asec(x) let asec (x:complex) = Trig.Asec(x)
@ -130,8 +130,8 @@ namespace MathNet.Numerics
let sec (x:complex32) = ofComplex <| Trig.Sec(x.ToComplex()) let sec (x:complex32) = ofComplex <| Trig.Sec(x.ToComplex())
let csc (x:complex32) = ofComplex <| Trig.Csc(x.ToComplex()) let csc (x:complex32) = ofComplex <| Trig.Csc(x.ToComplex())
let asin x = Complex32.Asin(x) let asin (x:complex32) = ofComplex <| Trig.Asin(x.ToComplex()) // numerically more stable than Complex.Asin
let acos x = Complex32.Acos(x) let acos (x:complex32) = ofComplex <| Trig.Acos(x.ToComplex()) // numerically more stable than Complex.Acos
let atan x = Complex32.Atan(x) let atan x = Complex32.Atan(x)
let acot (x:complex32) = ofComplex <| Trig.Acot(x.ToComplex()) let acot (x:complex32) = ofComplex <| Trig.Acot(x.ToComplex())
let asec (x:complex32) = ofComplex <| Trig.Asec(x.ToComplex()) let asec (x:complex32) = ofComplex <| Trig.Asec(x.ToComplex())

8
src/Numerics/ComplexExtensions.cs

@ -132,7 +132,7 @@ namespace MathNet.Numerics
/// The exponential of this complex number. /// The exponential of this complex number.
/// </returns> /// </returns>
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static Complex Exponential(this Complex complex) public static Complex Exp(this Complex complex)
{ {
return Complex.Exp(complex); return Complex.Exp(complex);
} }
@ -145,7 +145,7 @@ namespace MathNet.Numerics
/// The natural logarithm of this complex number. /// The natural logarithm of this complex number.
/// </returns> /// </returns>
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static Complex NaturalLogarithm(this Complex complex) public static Complex Ln(this Complex complex)
{ {
return Complex.Log(complex); return Complex.Log(complex);
} }
@ -155,7 +155,7 @@ namespace MathNet.Numerics
/// </summary> /// </summary>
/// <returns>The common logarithm of this complex number.</returns> /// <returns>The common logarithm of this complex number.</returns>
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static Complex CommonLogarithm(this Complex complex) public static Complex Log10(this Complex complex)
{ {
return Complex.Log10(complex); return Complex.Log10(complex);
} }
@ -165,7 +165,7 @@ namespace MathNet.Numerics
/// </summary> /// </summary>
/// <returns>The logarithm of this complex number.</returns> /// <returns>The logarithm of this complex number.</returns>
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static Complex Logarithm(this Complex complex, double baseValue) public static Complex Log(this Complex complex, double baseValue)
{ {
return Complex.Log(complex, baseValue); return Complex.Log(complex, baseValue);
} }

2
src/Numerics/LinearAlgebra/Complex/Factorization/Cholesky.cs

@ -77,7 +77,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
var det = Complex.Zero; var det = Complex.Zero;
for (var j = 0; j < CholeskyFactor.RowCount; j++) for (var j = 0; j < CholeskyFactor.RowCount; j++)
{ {
det += 2.0 * CholeskyFactor.At(j, j).NaturalLogarithm(); det += 2.0 * CholeskyFactor.At(j, j).Ln();
} }
return det; return det;

28
src/Numerics/Trigonometry.cs

@ -378,7 +378,7 @@ namespace MathNet.Numerics
return -Asin(-value); return -Asin(-value);
} }
return -Complex.ImaginaryOne * ((1 - value.Square()).SquareRoot() + (Complex.ImaginaryOne * value)).NaturalLogarithm(); return -Complex.ImaginaryOne * ((1 - value.Square()).SquareRoot() + (Complex.ImaginaryOne * value)).Ln();
} }
/// <summary> /// <summary>
@ -414,7 +414,7 @@ namespace MathNet.Numerics
return Constants.Pi - Acos(-value); return Constants.Pi - Acos(-value);
} }
return -Complex.ImaginaryOne * (value + (Complex.ImaginaryOne * (1 - value.Square()).SquareRoot())).NaturalLogarithm(); return -Complex.ImaginaryOne * (value + (Complex.ImaginaryOne * (1 - value.Square()).SquareRoot())).Ln();
} }
/// <summary> /// <summary>
@ -443,7 +443,7 @@ namespace MathNet.Numerics
public static Complex Atan(this Complex value) public static Complex Atan(this Complex value)
{ {
var iz = new Complex(-value.Imaginary, value.Real); // I*this var iz = new Complex(-value.Imaginary, value.Real); // I*this
return new Complex(0, 0.5) * ((1 - iz).NaturalLogarithm() - (1 + iz).NaturalLogarithm()); return new Complex(0, 0.5) * ((1 - iz).Ln() - (1 + iz).Ln());
} }
/// <summary> /// <summary>
@ -477,7 +477,7 @@ namespace MathNet.Numerics
} }
var inv = Complex.ImaginaryOne / value; var inv = Complex.ImaginaryOne / value;
return (Complex.ImaginaryOne * 0.5) * ((1.0 - inv).NaturalLogarithm() - (1.0 + inv).NaturalLogarithm()); return (Complex.ImaginaryOne * 0.5) * ((1.0 - inv).Ln() - (1.0 + inv).Ln());
} }
/// <summary> /// <summary>
@ -506,7 +506,7 @@ namespace MathNet.Numerics
public static Complex Asec(this Complex value) public static Complex Asec(this Complex value)
{ {
var inv = 1 / value; var inv = 1 / value;
return -Complex.ImaginaryOne * (inv + (Complex.ImaginaryOne * (1 - inv.Square()).SquareRoot())).NaturalLogarithm(); return -Complex.ImaginaryOne * (inv + (Complex.ImaginaryOne * (1 - inv.Square()).SquareRoot())).Ln();
} }
/// <summary> /// <summary>
@ -538,7 +538,7 @@ namespace MathNet.Numerics
public static Complex Acsc(this Complex value) public static Complex Acsc(this Complex value)
{ {
var inv = 1 / value; var inv = 1 / value;
return -Complex.ImaginaryOne * ((Complex.ImaginaryOne * inv) + (1 - inv.Square()).SquareRoot()).NaturalLogarithm(); return -Complex.ImaginaryOne * ((Complex.ImaginaryOne * inv) + (1 - inv.Square()).SquareRoot()).Ln();
} }
/// <summary> /// <summary>
@ -751,7 +751,7 @@ namespace MathNet.Numerics
return new Complex(Sech(value.Real), 0.0); return new Complex(Sech(value.Real), 0.0);
} }
var exp = value.Exponential(); var exp = value.Exp();
if (exp.IsInfinity()) if (exp.IsInfinity())
{ {
@ -791,7 +791,7 @@ namespace MathNet.Numerics
return new Complex(Csch(value.Real), 0.0); return new Complex(Csch(value.Real), 0.0);
} }
var exp = value.Exponential(); var exp = value.Exp();
if (exp.IsInfinity()) if (exp.IsInfinity())
{ {
@ -826,7 +826,7 @@ namespace MathNet.Numerics
/// </returns> /// </returns>
public static Complex Asinh(this Complex value) public static Complex Asinh(this Complex value)
{ {
return (value + (value.Square() + 1).SquareRoot()).NaturalLogarithm(); return (value + (value.Square() + 1).SquareRoot()).Ln();
} }
/// <summary> /// <summary>
@ -854,7 +854,7 @@ namespace MathNet.Numerics
/// </returns> /// </returns>
public static Complex Acosh(this Complex value) public static Complex Acosh(this Complex value)
{ {
return (value + ((value - 1).SquareRoot() * (value + 1).SquareRoot())).NaturalLogarithm(); return (value + ((value - 1).SquareRoot() * (value + 1).SquareRoot())).Ln();
} }
/// <summary> /// <summary>
@ -882,7 +882,7 @@ namespace MathNet.Numerics
/// </returns> /// </returns>
public static Complex Atanh(this Complex value) public static Complex Atanh(this Complex value)
{ {
return 0.5 * ((1 + value).NaturalLogarithm() - (1 - value).NaturalLogarithm()); return 0.5 * ((1 + value).Ln() - (1 - value).Ln());
} }
/// <summary> /// <summary>
@ -911,7 +911,7 @@ namespace MathNet.Numerics
public static Complex Acoth(this Complex value) public static Complex Acoth(this Complex value)
{ {
var inv = 1.0 / value; var inv = 1.0 / value;
return 0.5 * ((1.0 + inv).NaturalLogarithm() - (1.0 - inv).NaturalLogarithm()); return 0.5 * ((1.0 + inv).Ln() - (1.0 - inv).Ln());
} }
/// <summary> /// <summary>
@ -940,7 +940,7 @@ namespace MathNet.Numerics
public static Complex Asech(this Complex value) public static Complex Asech(this Complex value)
{ {
var inv = 1 / value; var inv = 1 / value;
return (inv + ((inv - 1).SquareRoot() * (inv + 1).SquareRoot())).NaturalLogarithm(); return (inv + ((inv - 1).SquareRoot() * (inv + 1).SquareRoot())).Ln();
} }
/// <summary> /// <summary>
@ -969,7 +969,7 @@ namespace MathNet.Numerics
public static Complex Acsch(this Complex value) public static Complex Acsch(this Complex value)
{ {
var inv = 1 / value; var inv = 1 / value;
return (inv + (inv.Square() + 1).SquareRoot()).NaturalLogarithm(); return (inv + (inv.Square() + 1).SquareRoot()).Ln();
} }
} }
} }

4
src/UnitTests/ComplexTests/ComplexTest.cs

@ -50,7 +50,7 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{ {
var value = new Complex(real, imag); var value = new Complex(real, imag);
var expected = new Complex(expectedReal, expectedImag); var expected = new Complex(expectedReal, expectedImag);
AssertHelpers.AlmostEqual(expected, value.Exponential(), 15); AssertHelpers.AlmostEqual(expected, value.Exp(), 15);
} }
/// <summary> /// <summary>
@ -69,7 +69,7 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{ {
var value = new Complex(real, imag); var value = new Complex(real, imag);
var expected = new Complex(expectedReal, expectedImag); var expected = new Complex(expectedReal, expectedImag);
AssertHelpers.AlmostEqual(expected, value.NaturalLogarithm(), 15); AssertHelpers.AlmostEqual(expected, value.Ln(), 15);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save