PYTHON = python3 -OO
mkfname = $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST) )

.PHONEY: all
all: out.txt plot.times.svg
	cat $(word 1,$^)

out.txt: main.py jacobi.py ../matrix/matrix.py
	$(PYTHON) $< > $@

out.times.txt : main.py jacobi.py ../matrix/matrix.py
	cat /dev/null > $@
	for n in `seq 9 1 21`; do \
	echo "n=$$n"; \time -ao $@ -f "$$n %U" $(PYTHON) $< $$n; done


plot.times.svg: out.times.txt $(mkfname)
	echo '\
	set term svg background "white";\
	set out "$@";\
	set key left;\
	set title "matrix diagonalization times (`$(PYTHON) --version` `uname -m`)";\
	set xlabel "matrix size n";\
	set ylabel "diagonalization time t, sec";\
	f(x)=b+(x/a)**c;\
	b=0.7; a=20; c=3;\
	fit f(x) "$<" via b,a,c;\
	plot \
	 "$<" title "measurement" \
	,f(x) title sprintf("cyclic: fit: (n/%.f)^{%.2f}+%.2f",a,c,b) \
	'| gnuplot

.PHONEY: clean
clean: ; $(RM) out* plot*
