From 5c2efa6c868670d3e4731e65100ea0edb70fb7a6 Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Fri, 21 Aug 2009 14:23:41 +0800 Subject: [PATCH] Vector: used Parallel.ForEach where we could Signed-off-by: Marcus Cuda --- src/Numerics/LinearAlgebra/Double/Vector.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs index a3f87570..1df0044b 100644 --- a/src/Numerics/LinearAlgebra/Double/Vector.cs +++ b/src/Numerics/LinearAlgebra/Double/Vector.cs @@ -334,7 +334,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double public virtual Vector Negate() { var result = CreateVector(Count); - Parallel.For(0, Count, i => result[i] = -this[i]); + + Parallel.ForEach(GetIndexedEnumerator(), item => result[item.Key] = -item.Value); + return result; } @@ -404,7 +406,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double return; } - Parallel.For(0, Count, i => this[i] *= scalar); + Parallel.ForEach(GetIndexedEnumerator(), item => this[item.Key] = scalar * item.Value); } /// @@ -766,10 +768,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double return; } - for (var index = 0; index < Count; index++) - { - target[index] = this[index]; - } + Parallel.ForEach(GetIndexedEnumerator(), item => target[item.Key] = item.Value); } /// @@ -822,10 +821,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double } else { - for (var index = 0; index < count; index++) - { - destination[destinationOffset + index] = this[offset + index]; - } + Parallel.For(0, count, + index => destination[destinationOffset + index] = this[offset + index] + ); } }