danrosher commented on code in PR #940:
URL: https://github.com/apache/solr/pull/940#discussion_r922320371


##########
solr/core/src/test/org/apache/solr/util/FastInvTrigTest.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util;
+
+import org.apache.solr.SolrTestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Random;
+
+import static org.apache.solr.util.NVectorUtil.EARTH_RADIUS;
+
+public class FastInvTrigTest extends SolrTestCase {
+
+    final static int num_points = 100000;
+    final static double EPSILON = 0.0001;
+    static final Random r = new Random();
+    private static final double TEN_METERS = 0.01;
+
+    static double[][] points = new double[num_points][2];
+
+    @Before
+    public void initAll() {
+        for (int i = 0; i < num_points; i++) {
+            points[i] = generateRandomPoint();
+        }
+    }
+
+    public static double deg2rad(double deg) {
+        return deg * (Math.PI / 180);
+    }
+
+    public static double[] generateRandomPoint() {
+        double u = r.nextDouble();
+        double v = r.nextDouble();
+
+        double latitude = deg2rad(Math.toDegrees(Math.acos(u * 2 - 1)) - 90);
+        double longitude = deg2rad(360 * v - 180);
+        return new double[]{latitude, longitude};
+    }
+
+    @Test
+    public void acos() {
+        for (double i = -1; i <= 1; i = i + 0.00001) {
+            assertTrue(FastInvTrig.acos(i) - Math.acos(i) <= EPSILON);

Review Comment:
   changed to assertEquals



##########
solr/core/src/java/org/apache/solr/util/FastInvTrig.java:
##########
@@ -0,0 +1,108 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util;
+
+public class FastInvTrig {

Review Comment:
   Yes I wrote this, original in my github repo. It's a Maclaurin series 
expansion of acos. TABLE stores the coefficients that can be re-used for 
subsequent calculations, it also reuses x^2 for x^3,x^5 etc. Also initially my 
implementation required a lot of terms for convergence, until I found this 
https://stackoverflow.com/questions/20196000/own-asin-function-with-taylor-series-not-accurate
 which allows for faster convergence near -1,1. I have a benchmark in my repo 
to show it more performant than Math.acos or FastMath.acos, accuracy appears OK 
in my tests. NVector with acos faster than Haversine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to