lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [1/2] lucenenet git commit: use reduced precision float base class
Date Fri, 19 Jun 2015 15:07:02 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 26758e6ec -> 70ba377a8


use reduced precision float base class


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/c11e3683
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/c11e3683
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/c11e3683

Branch: refs/heads/master
Commit: c11e3683b9abcc67893e8a885066107d9f703f80
Parents: f47779a
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Sat Jun 6 14:20:27 2015 -0400
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Wed Jun 17 21:43:23 2015 -0400

----------------------------------------------------------------------
 .../Lucene.Net.TestFramework.csproj             |  2 ++
 .../Support/FloatUtils.cs                       | 28 ++++++++++++++++++++
 .../LuceneTestCaseWithReducedFloatPrecision.cs  | 15 +++++++++++
 .../core/Search/TestExplanations.cs             |  3 ++-
 .../core/Search/TestFuzzyQuery.cs               |  3 ++-
 .../core/Search/TestQueryRescorer.cs            |  2 +-
 .../core/Search/TestSearchAfter.cs              |  3 ++-
 .../core/Search/TestTopDocsMerge.cs             |  3 ++-
 8 files changed, 54 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
index 778659d..dfc076b 100644
--- a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
+++ b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
@@ -419,6 +419,7 @@
     <Compile Include="Store\TestHelper.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Support\FloatUtils.cs" />
     <Compile Include="Support\RandomizedTest.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -452,6 +453,7 @@
     <Compile Include="Util\Paths.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Util\LuceneTestCaseWithReducedFloatPrecision.cs" />
     <Compile Include="Util\TestRuleSetupAndRestoreClassEnv.cs">
       <SubType>Code</SubType>
     </Compile>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.TestFramework/Support/FloatUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Support/FloatUtils.cs b/src/Lucene.Net.TestFramework/Support/FloatUtils.cs
new file mode 100644
index 0000000..28d43b6
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Support/FloatUtils.cs
@@ -0,0 +1,28 @@
+´╗┐using System;
+using System.Runtime.InteropServices;
+
+namespace Lucene.Net.Support
+{
+    public static class FloatUtils
+    {
+        [DllImport("msvcrt", CharSet = CharSet.Auto)]
+        public static extern IntPtr _controlfp_s(IntPtr currentControl, int newControl, int
mask);
+
+        public static void SetPrecision()
+        {
+            //if (!IsLinux())
+            {
+                // precision control
+                const int _MCW_PC = 0x00030000;
+                const int _PC_24 = 0x00020000;
+
+                _controlfp_s(IntPtr.Zero, _PC_24, _MCW_PC);
+            }
+            //else
+            {
+                // LUCENENET TODO: implement setting float precision
+                // on *nix systems.
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.TestFramework/Util/LuceneTestCaseWithReducedFloatPrecision.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCaseWithReducedFloatPrecision.cs
b/src/Lucene.Net.TestFramework/Util/LuceneTestCaseWithReducedFloatPrecision.cs
new file mode 100644
index 0000000..863fe54
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCaseWithReducedFloatPrecision.cs
@@ -0,0 +1,15 @@
+´╗┐using Lucene.Net.Support;
+
+namespace Lucene.Net.Util
+{
+    public class LuceneTestCaseWithReducedFloatPrecision :  LuceneTestCase
+    {
+        public override void SetUp()
+        {
+            base.SetUp();
+
+            // set precision
+            FloatUtils.SetPrecision();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.Tests/core/Search/TestExplanations.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestExplanations.cs b/src/Lucene.Net.Tests/core/Search/TestExplanations.cs
index fe9015e..7a677ec 100644
--- a/src/Lucene.Net.Tests/core/Search/TestExplanations.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestExplanations.cs
@@ -1,4 +1,5 @@
 using Lucene.Net.Documents;
+using Lucene.Net.Util;
 using NUnit.Framework;
 
 namespace Lucene.Net.Search
@@ -48,7 +49,7 @@ namespace Lucene.Net.Search
     /// </summary>
     /// <seealso cref= "Subclasses for actual tests" </seealso>
     [TestFixture]
-    public class TestExplanations : LuceneTestCase
+    public class TestExplanations : LuceneTestCaseWithReducedFloatPrecision
     {
         protected internal static IndexSearcher Searcher;
         protected internal static IndexReader Reader;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.Tests/core/Search/TestFuzzyQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestFuzzyQuery.cs b/src/Lucene.Net.Tests/core/Search/TestFuzzyQuery.cs
index 8d4611f..e924529 100644
--- a/src/Lucene.Net.Tests/core/Search/TestFuzzyQuery.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestFuzzyQuery.cs
@@ -1,5 +1,6 @@
 using System.Collections.Generic;
 using Lucene.Net.Documents;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Search
 {
@@ -39,7 +40,7 @@ namespace Lucene.Net.Search
     ///
     /// </summary>
     [TestFixture]
-    public class TestFuzzyQuery : LuceneTestCase
+    public class TestFuzzyQuery : LuceneTestCaseWithReducedFloatPrecision
     {
         [Test]
         public virtual void TestFuzziness()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.Tests/core/Search/TestQueryRescorer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestQueryRescorer.cs b/src/Lucene.Net.Tests/core/Search/TestQueryRescorer.cs
index 6655e57..235ff28 100644
--- a/src/Lucene.Net.Tests/core/Search/TestQueryRescorer.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestQueryRescorer.cs
@@ -246,7 +246,7 @@ namespace Lucene.Net.Search
             Assert.IsTrue(s.Contains("no second pass score"));
             Assert.IsFalse(s.Contains("= second pass score"));
             Assert.IsTrue(s.Contains("NON-MATCH"));
-            Assert.AreEqual(hits2.ScoreDocs[1].Score, explain.Value, 0.0f);
+            Assert.IsTrue(Math.Abs(hits2.ScoreDocs[1].Score - explain.Value) < 0.0000001f);
 
             r.Dispose();
             dir.Dispose();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.Tests/core/Search/TestSearchAfter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestSearchAfter.cs b/src/Lucene.Net.Tests/core/Search/TestSearchAfter.cs
index f299a1b..c11c9f6 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSearchAfter.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSearchAfter.cs
@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using Lucene.Net.Attributes;
 using Lucene.Net.Documents;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Search
 {
@@ -51,7 +52,7 @@ namespace Lucene.Net.Search
     /// Tests IndexSearcher's searchAfter() method
     /// </summary>
     [TestFixture]
-    public class TestSearchAfter : LuceneTestCase
+    public class TestSearchAfter : LuceneTestCaseWithReducedFloatPrecision
     {
         private Directory Dir;
         private IndexReader Reader;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c11e3683/src/Lucene.Net.Tests/core/Search/TestTopDocsMerge.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestTopDocsMerge.cs b/src/Lucene.Net.Tests/core/Search/TestTopDocsMerge.cs
index 3edac14..63bbcf9 100644
--- a/src/Lucene.Net.Tests/core/Search/TestTopDocsMerge.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestTopDocsMerge.cs
@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 using Lucene.Net.Documents;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Search
 {
@@ -41,7 +42,7 @@ namespace Lucene.Net.Search
     using TestUtil = Lucene.Net.Util.TestUtil;
 
     [TestFixture]
-    public class TestTopDocsMerge : LuceneTestCase
+    public class TestTopDocsMerge : LuceneTestCaseWithReducedFloatPrecision
     {
         private class ShardSearcher : IndexSearcher
         {


Mime
View raw message