From b2aa32c872ced281abd2626da0790505aa55219a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sun, 25 Nov 2012 06:13:08 +0200 Subject: [PATCH] [SymmetricMatrix] Throw exception when attempting to point-wise operate symmetric+non-symmetric into symmetric Signed-off-by: Alexander Karatarakis --- .../LinearAlgebra/Double/SymmetricMatrix.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs b/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs index 6bb58965..a4629b1f 100644 --- a/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs @@ -100,6 +100,12 @@ { var symmetricOther = other as SymmetricMatrix; var symmetricResult = result as SymmetricMatrix; + + if (symmetricResult != null && !other.IsSymmetric) + { + throw new InvalidOperationException("Symmetric + non-symmetric matrix cannot be a symmetric matrix"); + } + if (symmetricOther == null || symmetricResult == null) { base.DoAdd(other, result); @@ -135,6 +141,12 @@ { var symmetricOther = other as SymmetricMatrix; var symmetricResult = result as SymmetricMatrix; + + if (symmetricResult != null && !other.IsSymmetric) + { + throw new InvalidOperationException("Symmetric - non-symmetric matrix cannot be a symmetric matrix"); + } + if (symmetricOther == null || symmetricResult == null) { base.DoSubtract(other, result); @@ -247,6 +259,12 @@ { var symmetricOther = other as SymmetricMatrix; var symmetricResult = result as SymmetricMatrix; + + if (symmetricResult != null && !other.IsSymmetric) + { + throw new InvalidOperationException("Symmetric pointwise* non-symmetric matrix cannot be a symmetric matrix"); + } + if (symmetricOther == null || symmetricResult == null) { base.DoPointwiseMultiply(other, result); @@ -276,6 +294,12 @@ { var symmetricOther = other as SymmetricMatrix; var symmetricResult = result as SymmetricMatrix; + + if (symmetricResult != null && !other.IsSymmetric) + { + throw new InvalidOperationException("Symmetric pointwise/ non-symmetric matrix cannot be a symmetric matrix"); + } + if (symmetricOther == null || symmetricResult == null) { base.DoPointwiseDivide(other, result);