Last active
August 10, 2020 03:51
-
-
Save enkimute/a19d6013e1e96d8626e428ca450969c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Grassmann; | |
@basis D"1,1,1,0"; | |
P = [ rand()*v124 + rand()*v134 + rand()*v234 + v123 for i=1:1000 ]; | |
L = [ rand()*v12 + rand()*v13 + rand()*v14 + rand()*v23 + rand()*v24 + rand()*v34 for i=1:1000 ]; | |
A = [ rand() for i=1:1000]; | |
test2(L,A,P) = (LA = exp.(L.*A); LA.*P.*.~LA) | |
@time begin for j in 1:1000; test2(L,A,P); end; end; | |
# Checked with the Grassmann author - this setup re-allocates but our non-allocating tests were slower. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ test_klein.cpp -lm -o test_klein -msse4.2 -O2 | |
#include <stdio.h> | |
#include <math.h> | |
#include <chrono> | |
#include "klein/klein.hpp" | |
using namespace kln; | |
double rnd() { return (double)rand() / RAND_MAX; } // bad random. | |
int main() { | |
// Array of 1000 points, initialize with random values. | |
point points[1000]; | |
for (int i=0; i<1000; ++i) points[i] = point(rnd(),rnd(),rnd()); | |
// Array of 1000 lines, initialize with random values. | |
line lines[1000]; | |
for (int i=0; i<1000; ++i) lines[i] = line(rnd(),rnd(),rnd(),rnd(),rnd(),rnd()); | |
// Array of 1000 random angles. | |
float angles[1000]; | |
for (int i=0; i<1000; ++i) angles[i] = (float)rnd(); | |
// A place for the outputs | |
point results[1000]; | |
// Time e^(angle*line) * point * ~(e^(angle*line)) | |
auto start = std::chrono::high_resolution_clock::now(); | |
for (int t=0; t<1000; ++t) { | |
for (int i=0; i<1000; ++i) { | |
motor m = exp( angles[i] * lines[i] ); | |
results[i] = m(points[i]); | |
} | |
} | |
auto elapsed = std::chrono::high_resolution_clock::now() - start; | |
long long microseconds = std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count(); | |
printf("1 runs on 1 samples.\n\n e^(angle*line) * point * ~(e^(angle*line))\n\n"); | |
printf("time in microseconds : %lld \ntime in seconds : %f\n",microseconds,(double) microseconds / 1000000); | |
// Some debug output. (and force compiler to do the calculations ...) | |
for (int i=0; i<10; ++i) printf("point %d : %f,%f,%f\n",i,points[i].x(),points[i].y(),points[i].z()); | |
for (int i=0; i<10; ++i) printf("line %d : %2f,%2f,%2f - %2f,%2f,%2f\n",i,lines[i].e01(),lines[i].e02(),lines[i].e03(),lines[i].e12(),lines[i].e31(),lines[i].e23()); | |
for (int i=0; i<10; ++i) printf("angle %d : %f\n",i,angles[i]); | |
for (int i=0; i<10; ++i) printf("point %d : %f,%f,%f\n",i,results[i].x(),results[i].y(),results[i].z()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment