Skip to content

Commit

Permalink
Start using jafama library to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
bdezonia committed Jan 27, 2019
1 parent 10e087e commit 99616ea
Show file tree
Hide file tree
Showing 29 changed files with 244 additions and 210 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jafama</groupId>
<artifactId>jafama</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.complex.ComplexFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -45,8 +46,8 @@ private ComplexPolar() { }
*/
public static void compute(double r, double theta, ComplexFloat64Member out)
{
out.setR(r * Math.cos(theta));
out.setI(r * Math.sin(theta));
out.setR(r * FastMath.cos(theta));
out.setI(r * FastMath.sin(theta));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/nom/bdezonia/zorbage/algorithm/FFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.complex.ComplexFloat64Algebra;
import nom.bdezonia.zorbage.type.data.float64.complex.ComplexFloat64Member;
import nom.bdezonia.zorbage.type.storage.IndexedDataSource;
Expand Down Expand Up @@ -83,8 +84,8 @@ void compute(ComplexFloat64Algebra Algebra, IndexedDataSource<?,ComplexFloat64Me
for (long L = 2; L <= aSize; L = L+L) {
for (long k = 0; k < L/2; k++) {
double kth = -2 * k * Math.PI / L;
w.setR(Math.cos(kth));
w.setI(Math.sin(kth));
w.setR(FastMath.cos(kth));
w.setI(FastMath.sin(kth));
for (long j = 0; j < aSize/L; j++) {
b.get(j*L + k + L/2, tmp1);
Algebra.multiply().call(w, tmp1, tao);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.octonion.OctonionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -50,8 +51,8 @@ public class OctonionCylindrical {
*/
public static void compute(double rad, double angle, double j, double k, double l, double i0, double j0, double k0, OctonionFloat64Member out) {

double tmpAngC = Math.cos(angle);
double tmpAngS = Math.sin(angle);
double tmpAngC = FastMath.cos(angle);
double tmpAngS = FastMath.sin(angle);

double r = rad * tmpAngC;
double i = rad * tmpAngS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.octonion.OctonionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -50,14 +51,14 @@ public class OctonionMultiPolar {
*/
public static void compute(double rho1, double theta1, double rho2, double theta2, double rho3, double theta3, double rho4, double theta4, OctonionFloat64Member out) {

double tmpTh1C = Math.cos(theta1);
double tmpTh1S = Math.sin(theta1);
double tmpTh2C = Math.cos(theta2);
double tmpTh2S = Math.sin(theta2);
double tmpTh3C = Math.cos(theta3);
double tmpTh3S = Math.sin(theta3);
double tmpTh4C = Math.cos(theta4);
double tmpTh4S = Math.sin(theta4);
double tmpTh1C = FastMath.cos(theta1);
double tmpTh1S = FastMath.sin(theta1);
double tmpTh2C = FastMath.cos(theta2);
double tmpTh2S = FastMath.sin(theta2);
double tmpTh3C = FastMath.cos(theta3);
double tmpTh3S = FastMath.sin(theta3);
double tmpTh4C = FastMath.cos(theta4);
double tmpTh4S = FastMath.sin(theta4);

double r = rho1 * tmpTh1C;
double i = rho1 * tmpTh1S;
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/nom/bdezonia/zorbage/algorithm/OctonionSpherical.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.octonion.OctonionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -50,20 +51,20 @@ public class OctonionSpherical {
*/
public static void compute(double rho, double theta, double phi1, double phi2, double phi3, double phi4, double phi5, double phi6, OctonionFloat64Member out) {

double tmpThC = Math.cos(theta);
double tmpThS = Math.sin(theta);
double tmpPhi1C = Math.cos(phi1);
double tmpPhi1S = Math.sin(phi1);
double tmpPhi2C = Math.cos(phi2);
double tmpPhi2S = Math.sin(phi2);
double tmpPhi3C = Math.cos(phi3);
double tmpPhi3S = Math.sin(phi3);
double tmpPhi4C = Math.cos(phi4);
double tmpPhi4S = Math.sin(phi4);
double tmpPhi5C = Math.cos(phi5);
double tmpPhi5S = Math.sin(phi5);
double tmpPhi6C = Math.cos(phi6);
double tmpPhi6S = Math.sin(phi6);
double tmpThC = FastMath.cos(theta);
double tmpThS = FastMath.sin(theta);
double tmpPhi1C = FastMath.cos(phi1);
double tmpPhi1S = FastMath.sin(phi1);
double tmpPhi2C = FastMath.cos(phi2);
double tmpPhi2S = FastMath.sin(phi2);
double tmpPhi3C = FastMath.cos(phi3);
double tmpPhi3S = FastMath.sin(phi3);
double tmpPhi4C = FastMath.cos(phi4);
double tmpPhi4S = FastMath.sin(phi4);
double tmpPhi5C = FastMath.cos(phi5);
double tmpPhi5S = FastMath.sin(phi5);
double tmpPhi6C = FastMath.cos(phi6);
double tmpPhi6S = FastMath.sin(phi6);

double k0 = tmpPhi6S;
double j0 = tmpPhi5S * tmpPhi6C;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.quaternion.QuaternionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -46,8 +47,8 @@ public class QuaternionCylindrical {
*/
public static void compute(double rad, double angle, double j, double k, QuaternionFloat64Member out) {

double tmpAngC = Math.cos(angle);
double tmpAngS = Math.sin(angle);
double tmpAngC = FastMath.cos(angle);
double tmpAngS = FastMath.sin(angle);

double r = rad * tmpAngC;
double i = rad * tmpAngS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.quaternion.QuaternionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -46,10 +47,10 @@ public class QuaternionCylindroSpherical {
*/
public static void compute(double r, double rad, double longitude, double latitude, QuaternionFloat64Member out) {

double tmpLngC = Math.cos(longitude);
double tmpLngS = Math.sin(longitude);
double tmpLatC = Math.cos(latitude);
double tmpLatS = Math.sin(latitude);
double tmpLngC = FastMath.cos(longitude);
double tmpLngS = FastMath.sin(longitude);
double tmpLatC = FastMath.cos(latitude);
double tmpLatS = FastMath.sin(latitude);

double i = rad * tmpLngC * tmpLatC;
double j = rad * tmpLngS * tmpLatC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.quaternion.QuaternionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -46,10 +47,10 @@ public class QuaternionMultiPolar {
*/
public static void compute(double rho1, double theta1, double rho2, double theta2, QuaternionFloat64Member out) {

double tmpTh1C = Math.cos(theta1);
double tmpTh1S = Math.sin(theta1);
double tmpTh2C = Math.cos(theta2);
double tmpTh2S = Math.sin(theta2);
double tmpTh1C = FastMath.cos(theta1);
double tmpTh1S = FastMath.sin(theta1);
double tmpTh2C = FastMath.cos(theta2);
double tmpTh2S = FastMath.sin(theta2);

double r = rho1 * tmpTh1C;
double i = rho1 * tmpTh1S;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.quaternion.QuaternionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -46,12 +47,12 @@ public class QuaternionSemiPolar {
*/
public static void compute(double rho, double alpha, double theta1, double theta2, QuaternionFloat64Member out) {

double tmpAlC = Math.cos(alpha);
double tmpAlS = Math.sin(alpha);
double tmpTh1C = Math.cos(theta1);
double tmpTh1S = Math.sin(theta1);
double tmpTh2C = Math.cos(theta2);
double tmpTh2S = Math.sin(theta2);
double tmpAlC = FastMath.cos(alpha);
double tmpAlS = FastMath.sin(alpha);
double tmpTh1C = FastMath.cos(theta1);
double tmpTh1S = FastMath.sin(theta1);
double tmpTh2C = FastMath.cos(theta2);
double tmpTh2S = FastMath.sin(theta2);

double r = tmpAlC * tmpTh1C;
double i = tmpAlC * tmpTh1S;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.algorithm;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.type.data.float64.quaternion.QuaternionFloat64Member;
import nom.bdezonia.zorbage.type.data.float64.real.Float64Member;

Expand All @@ -46,12 +47,12 @@ public class QuaternionSpherical {
*/
public static void compute(double rho, double theta, double phi1, double phi2, QuaternionFloat64Member out) {

double tmpThC = Math.cos(theta);
double tmpThS = Math.sin(theta);
double tmpPhi1C = Math.cos(phi1);
double tmpPhi1S = Math.sin(phi1);
double tmpPhi2C = Math.cos(phi2);
double tmpPhi2S = Math.sin(phi2);
double tmpThC = FastMath.cos(theta);
double tmpThS = FastMath.sin(theta);
double tmpPhi1C = FastMath.cos(phi1);
double tmpPhi1S = FastMath.sin(phi1);
double tmpPhi2C = FastMath.cos(phi2);
double tmpPhi2S = FastMath.sin(phi2);

double r = tmpThC * tmpPhi1C * tmpPhi2C;
double i = tmpThS * tmpPhi1C * tmpPhi2C;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.sampling;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.misc.RealUtils;

/**
Expand Down Expand Up @@ -150,8 +151,8 @@ public void next(RealIndex value) {
final double radius = r + tr*dr;
final double angle = theta + ttheta*dtheta;
final double height = z + tz*dz;
value.set(0, Math.cos(angle) * radius); // xcoord
value.set(1, Math.sin(angle) * radius); // ycoord
value.set(0, FastMath.cos(angle) * radius); // xcoord
value.set(1, FastMath.sin(angle) * radius); // ycoord
value.set(2, height); // zcoord
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.sampling;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.misc.RealUtils;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ public boolean contains(RealIndex samplePoint) {
if (r < Math.min(r1, r2) - TOL) return false;
if (r > Math.max(r1, r2) + TOL) return false;
if (!RealUtils.near((r - this.r) % dr, 0, TOL)) return false;
double theta = Math.atan2(y, x);
double theta = FastMath.atan2(y, x);
double theta1 = this.theta;
double theta2 = this.theta + dtheta * thetaCount;
while (theta < 0) theta += Math.PI * 2;
Expand Down Expand Up @@ -133,8 +134,8 @@ public void next(RealIndex value) {
}
final double radius = r + tr*dr;
final double angle = theta + ttheta*dtheta;
value.set(0, Math.cos(angle) * radius); // xcoord
value.set(1, Math.sin(angle) * radius); // ycoord
value.set(0, FastMath.cos(angle) * radius); // xcoord
value.set(1, FastMath.sin(angle) * radius); // ycoord
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package nom.bdezonia.zorbage.sampling;

import net.jafama.FastMath;
import nom.bdezonia.zorbage.misc.RealUtils;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ public boolean contains(RealIndex samplePoint) {
if (r < Math.min(r1, r2) - TOL) return false;
if (r > Math.max(r1, r2) + TOL) return false;
if (!RealUtils.near((r - this.r) % dr, 0, TOL)) return false;
double theta = Math.acos(z/r);
double theta = FastMath.acos(z/r);
double theta1 = this.theta;
double theta2 = this.theta + dtheta * thetaCount;
while (theta < 0) theta += Math.PI * 2;
Expand All @@ -101,7 +102,7 @@ public boolean contains(RealIndex samplePoint) {
if (theta < theta2 - TOL) return false;
if (!RealUtils.near((theta - theta2) % dtheta, 0, TOL)) return false;
}
double phi = Math.atan2(y,x);
double phi = FastMath.atan2(y,x);
double phi1 = this.phi;
double phi2 = this.phi + dphi*phiCount;
while (phi < 0) phi += Math.PI * 2;
Expand Down Expand Up @@ -162,9 +163,11 @@ public void next(RealIndex value) {
final double radius = r + tr*dr;
final double angleTheta = theta + ttheta*dtheta;
final double anglePhi = phi + tphi*dphi;
value.set(0, Math.sin(angleTheta) * Math.cos(anglePhi) * radius); // xcoord
value.set(1, Math.sin(angleTheta) * Math.sin(anglePhi) * radius); // ycoord
value.set(2, Math.cos(anglePhi) * radius); // zcoord }
final double s = FastMath.sin(angleTheta);
final double c = FastMath.cos(angleTheta);
value.set(0, s * FastMath.cos(anglePhi) * radius); // xcoord
value.set(1, s * FastMath.sin(anglePhi) * radius); // ycoord
value.set(2, c * radius); // zcoord }
}
}

Expand Down
Loading

0 comments on commit 99616ea

Please sign in to comment.