Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plots, code & comparison of methods #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
plots, code & comparison of methods
  • Loading branch information
Roj committed Dec 11, 2016
commit 628b61784e29084c270b091e0e12f614b88372b4
512 changes: 512 additions & 0 deletions utils/plots/.Rhistory

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions utils/plots/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CFLAGS= -g -std=c99 -Wall -Wconversion -Wtype-limits -Wshadow -Wpointer-arith -Wunreachable-code -Werror -MMD -O0
EXEC=CSV
CC=gcc

all: $(EXEC)

$(EXEC):
$(CC) sr_stability.c $(CFLAGS) -o $(EXEC) -lm

.PHONY: clean

clean:
rm $(EXEC)
Binary file added utils/plots/comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added utils/plots/comparison_sinN_R.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions utils/plots/graph.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library("ggplot2")
options(digits=3)
setwd("/home/joaquintz/Desktop/projects/utils/utils/plots/")

comparison <- read.table("benchmark.tsv",sep="\t",header=TRUE)

comparison$err_rel <- (comparison$fsqrt-comparison$sqrt)/comparison$sqrt

max_error <- max(comparison$err_rel,na.rm=TRUE)
min_error <- min(comparison$err_rel,na.rm=TRUE)
step_error <- (max_error-min_error)/5
max_x_exp <- ceiling(max(log10(comparison$x),na.rm=TRUE))

exponent_breaks <- function(coeficientes,pot)
as.expression(parse(text=paste(coeficientes,"10^",pot,sep="")))

comparison.plot <- (ggplot(data=comparison,aes(x=x,y=err_rel))
+ geom_line()
+ scale_y_continuous(limits=c(min_error,max_error),
breaks=seq(min_error,max_error,by=step_error))
+ scale_x_log10(breaks=10^seq(0,max_x_exp),
labels=exponent_breaks(NULL,seq(0,max_x_exp)))
+ theme_bw()
+ ggtitle("Error relativo: sqrt vs fsqrt")
+ ylab("Error relativo (%)") + xlab("x [log 10]"))

print(comparison.plot)

ggsave("comparison.png")
32 changes: 32 additions & 0 deletions utils/plots/sr_stability.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#define NUM_STEPS 100000000

float fsqrt(float n) {
unsigned i = *(unsigned*)&n;
i = (i + 0x3f800000) >> 1;
float y = *(float*)&i;
//y = y*0.5f + n/(2*y);
//y = y*0.5f + n/(2*y);
return y;
}
void next(size_t *n) {
if(*n<100)*n=*n+1;
else if(*n<10000)*n=*n+10;
else if(*n<1000000) *n=*n+100;
else *n=*n+1000;
}

int main() {
float res1, res2, x;
printf("x\tsqrt\tfsqrt\n");
for(size_t i= 0; i < NUM_STEPS ; next(&i)) {
x = (float) i;
res2 = (float)sqrt(x);
res1 = fsqrt(x);
printf("%.6f\t%.6f\t%.6f\n",x,res2,res1);
}
return 0;
}