├── .github ├── FUNDING.yml └── workflows │ ├── build-windows.yml │ └── build.yml ├── .gitignore ├── INSTALL ├── LICENSE ├── README.md ├── benchmarks ├── integration │ ├── qag-bench.c │ ├── qag-bench.lua │ ├── vegas-bench.c │ └── vegas-bench.lua ├── lmfit │ ├── enso-model-cgsl.lua │ ├── enso-model.lua │ ├── enso.lua │ ├── hahn1.lua │ ├── hahn1_benchmark.lua │ ├── nist_test.lua │ ├── rat43-cgsl.lua │ ├── rat43.lua │ └── thurber.lua ├── matinv.lua ├── matmul.lua ├── matsolve.lua ├── ode │ ├── ode-benchmark-rk8pd.c │ ├── ode-benchmark-rk8pd.lua │ ├── ode-benchmark.c │ ├── ode-benchmark.lua │ ├── ode-vec-benchmark.lua │ └── results.txt ├── plot-benchmark.lua ├── results.csv └── sf │ └── sf-roots.lua ├── build-gslcblas.lhelper ├── build-openblas-static.lhelper ├── build.lhelper ├── changelog.md ├── data ├── algorithm.lua ├── base.lua ├── bspline.lua ├── cgdt.lua ├── check.lua ├── cie-lab.lua ├── contour.lua ├── csv.lua ├── demo-init.lua ├── demos │ ├── anim.lua │ ├── bspline.lua │ ├── contour.lua │ ├── fft.lua │ ├── fractals.lua │ ├── gdt-lm.lua │ ├── graphics.lua │ ├── hist.lua │ ├── integ.lua │ ├── linfit.lua │ ├── nlinfit.lua │ ├── ode.lua │ ├── plot.lua │ ├── sf.lua │ ├── svg.lua │ ├── vegas.lua │ └── wave-particle.lua ├── eigen.lua ├── expr-actions.lua ├── expr-lexer.lua ├── expr-parse.lua ├── expr-print.lua ├── fft-init.lua ├── gdt-expr.lua ├── gdt-factors.lua ├── gdt-from-table.lua ├── gdt-hist.lua ├── gdt-integrate.lua ├── gdt-interp.lua ├── gdt-lm.lua ├── gdt-parse-csv.lua ├── gdt-plot.lua ├── gdt-subsample.lua ├── gdt.lua ├── graph-init.lua ├── gsl-check.lua ├── gsl.lua ├── help.lua ├── help │ ├── fft.lua │ ├── graphics.lua │ ├── integ.lua │ ├── iter.lua │ ├── matrix.lua │ ├── nlfit.lua │ ├── ode.lua │ ├── rng.lua │ └── vegas.lua ├── import.lua ├── integ-init.lua ├── interp2d.lua ├── iter.lua ├── linfit.lua ├── linfit_rank.lua ├── lm-expr.lua ├── lm-helpers.lua ├── matrix-power.lua ├── matrix.lua ├── monomial.lua ├── num.lua ├── pcolormesh.lua ├── plot-utils.lua ├── plot3d.lua ├── pre3d │ ├── pre3d.js │ ├── pre3d.lua │ └── pre3d_shape_utils.lua ├── project.lua ├── randist.lua ├── record.lua ├── rnd.lua ├── rng.lua ├── roots.lua ├── sf.lua ├── start.lua ├── template.lua ├── templates │ ├── gauss-kronrod-x-wgs.lua.in │ ├── lmfit.lua.in │ ├── ode-defs.lua.in │ ├── qag.lua.in │ ├── qng.lua.in │ ├── rk4.lua.in │ ├── rk8pd.lua.in │ ├── rkf45.lua.in │ ├── rkf45vec.lua.in │ ├── rnd-defs.lua.in │ ├── sf-defs.lua.in │ └── vegas-defs.lua.in ├── time.lua └── vegas.lua ├── doc ├── gsl-shell-index │ ├── acknowledgments.rst │ ├── authors.rst │ ├── benchmarks.rst │ ├── conf.py │ ├── donate.html │ ├── email-gslshell.png │ ├── gsl-shell-benchmark.png │ ├── index.rst │ └── why-donate.rst └── user-manual │ ├── bsplines.rst │ ├── complex.rst │ ├── conf.py │ ├── contour-plot-hyper.png │ ├── contour.rst │ ├── cspline-example-bell-curve.png │ ├── csv.rst │ ├── eigen.rst │ ├── example-bessJ-plot.png │ ├── example-bsplines-plot.png │ ├── example-linfit.png │ ├── example-vtiled-plots.png │ ├── examples-airy-functions-plot.png │ ├── examples-legendre-polynomials.png │ ├── examples-levy-c-curve-1.png │ ├── examples-levy-c-curve-2.png │ ├── examples-von-koch-complete.png │ ├── examples-von-koch-plot.png │ ├── examples.rst │ ├── fft-example-power-spectrum.png │ ├── fft-example-time-signal.png │ ├── fft.rst │ ├── filesystem.rst │ ├── gdt-boxplot-example-exam.png │ ├── gdt-hist-example.png │ ├── gdt-lm-plot-example.png │ ├── gdt-plot-exam-by-sex.png │ ├── gdt-plot-exam-m2-final.png │ ├── gdt-plot-exam.png │ ├── gdt-plot-perf-filter-mandel.png │ ├── gdt-reduce-exam-example-plot.png │ ├── gdt.rst │ ├── general.rst │ ├── graphics-categories-example.png │ ├── graphics-example-1.png │ ├── graphics-example-ibars.png │ ├── graphics-example-yellow-area.png │ ├── graphics.rst │ ├── gsl-ffi.rst │ ├── index.rst │ ├── integ.rst │ ├── interp2d.rst │ ├── intro-example.lua │ ├── intro-first-step-plot-1.png │ ├── intro-first-step-plot-2.png │ ├── intro-first-step-plot-3.png │ ├── intro.rst │ ├── linalg.rst │ ├── linfit.rst │ ├── lmfit-enso-dataset-plot.png │ ├── lua-base.rst │ ├── matrices.rst │ ├── nlinfit-example-plot.png │ ├── nlinfit.rst │ ├── ode-integration-quasi-spiral.png │ ├── ode.rst │ ├── pdf.rst │ ├── plot-intro-example.png │ ├── plot3d-example-1.png │ ├── plot3d.rst │ ├── polar-contour-example-cos-cos.png │ ├── project.rst │ ├── randist.rst │ ├── random.rst │ ├── record.rst │ ├── sf-bessel-Y.png │ ├── sf-besselJ-functions.png │ ├── sf.rst │ ├── sige-plot-example.png │ ├── simpler-example-1.png │ ├── simpler-example-2.png │ ├── simpler-example-3.png │ ├── split-window-example.png │ ├── square-circle-homeomorphism.png │ ├── surfplot-example-1.png │ ├── vegas.png │ ├── vegas.rst │ ├── zernicke-contour-3-1.png │ ├── zernicke-contour-5-1.png │ ├── zernicke-contour-5-5.png │ └── zernicke-contour-8-2.png ├── examples ├── am-women-weight.csv ├── exam.csv ├── metro-lm-example.csv └── perf-julia.csv ├── include ├── completion.h ├── defs.h.in ├── gsl-shell.h ├── lua-filesystem.h ├── lua-graph.h ├── lua-gsl.h └── meson.build ├── meson.build ├── meson_options.txt ├── resources ├── gsl-shell-128.png ├── gsl-shell-256.gif ├── gsl-shell-32.gif ├── gsl-shell.desktop ├── gsl-shell.svg ├── lhelper.build └── luagdb.txt ├── scripts ├── build-package.sh ├── dos2unix.py ├── repackage-appimage.sh ├── run-local.sh ├── ubuntu-build.yml ├── unix2dos.py └── www-cvs-sync.py ├── src ├── agg-plot │ ├── agg-parse-trans.cpp │ ├── agg-parse-trans.h │ ├── agg-pixfmt-config.h │ ├── agg_font_freetype.cpp │ ├── agg_font_freetype.h │ ├── agg_pixfmt_rgb24_lcd.h │ ├── agg_platform_support_win32.cpp │ ├── agg_platform_support_x11.cpp │ ├── agg_win32_bmp.cpp │ ├── bitmap-plot.cpp │ ├── bitmap-plot.h │ ├── canvas-window-cpp.h │ ├── canvas-window.cpp │ ├── canvas.h │ ├── canvas_svg.cpp │ ├── canvas_svg.h │ ├── categories.h │ ├── colors.cpp │ ├── colors.h │ ├── draw_svg.cpp │ ├── draw_svg.h │ ├── factor_labels.h │ ├── fonts.cpp │ ├── gamma.cpp │ ├── lua-cpp-utils.h │ ├── lua-draw.cpp │ ├── lua-draw.h │ ├── lua-graph.cpp │ ├── lua-plot-cpp.h │ ├── lua-plot.cpp │ ├── lua-plot.h │ ├── lua-text.cpp │ ├── lua-text.h │ ├── markers.cpp │ ├── markers.h │ ├── meson.build │ ├── my_conv_simple_marker.h │ ├── path.h │ ├── pixel_fmt.h │ ├── platform_support_ext.h │ ├── plot-auto.cpp │ ├── plot-auto.h │ ├── plot.cpp │ ├── plot.h │ ├── printf_check.cpp │ ├── printf_check.h │ ├── rect.h │ ├── rendering_buffer_utils.h │ ├── resource-manager.h │ ├── sg_marker.h │ ├── sg_object.h │ ├── split-parser.h │ ├── support_win32.cpp │ ├── support_x11.cpp │ ├── text-shape.h │ ├── text.cpp │ ├── text.h │ ├── text_label.h │ ├── trans.h │ ├── units.cpp │ ├── units.h │ ├── utils.cpp │ ├── utils.h │ ├── window-cpp.h │ ├── window.cpp │ ├── window.h │ ├── window_hooks.h │ ├── window_registry.cpp │ └── window_registry.h ├── console │ ├── completion.c │ ├── gsl-shell-jit.c │ └── meson.build ├── cpp-utils │ ├── list.h │ ├── pthreadpp.h │ ├── shared_vector.h │ └── tree.h ├── fox-gui │ ├── .gitignore │ ├── fox_gsl_shell.cpp │ ├── fox_gsl_shell.h │ ├── fx_console.cpp │ ├── fx_console.h │ ├── fx_plot_canvas.cpp │ ├── fx_plot_canvas.h │ ├── fx_plot_window.cpp │ ├── fx_plot_window.h │ ├── gsl-shell-fox.cpp │ ├── gsl_shell_app.cpp │ ├── gsl_shell_app.h │ ├── gsl_shell_interp.cpp │ ├── gsl_shell_interp.h │ ├── gsl_shell_thread.cpp │ ├── gsl_shell_thread.h │ ├── gsl_shell_window.cpp │ ├── gsl_shell_window.h │ ├── history.h │ ├── icons.h │ ├── image_buf.h │ ├── io_thread.cpp │ ├── io_thread.h │ ├── lua_plot_window.cpp │ ├── lua_plot_window.h │ ├── meson.build │ ├── plot_win.gif │ ├── plot_win.svg │ ├── redirect.cpp │ ├── redirect.h │ ├── window_part.cpp │ ├── window_part.h │ ├── window_surface.cpp │ └── window_surface.h ├── gdt │ ├── char_buffer.c │ ├── char_buffer.h │ ├── gdt_index.c │ ├── gdt_index.h │ ├── gdt_table.c │ ├── gdt_table.h │ ├── gdt_table_priv.h │ ├── meson.build │ └── xmalloc.h ├── lua-gsl │ ├── fatal.c │ ├── fatal.h │ ├── gs-types.c │ ├── gs-types.h │ ├── lua-defs.h │ ├── lua-filesystem.c │ ├── lua-gsl.c │ ├── lua-properties.c │ ├── lua-properties.h │ ├── lua-utils.c │ ├── lua-utils.h │ ├── meson.build │ ├── platform.c │ ├── platform.h │ ├── str.c │ ├── str.h │ └── strpp.h └── meson.build ├── subprojects ├── fox.wrap ├── gsl.wrap ├── libagg.wrap └── luajit.wrap ├── tests ├── eigentests.lua ├── fft-stride.lua ├── fft-tests.lua ├── linearalgebra-tests.lua ├── sf-tests.lua ├── test-gdt-integrate.lua ├── test-gdt-interp.lua └── test-gdt-subsample.lua └── todo.txt /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: franko 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/build-windows.yml: -------------------------------------------------------------------------------- 1 | name: Windows Build 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build_windows: 8 | name: Windows builds 9 | runs-on: windows-latest 10 | defaults: 11 | run: 12 | shell: msys2 {0} 13 | env: 14 | PATH: ${{ github.workspace }}/.local/bin:$PATH 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: msys2/setup-msys2@v2 18 | with: 19 | msystem: MINGW64 20 | update: true 21 | install: >- 22 | base-devel 23 | git 24 | zip 25 | - name: Python Setup 26 | uses: actions/setup-python@v2 27 | with: 28 | python-version: 3.9 29 | - name: Install Dependencies 30 | run: | 31 | pacman --noconfirm -S \ 32 | ${MINGW_PACKAGE_PREFIX}-{gcc,meson,ninja,pkg-config} unzip 33 | - name: Install Lhelper 34 | run: | 35 | git clone https://github.com/franko/lhelper 36 | cd lhelper 37 | bash install "$HOME/.local" 38 | - name: Build 39 | run: | 40 | export CPU_TYPE=x86-64 41 | export CPU_TARGET=x86-64 42 | lhelper create build-openblas-static 43 | source "$(lhelper env-source build-openblas-static)" 44 | bash scripts/build-package.sh -name=dynamic -openblas 45 | - name: Upload Artifacts 46 | uses: actions/upload-artifact@v2 47 | with: 48 | name: Windows Artifacts 49 | path: | 50 | gsl-shell-*.zip 51 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Linux Builds 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build_linux: 8 | name: Linux builds 9 | runs-on: ubuntu-18.04 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Python Setup 13 | uses: actions/setup-python@v2 14 | with: 15 | python-version: 3.9 16 | - name: Install Dependencies 17 | run: | 18 | sudo apt-get install -qq ninja-build python3-pip fuse make \ 19 | ninja-build pkg-config libx11-dev libxext-dev libxrandr-dev \ 20 | libxrender-dev libxcursor-dev libxfixes-dev libxi-dev libxft-dev \ 21 | gcc g++ gfortran 22 | pip3 install --user meson 23 | - name: Install Lhelper 24 | run: | 25 | git clone https://github.com/franko/lhelper 26 | cd lhelper 27 | bash install "$HOME/.local" 28 | - name: Build 29 | run: | 30 | export CPU_TYPE=x86-64 31 | export CPU_TARGET=x86-64 32 | lhelper create build-openblas-static 33 | source "$(lhelper env-source build-openblas-static)" 34 | bash scripts/build-package.sh -appimage -name=dynamic -openblas -unix 35 | - name: Upload Artifacts 36 | uses: actions/upload-artifact@v2 37 | with: 38 | name: Linux Artifacts 39 | path: | 40 | gsl-shell-dynamic-linux-x86-64.tar.gz 41 | GslShell-dynamic-x86-64.AppImage 42 | 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | debian_build/ 2 | /subprojects/*/ 3 | *~ 4 | .*/ 5 | !.github/ 6 | _build 7 | www/ 8 | doc/html/ 9 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | 2 | GSL Shell 2.2 3 | 4 | ** BUILD INSTRUCTION 5 | 6 | GSL Shell needs the following external libraries: 7 | 8 | - AGG library, version 2.5 9 | - GSL Library, version 1.14 or 1.15 10 | - GNU readline library (on Linux only) 11 | - Freetype2 library, version 2.4.10 12 | 13 | To build the Graphical user interface you will need also the FOX 1.6 library. 14 | 15 | Optionally you can install an optimized BLAS library like ATLAS or OPENBLAS. These can greatly improve the speed for operation on large matrices. 16 | 17 | Please note that the Lua implementation used in GSL Shell is included with 18 | the source code so that you don't need any external Lua library or 19 | executable. 20 | 21 | On Linux you just need to make sure that the appropriate dev packages are included for each of the library given above. 22 | 23 | The main compilation options for GSL Shell are located in the file "makeconfig". You can modify this file to change some compilation options if you want. In particular you may want to change the PREFIX path to something else than "/usr/local". 24 | 25 | If you have troubles you can have a look to the "makepackages" files where the include and link flags for each library are defined. In the file "makedefs" you will have additional compiling options but normally you should not need to modify this file. 26 | 27 | The makepackages files call the pkg-config command to determine some of the 28 | options. If the pkg-config utility is not on your computer, you will 29 | need to either install it or replace those calls with hard-coded flags. 30 | 31 | Once you have modified the file "makeconfig" you can just give: 32 | 33 | > make 34 | 35 | to build the software and 36 | 37 | > make install 38 | 39 | to install it. 40 | 41 | ** EXTERNAL REFERENCIES 42 | 43 | The GSL Library: 44 | 45 | http://www.gnu.org/software/gsl/ 46 | 47 | The LuaJIT project: 48 | 49 | http://luajit.org 50 | 51 | The AGG library: 52 | 53 | http://www.antigrain.com/ 54 | 55 | The FOX library: 56 | 57 | http://www.fox-toolkit.org/ 58 | 59 | The FreeType project: 60 | 61 | http://www.freetype.org/ 62 | -------------------------------------------------------------------------------- /benchmarks/integration/qag-bench.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct bessel_param { 6 | double x; 7 | int n; 8 | }; 9 | 10 | double f (double t, void * params) { 11 | struct bessel_param *p = (struct bessel_param *) params; 12 | double x = p->x; 13 | int n = p->n; 14 | return cos(n * t - x * sin(t)); 15 | } 16 | 17 | int 18 | main (void) 19 | { 20 | gsl_integration_workspace * ws = gsl_integration_workspace_alloc (1000); 21 | 22 | struct bessel_param param = {0.0, 12}; 23 | double result, error; 24 | double xold = -100, xsmp = 10; 25 | int k; 26 | 27 | gsl_function F; 28 | F.function = &f; 29 | F.params = ¶m; 30 | 31 | for (k = 0; k < 4096 * 8; k++) 32 | { 33 | param.x = (k * 30 * M_PI) / (4096 * 8); 34 | 35 | gsl_integration_qag (&F, 0, M_PI, 1e-6, 1e-4, 1000, GSL_INTEG_GAUSS21, ws, &result, &error); 36 | 37 | if (param.x - xold > xsmp) 38 | { 39 | xold = param.x; 40 | printf ("%.18f %.18f\n", param.x, result); 41 | } 42 | } 43 | 44 | gsl_integration_workspace_free (ws); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /benchmarks/integration/qag-bench.lua: -------------------------------------------------------------------------------- 1 | local template = require 'template' 2 | local q = template.load('qag', {limit=1000, order=21}) 3 | 4 | local sin, cos, pi = math.sin, math.cos, math.pi 5 | local epsabs, epsrel = 1e-6, 0.01 6 | 7 | function bessel_gen(n) 8 | local xs 9 | local fint = function(t) return cos(n*t - xs*sin(t)) end 10 | return function(x) 11 | xs = x 12 | return q(fint, 0, pi, epsabs, epsrel) 13 | end 14 | end 15 | 16 | local J12 = bessel_gen(12) 17 | 18 | -- p = graph.fxplot(J12, 0, 30*pi) 19 | 20 | local xold, xsmp = -100, 10 21 | for k = 1, 4096*8 do 22 | local x = (k-1) * 30 * math.pi / (4096*8) 23 | local y = J12(x); 24 | if x - xold > xsmp then 25 | print(x, y) 26 | xold = x 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /benchmarks/integration/vegas-bench.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | double exact = 30720.; 6 | 7 | double 8 | f (double *x, size_t dim, void *params) 9 | { 10 | return 1.*x[0]*x[0]+2.*x[1]*x[1]+3.*x[2]*x[2] 11 | +4.*x[3]*x[3]+5.*x[4]*x[4]+6.*x[5]*x[5] 12 | +7.*x[6]*x[6]+8.*x[7]*x[7]+9.*x[8]*x[8]; 13 | } 14 | void 15 | display_results (char *title, double result, double error, int i) 16 | { 17 | printf ("%s ==================\n", title); 18 | printf ("result = % .6f\n", result); 19 | printf ("sigma = % .6f\n", error); 20 | printf ("exact = % .6f\n", exact); 21 | printf ("error = % .6f = %.2g sigma\n", result - exact, 22 | fabs (result - exact) / error); 23 | printf ("i = % d\n", i); 24 | } 25 | int 26 | main (void) 27 | { 28 | double res, err; 29 | double a= 0.; 30 | double b= 2.; 31 | int dim=9; 32 | double xl[9] = { a,a,a,a,a,a,a,a,a}; 33 | double xu[9] = { b,b,b,b,b,b,b,b,b}; 34 | gsl_monte_function G = { &f, dim, 0 }; 35 | size_t calls =1e6*dim; 36 | 37 | gsl_rng_env_setup (); 38 | gsl_rng *r = gsl_rng_alloc (gsl_rng_taus2); 39 | gsl_rng_set (r, 30776); 40 | 41 | gsl_monte_vegas_state *s = gsl_monte_vegas_alloc (dim); 42 | 43 | gsl_monte_vegas_integrate (&G, xl, xu, dim, 1e4, r, s, 44 | &res, &err); 45 | //display_results ("vegas warm-up", res, err,0); 46 | 47 | //printf ("converging...\n"); 48 | int i=0; 49 | do 50 | { 51 | gsl_monte_vegas_integrate (&G, xl, xu, dim, calls/5, r, s, 52 | &res, &err); 53 | //printf ("result = % .6f sigma = % .6f chisq/dof = %.1f\n", 54 | // res, err, gsl_monte_vegas_chisq (s)); 55 | i=i+1; 56 | } 57 | while (fabs (gsl_monte_vegas_chisq (s) - 1.0) > 0.5); 58 | 59 | display_results ("vegas final", res, err, i); 60 | 61 | gsl_monte_vegas_free (s); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /benchmarks/integration/vegas-bench.lua: -------------------------------------------------------------------------------- 1 | local n=9 2 | local lo,hi = 0,2 3 | local exact = n*(n+1)/2 * (hi^3 - lo^3)/3 * (hi-lo)^(n-1) 4 | local a,b={},{} 5 | for i=1,n do 6 | a[i],b[i]=lo,hi 7 | end 8 | local calls = 1e6*n 9 | local r = rng.new('taus2') 10 | r:set(30776) 11 | local function f(x) 12 | return 1*x[1]^2+2*x[2]^2+3*x[3]^2+4*x[4]^2+5*x[5]^2+6*x[6]^2+7*x[7]^2+8*x[8]^2+9*x[9]^2 13 | end 14 | local vegas_integ = num.vegas_prepare({N=n}) 15 | local result,sigma,runs,cont = vegas_integ(f,a,b,calls,{r=r}) 16 | io.write( string.format([[ 17 | ================== 18 | result = %.6f 19 | sigma = %.6f 20 | exact = %.6f 21 | error = %.6f = %.2g sigma 22 | i = %d 23 | ]] ,result,sigma,exact, result - exact, math.abs(result - exact)/sigma, runs)) 24 | 25 | -------------------------------------------------------------------------------- /benchmarks/lmfit/enso-model.lua: -------------------------------------------------------------------------------- 1 | 2 | use 'math' 3 | 4 | local function fdf_generate(dataset) 5 | local Y = dataset.F 6 | local n = #Y 7 | 8 | return function(x, f, J) 9 | local b0 = x[1] 10 | local b1 = x[2] 11 | local b2 = x[3] 12 | local b3 = x[4] 13 | local b4 = x[5] 14 | local b5 = x[6] 15 | local b6 = x[7] 16 | local b7 = x[8] 17 | local b8 = x[9] 18 | 19 | if f then 20 | for i = 1, n do 21 | local t = i 22 | local y = b0 23 | 24 | y = y + b1 * cos(2*pi*t/12) 25 | y = y + b2 * sin(2*pi*t/12) 26 | y = y + b4 * cos(2*pi*t/b3) 27 | y = y + b5 * sin(2*pi*t/b3) 28 | y = y + b7 * cos(2*pi*t/b6) 29 | y = y + b8 * sin(2*pi*t/b6) 30 | 31 | f[i] = Y[i] - y 32 | end 33 | end 34 | 35 | if J then 36 | for i = 1, n do 37 | local t = i 38 | J:set(i, 1, -1) 39 | J:set(i, 2, -cos(2*pi*t/12)) 40 | J:set(i, 3, -sin(2*pi*t/12)) 41 | J:set(i, 4, -b4*(2*pi*t/(b3*b3))*sin(2*pi*t/b3) + 42 | b5*(2*pi*t/(b3*b3))*cos(2*pi*t/b3)) 43 | J:set(i, 5, -cos(2*pi*t/b3)) 44 | J:set(i, 6, -sin(2*pi*t/b3)) 45 | J:set(i, 7, -b7 * (2*pi*t/(b6*b6)) * sin(2*pi*t/b6) + 46 | b8 * (2*pi*t/(b6*b6)) * cos(2*pi*t/b6)) 47 | J:set(i, 8, -cos(2*pi*t/b6)) 48 | J:set(i, 9, -sin(2*pi*t/b6)) 49 | end 50 | end 51 | end 52 | end 53 | 54 | local function eval(x, t) 55 | local y = x[1] 56 | y = y + x[2] * cos(2*pi*t/12) 57 | y = y + x[3] * sin(2*pi*t/12) 58 | y = y + x[5] * cos(2*pi*t/x[4]) 59 | y = y + x[6] * sin(2*pi*t/x[4]) 60 | y = y + x[8] * cos(2*pi*t/x[7]) 61 | y = y + x[9] * sin(2*pi*t/x[7]) 62 | return y 63 | end 64 | 65 | return function(dataset) 66 | return {fdf= fdf_generate(dataset), eval= eval} 67 | end 68 | -------------------------------------------------------------------------------- /benchmarks/lmfit/hahn1_benchmark.lua: -------------------------------------------------------------------------------- 1 | 2 | local time = require 'time' 3 | 4 | use_cgsl = true 5 | 6 | suffix = (use_cgsl and '-cgsl' or '') 7 | 8 | local function nist_test(data_name, model_name) 9 | local dname = string.format('benchmarks/lmfit/%s.lua', data_name) 10 | local dataset = dofile(dname) 11 | 12 | local mname = string.format('benchmarks/lmfit/%s%s.lua', model_name, suffix) 13 | local model = dofile(mname)(dataset) 14 | 15 | local n, p = dataset.N, dataset.P 16 | 17 | local s = num.nlinfit {n= n, p= p} 18 | 19 | s:set(model.fdf, dataset.x0) 20 | 21 | local iter = 200 22 | for i=1, 200 do 23 | s:iterate() 24 | if s:test(0, 1e-8) then iter = i; break end 25 | end 26 | 27 | return s, iter 28 | end 29 | 30 | print 'starting benchmark' 31 | local t0 = time.ms() 32 | for k= 1, 80 do 33 | local s, iter = nist_test('hahn1', 'rat43') 34 | print(k, ':', 'iter=', iter, 'chisq=', s.chisq) 35 | end 36 | print('benchmark terminated, execution time= ', time.ms() - t0, 'ms') 37 | -------------------------------------------------------------------------------- /benchmarks/lmfit/nist_test.lua: -------------------------------------------------------------------------------- 1 | 2 | use 'math' 3 | use 'graph' 4 | 5 | use_cgsl = true 6 | 7 | suffix = (use_cgsl and '-cgsl' or '') 8 | 9 | local function nist_test(data_name, model_name) 10 | local dname = string.format('benchmarks/lmfit/%s.lua', data_name) 11 | local dataset = dofile(dname) 12 | 13 | local mname = string.format('benchmarks/lmfit/%s%s.lua', model_name, suffix) 14 | local model = dofile(mname)(dataset) 15 | 16 | local n, p = dataset.N, dataset.P 17 | 18 | local s = num.nlinfit {n= n, p= p} 19 | 20 | s:set(model.fdf, dataset.x0) 21 | 22 | for i=1, 200 do 23 | s:iterate() 24 | print(i, ':', ' chisq=', s.chisq) 25 | if s:test(0, 1e-8) then break end 26 | end 27 | 28 | print 'Solution:' 29 | for j=1, p do print(string.format('x[%i] = %14g ', j, s.x[j])) end 30 | print('chisq= ', s.chisq) 31 | 32 | local p = plot() 33 | local pts = ipath(dataset.iter()) 34 | 35 | local t0, t1 = dataset.t0, dataset.t1 36 | local fitln = fxline(function(t) return model.eval(s.x, t) end, t0, t1) 37 | 38 | p:addline(pts, 'blue', {{'marker', size=4}}) 39 | p:addline(fitln) 40 | p.title = dataset.title 41 | p:show() 42 | end 43 | 44 | nist_test('enso', 'enso-model') 45 | nist_test('thurber', 'rat43') 46 | nist_test('hahn1', 'rat43') 47 | -------------------------------------------------------------------------------- /benchmarks/lmfit/rat43-cgsl.lua: -------------------------------------------------------------------------------- 1 | 2 | local gsl = require 'gsl' 3 | 4 | local function fdf_generate(dataset) 5 | local td, Y = dataset.t, dataset.F 6 | local n = #Y 7 | 8 | return function(x, f, J) 9 | local b0 = gsl.gsl_matrix_get(x, 0, 0) 10 | local b1 = gsl.gsl_matrix_get(x, 1, 0) 11 | local b2 = gsl.gsl_matrix_get(x, 2, 0) 12 | local b3 = gsl.gsl_matrix_get(x, 3, 0) 13 | local b4 = gsl.gsl_matrix_get(x, 4, 0) 14 | local b5 = gsl.gsl_matrix_get(x, 5, 0) 15 | local b6 = gsl.gsl_matrix_get(x, 6, 0) 16 | 17 | for i = 0, n-1 do 18 | local t = gsl.gsl_matrix_get(td, i, 0) 19 | local num = (b0 + b1*t + b2*t^2 + b3*t^3) 20 | local den = (1 + b4*t + b5*t^2 + b6*t^3) 21 | 22 | if f then 23 | local y = num / den 24 | local Yi = gsl.gsl_matrix_get(Y, i, 0) 25 | gsl.gsl_matrix_set(f, i, 0, y - Yi) 26 | end 27 | 28 | if J then 29 | gsl.gsl_matrix_set(J, i, 0, 1 / den) 30 | gsl.gsl_matrix_set(J, i, 1, t / den) 31 | gsl.gsl_matrix_set(J, i, 2, t^2 / den) 32 | gsl.gsl_matrix_set(J, i, 3, t^3 / den) 33 | gsl.gsl_matrix_set(J, i, 4, -t * num/den^2) 34 | gsl.gsl_matrix_set(J, i, 5, -t^2 * num/den^2) 35 | gsl.gsl_matrix_set(J, i, 6, -t^3 * num/den^2) 36 | end 37 | end 38 | end 39 | end 40 | 41 | local function eval(x, t) 42 | local num = (x[1] + x[2]*t + x[3]*t^2 + x[4]*t^3) 43 | local den = (1 + x[5]*t + x[6]*t^2 + x[7]*t^3) 44 | return num / den 45 | end 46 | 47 | return function(dataset) 48 | return {fdf= fdf_generate(dataset), eval= eval} 49 | end 50 | -------------------------------------------------------------------------------- /benchmarks/lmfit/rat43.lua: -------------------------------------------------------------------------------- 1 | 2 | local function fdf_generate(dataset) 3 | local td, Y = dataset.t, dataset.F 4 | local n = #Y 5 | 6 | return function(x, f, J) 7 | local b0, b1, b2, b3 = x[1], x[2], x[3], x[4] 8 | local b4, b5, b6 = x[5], x[6], x[7] 9 | 10 | for i = 1, n do 11 | local t = td[i] 12 | local num = (b0 + b1*t + b2*t^2 + b3*t^3) 13 | local den = (1 + b4*t + b5*t^2 + b6*t^3) 14 | 15 | if f then 16 | local y = num / den 17 | f[i] = y - Y[i] 18 | end 19 | 20 | if J then 21 | J:set(i, 1, 1 / den) 22 | J:set(i, 2, t / den) 23 | J:set(i, 3, t^2 / den) 24 | J:set(i, 4, t^3 / den) 25 | J:set(i, 5, -t * num/den^2) 26 | J:set(i, 6, -t^2 * num/den^2) 27 | J:set(i, 7, -t^3 * num/den^2) 28 | end 29 | end 30 | end 31 | end 32 | 33 | local function eval(x, t) 34 | local num = (x[1] + x[2]*t + x[3]*t^2 + x[4]*t^3) 35 | local den = (1 + x[5]*t + x[6]*t^2 + x[7]*t^3) 36 | return num / den 37 | end 38 | 39 | return function(dataset) 40 | return {fdf= fdf_generate(dataset), eval= eval} 41 | end 42 | -------------------------------------------------------------------------------- /benchmarks/matinv.lua: -------------------------------------------------------------------------------- 1 | local function test_matinv(N) 2 | gen = rng.new() 3 | a = matrix.new(N, N, |i,j| gen:get()) 4 | b = matrix.inv(a) 5 | print(b:slice(1, 1, 5, 5)) 6 | end 7 | 8 | test_matinv(2000) 9 | 10 | -------------------------------------------------------------------------------- /benchmarks/matmul.lua: -------------------------------------------------------------------------------- 1 | local function test_matmul(N) 2 | gen = rng.new() 3 | a = matrix.new(N, N, |i,j| gen:get()) 4 | b = matrix.new(N, N, |i,j| gen:get()) 5 | c = a * b 6 | print(c:slice(1, 1, 5, 5)) 7 | end 8 | 9 | test_matmul(3000) 10 | 11 | -------------------------------------------------------------------------------- /benchmarks/matsolve.lua: -------------------------------------------------------------------------------- 1 | local function test_matsolve(N) 2 | gen = rng.new() 3 | a = matrix.new(N, N, |i,j| gen:get()) 4 | b = matrix.new(N, 1, |i| gen:get()) 5 | x = matrix.solve(a, b) 6 | print(x:slice(1, 1, 5, 1)) 7 | end 8 | 9 | test_matsolve(2000) 10 | 11 | -------------------------------------------------------------------------------- /benchmarks/ode/ode-benchmark-rk8pd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int 7 | func (double t, const double y[], double f[], void *params) 8 | { 9 | double mu = *(double *)params; 10 | f[0] = y[1]; 11 | f[1] = -y[0] - mu*y[1]*(y[0]*y[0] - 1); 12 | return GSL_SUCCESS; 13 | } 14 | 15 | int 16 | jac (double t, const double y[], double *dfdy, double dfdt[], void *params) 17 | { 18 | double mu = *(double *)params; 19 | gsl_matrix_view dfdy_mat = gsl_matrix_view_array (dfdy, 2, 2); 20 | gsl_matrix * m = &dfdy_mat.matrix; 21 | gsl_matrix_set (m, 0, 0, 0.0); 22 | gsl_matrix_set (m, 0, 1, 1.0); 23 | gsl_matrix_set (m, 1, 0, -2.0*mu*y[0]*y[1] - 1.0); 24 | gsl_matrix_set (m, 1, 1, -mu*(y[0]*y[0] - 1.0)); 25 | dfdt[0] = 0.0; 26 | dfdt[1] = 0.0; 27 | return GSL_SUCCESS; 28 | } 29 | 30 | int 31 | main (void) 32 | { 33 | const gsl_odeiv_step_type * T = gsl_odeiv_step_rk8pd; 34 | int k; 35 | 36 | for (k=0; k < 10; k++) 37 | { 38 | gsl_odeiv_step * s = gsl_odeiv_step_alloc (T, 2); 39 | gsl_odeiv_control * c = gsl_odeiv_control_y_new (1e-8, 0.0); 40 | gsl_odeiv_evolve * e = gsl_odeiv_evolve_alloc (2); 41 | 42 | double mu = 10; 43 | gsl_odeiv_system sys = {func, jac, 2, &mu}; 44 | 45 | double t = 0.0, t1 = 20000.0; 46 | double h = 1e-6; 47 | double y[2] = { 1.0, 0.0 }; 48 | 49 | while (t < t1) 50 | { 51 | int status = gsl_odeiv_evolve_apply (e, c, s, 52 | &sys, 53 | &t, t1, 54 | &h, y); 55 | 56 | if (status != GSL_SUCCESS) 57 | break; 58 | } 59 | 60 | printf ("%i\t%g %g %g\n", k+1, t, y[0], y[1]); 61 | 62 | gsl_odeiv_evolve_free (e); 63 | gsl_odeiv_control_free (c); 64 | gsl_odeiv_step_free (s); 65 | } 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /benchmarks/ode/ode-benchmark-rk8pd.lua: -------------------------------------------------------------------------------- 1 | 2 | -- Benchmark of ODE integration functions. 3 | -- The benchmark integrates the Van der Pol differential equation 4 | -- using over a long time interval 5 | 6 | local format = string.format 7 | 8 | function f_vanderpol_gen(mu) 9 | return function(t, x, y) return y, -x + mu * y * (1-x^2) end 10 | end 11 | 12 | local results = {} 13 | 14 | local f = f_vanderpol_gen(10.0) 15 | local s = num.ode {N= 2, eps_abs= 1e-8, method= 'rk8pd'} 16 | local x, y = 1, 0 17 | local t0, t1, h0 = 0, 20000, 0.01 18 | local step = s.step 19 | for k=1, 10 do 20 | s:init(t0, h0, f, x, y) 21 | while s.t < t1 do 22 | step(s, t1) 23 | end 24 | results[#results+1] = format('%g %g %g', s.t, s.y[1], s.y[2]) 25 | end 26 | 27 | for i, line in ipairs(results) do 28 | print(i, line) 29 | end 30 | -------------------------------------------------------------------------------- /benchmarks/ode/ode-benchmark.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int 7 | func (double t, const double y[], double f[], void *params) 8 | { 9 | double mu = *(double *)params; 10 | f[0] = y[1]; 11 | f[1] = -y[0] - mu*y[1]*(y[0]*y[0] - 1); 12 | return GSL_SUCCESS; 13 | } 14 | 15 | int 16 | jac (double t, const double y[], double *dfdy, double dfdt[], void *params) 17 | { 18 | double mu = *(double *)params; 19 | gsl_matrix_view dfdy_mat = gsl_matrix_view_array (dfdy, 2, 2); 20 | gsl_matrix * m = &dfdy_mat.matrix; 21 | gsl_matrix_set (m, 0, 0, 0.0); 22 | gsl_matrix_set (m, 0, 1, 1.0); 23 | gsl_matrix_set (m, 1, 0, -2.0*mu*y[0]*y[1] - 1.0); 24 | gsl_matrix_set (m, 1, 1, -mu*(y[0]*y[0] - 1.0)); 25 | dfdt[0] = 0.0; 26 | dfdt[1] = 0.0; 27 | return GSL_SUCCESS; 28 | } 29 | 30 | int 31 | main (void) 32 | { 33 | const gsl_odeiv_step_type * T = gsl_odeiv_step_rkf45; 34 | int k; 35 | 36 | for (k=0; k < 10; k++) 37 | { 38 | gsl_odeiv_step * s = gsl_odeiv_step_alloc (T, 2); 39 | gsl_odeiv_control * c = gsl_odeiv_control_y_new (1e-8, 0.0); 40 | gsl_odeiv_evolve * e = gsl_odeiv_evolve_alloc (2); 41 | 42 | double mu = 10; 43 | gsl_odeiv_system sys = {func, jac, 2, &mu}; 44 | 45 | double t = 0.0, t1 = 20000.0; 46 | double h = 1e-6; 47 | double y[2] = { 1.0, 0.0 }; 48 | 49 | while (t < t1) 50 | { 51 | int status = gsl_odeiv_evolve_apply (e, c, s, 52 | &sys, 53 | &t, t1, 54 | &h, y); 55 | 56 | if (status != GSL_SUCCESS) 57 | break; 58 | } 59 | 60 | printf ("%i\t%g %g %g\n", k+1, t, y[0], y[1]); 61 | 62 | gsl_odeiv_evolve_free (e); 63 | gsl_odeiv_control_free (c); 64 | gsl_odeiv_step_free (s); 65 | } 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /benchmarks/ode/ode-benchmark.lua: -------------------------------------------------------------------------------- 1 | 2 | -- Benchmark of ODE integration functions. 3 | -- The benchmark integrates the Van der Pol differential equation 4 | -- using over a long time interval 5 | 6 | local format = string.format 7 | 8 | function f_vanderpol_gen(mu) 9 | return function(t, x, y) return y, -x + mu * y * (1-x^2) end 10 | end 11 | 12 | local results = {} 13 | 14 | local f = f_vanderpol_gen(10.0) 15 | local s = num.ode {N= 2, eps_abs= 1e-8, method= 'rkf45'} 16 | local x, y = 1, 0 17 | local t0, t1, h0 = 0, 20000, 0.01 18 | local step = s.step 19 | for k=1, 10 do 20 | s:init(t0, h0, f, x, y) 21 | while s.t < t1 do 22 | step(s, t1) 23 | end 24 | results[#results+1] = format('%g %g %g', s.t, s.y[1], s.y[2]) 25 | end 26 | 27 | for i, line in ipairs(results) do 28 | print(i, line) 29 | end 30 | -------------------------------------------------------------------------------- /benchmarks/ode/ode-vec-benchmark.lua: -------------------------------------------------------------------------------- 1 | 2 | local template = require 'template' 3 | 4 | local ffi = require "ffi" 5 | 6 | local ode_spec = {N = 2, eps_abs = 1e-6, eps_rel = 0, a_y = 1, a_dydt = 0} 7 | local ode = template.load('rkf45vec', ode_spec) 8 | 9 | function f_vanderpol_gen(mu) 10 | return function(t, y, f) 11 | f[0] = y[1] 12 | f[1] = -y[0] + mu * y[1] * (1-y[0]^2) 13 | end 14 | end 15 | 16 | local f = f_vanderpol_gen(10.0) 17 | local s = ode.new() 18 | local y = ffi.new('double[2]', {1, 0}) 19 | local t0, t1, h0 = 0, 20000, 0.01 20 | local init, evol = ode.init, ode.evolve 21 | for k=1, 10 do 22 | init(s, t0, h0, f, y) 23 | while s.t < t1 do 24 | evol(s, f, t1) 25 | end 26 | print(s.t, s.y[0], s.y[1]) 27 | end 28 | -------------------------------------------------------------------------------- /benchmarks/ode/results.txt: -------------------------------------------------------------------------------- 1 | Window, msys 2 | 3 | Test: ode-benchmark 4 | * C (-march=i686 -O2 -fomit-frame-pointer), 0m2.192s 5 | * LuaJIT2, 0m0.950s 6 | * LuaJIT2 (-joff), 0m22.270s 7 | * LuaJIT2 (-O0), 0m3.551s 8 | * LuaJIT2 (-O3), 0m0.810s 9 | 10 | Test: ode-benchmark-rk8pd 11 | * C (-march=i686 -O2 -fomit-frame-pointer), 0m1.449s 12 | * LuaJIT2, 0m0.732s 13 | * LuaJIT2 (-joff), 0m10.408s 14 | * LuaJIT2 (-O0), 0m1.730s 15 | * LuaJIT2 (-O3), 0m0.748s 16 | -------------------------------------------------------------------------------- /benchmarks/results.csv: -------------------------------------------------------------------------------- 1 | Test,Source,Time 2 | ODE rk8pd,LuaJIT2 joff,10.408 3 | ODE rk8pd,C,1.449 4 | ODE rk8pd,LuaJIT2,0.732 5 | ODE rkf45,LuaJIT2 joff,22.27 6 | ODE rkf45,C,2.192 7 | ODE rkf45,LuaJIT2,0.95 8 | SF roots,LuaJIT2 joff,18.765 9 | SF roots,LuaJIT2 FFI,6.437 10 | SF roots,LuaJIT2,6.531 11 | VEGAS,LuaJIT2 joff,134.617 12 | VEGAS,C,2.509 13 | VEGAS,LuaJIT2,2.914 14 | QAG,LuaJIT2 joff,6.889 15 | QAG,C,1.886 16 | QAG,LuaJIT2,1.107 17 | -------------------------------------------------------------------------------- /benchmarks/sf/sf-roots.lua: -------------------------------------------------------------------------------- 1 | 2 | local gsl = require 'gsl' 3 | local roots = require 'roots' 4 | 5 | local sqrt, pi = math.sqrt, math.pi 6 | local besselJ = sf.besselJ 7 | 8 | -- FFI call J1 9 | local f = gsl.gsl_sf_bessel_J1 10 | 11 | -- FFI call Jn 12 | -- local f = |x| gsl.gsl_sf_bessel_Jn(1, x) 13 | 14 | -- GSL Shell SF interface 15 | -- local f = |x| besselJ(1, x) 16 | local f_scale = |x| sqrt(2/(pi*x)) 17 | 18 | local s = roots.solver(f, 1e-8, 1e-6, f_scale) 19 | 20 | local x1, x2 = 0, 1000000 21 | local rs = s:solve(x1, x2) 22 | 23 | print(string.format('Found %d roots in the interval %f %f.', #rs, x1, x2)) 24 | 25 | for k=1, 10 do print(rs[k]) end 26 | -------------------------------------------------------------------------------- /build-gslcblas.lhelper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="${CC:-gcc}" 3 | CXX="${CXX:-g++}" 4 | # CFLAGS= 5 | # CXXFLAGS= 6 | # LDFLAGS= 7 | 8 | BUILD_TYPE=Release 9 | 10 | if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then 11 | packages=("freetype2" "fox") 12 | else 13 | packages=("freetype2" "expat" "fontconfig" "xft" "fox -xft") 14 | fi 15 | 16 | -------------------------------------------------------------------------------- /build-openblas-static.lhelper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="${CC:-gcc}" 3 | CXX="${CXX:-g++}" 4 | # CFLAGS= 5 | # CXXFLAGS= 6 | # LDFLAGS= 7 | 8 | BUILD_TYPE=Release 9 | 10 | if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then 11 | packages=("freetype2" "fox") 12 | else 13 | packages=("freetype2" "expat" "fontconfig" "xft" "fox -xft") 14 | fi 15 | 16 | # Do not install the gsl package "gsl -blas=openblas" because it is built as a 17 | # subproject. 18 | packages+=( 19 | "openblas -arch=static" 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /build.lhelper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="${CC:-gcc}" 3 | CXX="${CXX:-g++}" 4 | # CFLAGS= 5 | # CXXFLAGS= 6 | # LDFLAGS= 7 | 8 | BUILD_TYPE=Release 9 | 10 | if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then 11 | packages=("freetype2" "fox") 12 | else 13 | packages=("freetype2" "expat" "fontconfig" "xft" "fox -xft") 14 | fi 15 | 16 | # Do not install the gsl package "gsl -blas=openblas" because it is built as a 17 | # subproject. 18 | packages+=( 19 | "openblas -arch=dynamic" 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | ### upcoming release 2 | 3 | Changed the build system to Meson. 4 | 5 | **LuaJIT** 6 | 7 | No longer embeds LuaJIT in the git repository but use a separate 8 | repository for LuaJIT and use it as a subproject. 9 | 10 | In turn, the LuaJIT repository corresponds exactly to the official LuaJIT 11 | repository with: 12 | 13 | - addition of a Meson build beside the Makefile based one 14 | - add a portable option for unix-like system 15 | - add the optional "short function syntax" extension 16 | 17 | The previous LuaJIT modifications to modify the search path have been undone and 18 | the search path is now modified at runtime using GSL Shell specific Lua code. 19 | 20 | ** Code reorganization 21 | 22 | Move the Lua code in a separate "data" directory. Moved also the headers in the include 23 | folder and the console application in a console folder. 24 | 25 | ** Subprojects 26 | 27 | The AGG library, LuaJIT2 and the GSL Library are now provided as subprojects. That means 28 | that the user don't need to install the related dev packages to compile GSL Shell. 29 | 30 | ** Link statically the GSL Library 31 | 32 | The GSL library is now statically linked to GSL Shell using the link-whole and the 33 | export-dynamic options. 34 | 35 | Being statically linked it means that the application can be installed on any linux 36 | system without requiring the GSL runtime library. 37 | 38 | On Windows too the GSL library is statically linked so we can provide stand-alone executables. 39 | 40 | -------------------------------------------------------------------------------- /data/bspline.lua: -------------------------------------------------------------------------------- 1 | local ffi = require 'ffi' 2 | local gsl = require 'gsl' 3 | 4 | local gsl_check = require 'gsl-check' 5 | 6 | local function eval(bs, x) 7 | local dof, ws = bs.dof, bs.ws 8 | local c = matrix.alloc(dof, 1) 9 | local v = gsl.gsl_matrix_column (c, 0) 10 | gsl_check(gsl.gsl_bspline_eval(x, v, ws)) 11 | return c 12 | end 13 | 14 | local function deriv_eval(bs, x, nderiv) 15 | local dof, ws = bs.dof, bs.ws 16 | local c = matrix.alloc(dof, nderiv + 1) 17 | gsl_check(gsl.gsl_bspline_deriv_eval(x, nderiv, c, ws)) 18 | return c 19 | end 20 | 21 | local function model(bs, x) 22 | local dof, ws = bs.dof, bs.ws 23 | local n = matrix.dim(x) 24 | local m = matrix.alloc(n, dof) 25 | for j = 0, n-1 do 26 | local xj = gsl.gsl_matrix_get(x, j, 0) 27 | local v = gsl.gsl_matrix_row (m, j) 28 | gsl_check(gsl.gsl_bspline_eval(xj, v, ws)) 29 | end 30 | return m 31 | end 32 | 33 | local mt = { 34 | __index = {eval= eval, deriv_eval= deriv_eval, model= model} 35 | } 36 | 37 | local function bspline(a, b, nbreak, order) 38 | local breaks 39 | local brk 40 | if type(a) ~= 'number' then 41 | breaks = type(a) == 'table' and matrix.vec(a) or a 42 | brk = gsl.gsl_matrix_column (breaks, 0) 43 | nbreak = #breaks 44 | order = b 45 | end 46 | 47 | local k = order or 4 48 | local dof = nbreak + k - 2 49 | local ws = ffi.gc(gsl.gsl_bspline_alloc (k, nbreak), gsl.gsl_bspline_free) 50 | 51 | if breaks then 52 | gsl_check(gsl.gsl_bspline_knots (brk, ws)) 53 | else 54 | gsl_check(gsl.gsl_bspline_knots_uniform (a, b, ws)) 55 | end 56 | 57 | local bs = {dof= dof, ws= ws} 58 | setmetatable(bs, mt) 59 | 60 | return bs 61 | end 62 | 63 | return bspline 64 | -------------------------------------------------------------------------------- /data/check.lua: -------------------------------------------------------------------------------- 1 | 2 | local M = {} 3 | 4 | local floor = math.floor 5 | local type = type 6 | 7 | local function is_integer(x) 8 | if type(x) == 'number' then 9 | return (floor(x) == x) 10 | else 11 | return false 12 | end 13 | end 14 | 15 | local function is_real(x) 16 | return type(x) == 'number' 17 | end 18 | 19 | function M.integer(x) 20 | if not is_integer(x) then error('integer expected', 2) end 21 | end 22 | 23 | function M.number(x) 24 | if not is_real(x) then error('number expected', 2) end 25 | end 26 | 27 | M.is_integer = is_integer 28 | M.is_real = is_real 29 | 30 | return M 31 | -------------------------------------------------------------------------------- /data/demo-init.lua: -------------------------------------------------------------------------------- 1 | 2 | local demo_list = {} 3 | 4 | local function load_demo(name) 5 | local record = require('demos.' .. name) 6 | local group, info = record[1], record[2] 7 | local section = demo_list[group] 8 | if not section then 9 | section = {} 10 | demo_list[group] = section 11 | end 12 | local i = #section 13 | for k, v in ipairs(info) do 14 | section[i+k] = v 15 | end 16 | end 17 | 18 | local demo_files = { 19 | 'fft', 'hist', 'bspline', 'wave-particle', 'plot', 'fractals', 'ode', 'nlinfit', 'integ', 'anim', 'linfit', 'contour', 'svg', 'graphics', 'sf', 'vegas', 'gdt-lm'} 20 | 21 | for i, name in ipairs(demo_files) do 22 | load_demo(name) 23 | end 24 | 25 | local function print_demos_list() 26 | for group, t in pairs(demo_list) do 27 | io.write('*** ', group, '\n') 28 | for k, v in ipairs(t) do 29 | print(v.name .. ' - ' .. v.description) 30 | end 31 | print '' 32 | print("***************************************************") 33 | end 34 | print("Type demo() to execute the demo.") 35 | print("For example type demo(\"wave\") for wave particle demo.") 36 | print '' 37 | end 38 | 39 | local function load_demo(name) 40 | for group, t in pairs(demo_list) do 41 | for k, entry in ipairs(t) do 42 | if entry.name == name then 43 | return entry 44 | end 45 | end 46 | end 47 | end 48 | 49 | return { 50 | list = print_demos_list, 51 | load = load_demo, 52 | } 53 | -------------------------------------------------------------------------------- /data/demos/bspline.lua: -------------------------------------------------------------------------------- 1 | 2 | use 'math' 3 | use 'num' 4 | use 'graph' 5 | 6 | local function demo1() 7 | local n, br = 200, 10 8 | 9 | local f = |x| cos(x) * exp(-0.1 * x) 10 | local xsmp = |i| 15 * (i-1) / (n-1) 11 | 12 | local x = matrix.new(n, 1, xsmp) 13 | local y = matrix.new(n, 1, |i| f(xsmp(i))) 14 | 15 | local r = rng.new() 16 | local w = matrix.alloc(n, 1) 17 | for i = 1, n do 18 | local yi = y[i] 19 | local sigma = 0.1 * yi 20 | y[i] = yi + rnd.gaussian(r, sigma) 21 | w[i] = 1/sigma^2 22 | end 23 | 24 | local b = bspline(0, 15, br) 25 | local X = b:model(x) 26 | 27 | local c, chisq, cov = linfit(X, y, w) 28 | 29 | local p = plot('B-splines curve approximation') 30 | p:addline(xyline(x, X * c)) 31 | p:addline(xyline(x, y), 'blue', {{'marker', size=5}}) 32 | p.clip = false 33 | p:show() 34 | 35 | return p 36 | end 37 | 38 | return {'B-Splines', { 39 | { 40 | name = 'bspline1', 41 | f = demo1, 42 | description = 'B-Spline approximation of noisy data' 43 | }, 44 | }} 45 | -------------------------------------------------------------------------------- /data/demos/contour.lua: -------------------------------------------------------------------------------- 1 | use 'math' 2 | 3 | local function rosenbrock() 4 | -- rosenbrock function 5 | local f = function(x, y) return 100*(y-x^2)^2 + (1-x)^2 end 6 | local N = 9 7 | local function frbeval(k) return f(1, 1 - 2 * (k/N)^2) end 8 | local ls = iter.ilist(frbeval, N) 9 | local p = contour.plot(f, -1.5, -0.5, 1.5, 2, {gridx= 80, gridy= 80, levels= ls}) 10 | p.title = 'Contour plot of Rosenbrock function' 11 | return p 12 | end 13 | 14 | local function sincos() 15 | local fsincos = function(sx,sy) 16 | return function(x,y) 17 | return cos(x)+cos(y) + sx*x + sy*y 18 | end 19 | end 20 | 21 | local f = fsincos(0.1, 0.3) 22 | local p1 = contour.plot(f, -2*pi, -2*pi, 6*pi, 6*pi, {gridx=120, gridy=120, levels= 12, show= false}) 23 | p1.title = 'f(x,y) = cos(x) + cos(y) + 0.1x + 0.3y' 24 | p1:show() 25 | return p1 26 | end 27 | 28 | local function xypolar() 29 | local N, R, zmax = 5, 1.2, 1.2 30 | local ls = iter.ilist(|k| zmax * (k-N-1)/N, 2*N+1) 31 | local p = contour.polar_plot(|x,y| y^2 - x^2*(x+1), R, {levels= ls}) 32 | p.title = 'f(x,y) = y^2 - x^2*(x+1)' 33 | return p 34 | end 35 | 36 | return {'Contour Plots', { 37 | { 38 | name = 'contour1', 39 | f = rosenbrock, 40 | description = 'Contour plot of Rosenbrock function', 41 | }, 42 | { 43 | name = 'contour2', 44 | f = sincos, 45 | description = 'Another contour plot example', 46 | }, 47 | { 48 | name = 'contour3', 49 | f = xypolar, 50 | description = 'Polar plot example', 51 | }, 52 | }} 53 | -------------------------------------------------------------------------------- /data/demos/gdt-lm.lua: -------------------------------------------------------------------------------- 1 | 2 | local function lm_demo() 3 | local r = rng.new() 4 | 5 | local a, b = 2.3, 1.2 6 | local sigma = 0.3 7 | 8 | local tool_effect = {0.4, 0.7, -1.3} 9 | local tools = {"tool A", "tool B", "tool C"} 10 | 11 | local N, P = 30, #tool_effect 12 | local dx = 3.0 13 | 14 | local t = gdt.alloc(N * P, {"tool", "x", "y"}) 15 | 16 | for k, tool in ipairs(tools) do 17 | for i = 1, N do 18 | local x = dx * (i - 1) / N 19 | local y = a + b * x + rnd.gaussian(r, sigma) + tool_effect[k] 20 | local ip = (k-1)*N + i 21 | t:set(ip, 1, tool) 22 | t:set(ip, 2, x) 23 | t:set(ip, 3, y) 24 | end 25 | end 26 | 27 | local p = gdt.plot(t, "y ~ x | tool", {show= false}) 28 | 29 | p.title = "Linear Fit example" 30 | p.xtitle = "time, s" 31 | p.ytitle = "thickness, mm" 32 | 33 | local fit = gdt.lm(t, "y ~ x, tool", {predict= true}) 34 | fit:summary() 35 | 36 | for k = 1, P do 37 | local ln = graph.fxline(|x| fit:eval {tool= tools[k], x= x}, 0, dx) 38 | p:addline(ln, graph.webcolor(k), {{'dash', 7, 3}}) 39 | end 40 | 41 | p:show() 42 | end 43 | 44 | return {'Linear Regression', { 45 | { 46 | name= 'linreg1', 47 | f = lm_demo, 48 | description = 'Mixed model regression example' 49 | }, 50 | }} 51 | -------------------------------------------------------------------------------- /data/demos/hist.lua: -------------------------------------------------------------------------------- 1 | 2 | local function hist_demo() 3 | local r = rng.new() 4 | local mu, sigma = 5, 1.0 5 | local t = gdt.create(|| { x = rnd.gaussian(r, sigma) + mu }, 100) 6 | local p = gdt.hist(t, "x", {title = "Simulated gaussian mu=" .. mu .. " sigma=".. sigma, show= false}) 7 | p:show() 8 | end 9 | 10 | return {'Histogram', { 11 | { 12 | name= 'hist', 13 | f = hist_demo, 14 | description = 'Histogram of simulated gaussian data', 15 | }, 16 | }} 17 | -------------------------------------------------------------------------------- /data/demos/integ.lua: -------------------------------------------------------------------------------- 1 | use 'math' 2 | 3 | local qag = num.quad_prepare({method='qag', limit=64, order=21}) 4 | 5 | local epsabs, epsrel = 1e-6, 0.01 6 | 7 | function bessel_gen(n, q) 8 | local xs 9 | local fint = function(t) return cos(n*t - xs*sin(t)) end 10 | return function(x) 11 | xs = x 12 | return q(fint, 0, pi, epsabs, epsrel) / pi 13 | end 14 | end 15 | 16 | local function demo1() 17 | local J4i = bessel_gen(4, qag) 18 | local J4r = |x| sf.besselJ(4, x) 19 | 20 | local p = graph.plot('J4 Bessel function / numerical integration') 21 | p:addline(graph.fxline(J4i, 0, 30*pi), 'red') 22 | p:addline(graph.fxline(J4r, 0, 30*pi), 'blue', {{'dash', 7,3}}) 23 | 24 | p:show() 25 | end 26 | 27 | 28 | return {'Numerical Integration', { 29 | { 30 | name = 'numint', 31 | f = demo1, 32 | description = 'Numerical integration of Bessel function' 33 | }, 34 | }} 35 | -------------------------------------------------------------------------------- /data/demos/linfit.lua: -------------------------------------------------------------------------------- 1 | use 'math' 2 | use 'iter' 3 | use 'num' 4 | 5 | local function demo1() 6 | local x0, x1, n = 0, 12.5, 32 7 | local a, b = 0.55, -2.4 8 | local xsmp = |i| (i-1)/(n-1) * x1 9 | 10 | local r = rng.new() 11 | local x = matrix.new(n, 1, xsmp) 12 | local y = matrix.new(n, 1, |i| a*xsmp(i) + b + rnd.gaussian(r, 0.4)) 13 | 14 | local X = matrix.new(n, 2, |i,j| j==1 and 1 or xsmp(i)) 15 | 16 | local c, chisq, cov = linfit(X, y) 17 | 18 | local fit = function(x) return c[1]+c[2]*x end 19 | 20 | local p = graph.fxplot(fit, x0, x1) 21 | p:add(graph.xyline(x, y), 'blue', {{'stroke'}, {'marker', size=5}}) 22 | p.title = 'Linear Fit' 23 | p.clip = false 24 | 25 | return p 26 | end 27 | 28 | local function demo2() 29 | local order, x0, x1, n = 3, 0.0, 24.0, 96 30 | local bess = |x| sf.besselJ(order, x) 31 | local xsmp = |i| x0 + (i-1)/(n-1) * (x1 - x0) 32 | 33 | local x = matrix.new(n, 1, xsmp) 34 | local y = matrix.new(n, 1, |i| sf.besselJ(order, xsmp(i))) 35 | 36 | local xnorm = |x| (2*x - x0 - x1) / (x1-x0) 37 | 38 | local model = function(k, x) return sf.legendreP(k, xnorm(x)) end 39 | 40 | local legmodel_order = 18 41 | 42 | local X = matrix.new(n, legmodel_order+1, |i,j| model(j-1, xsmp(i))) 43 | 44 | local c, chisq = linfit(X, y) 45 | 46 | local pc = graph.fibars(|i| c[i], 1, #c) 47 | pc.title = 'Legendre polynomials fit coefficients' 48 | pc.pad = true 49 | 50 | local fitleg = function(x) 51 | return isum(|k| c[k+1] * model(k, x), 0, legmodel_order) 52 | end 53 | 54 | local p = graph.fxplot(fitleg, x0, x1) 55 | p:addline(graph.xyline(x, y), 'blue', {{'marker', size=5}}) 56 | p.title = 'Legendre polynomial fit of Bessel J3(x)' 57 | p.clip = false 58 | 59 | return p 60 | end 61 | 62 | return {'Linear Fit', { 63 | { 64 | name= 'linfit1', 65 | f = demo1, 66 | description = 'Simple linear regression example' 67 | }, 68 | { 69 | name= 'linfit2', 70 | f = demo2, 71 | description = 'Complex example of a linear fit based on legendre polynomials' 72 | }, 73 | }} 74 | -------------------------------------------------------------------------------- /data/demos/sf.lua: -------------------------------------------------------------------------------- 1 | use 'math' 2 | use 'graph' 3 | use 'sf' 4 | 5 | local function hermiteLp(n,x) 6 | return 1/sqrt(fact(n) *2^n*sqrt(pi)) * exp(-x*x/2) * (-4)^(n/2) * fact(n/2) * laguerre(n/2, -1/2, x^2) 7 | end 8 | 9 | local function hermiteFp(n,x) 10 | return 1/sqrt(fact(n) *2^n*sqrt(pi)) * exp(-x*x/2) * (-1)^(n/2) * fact(n)/fact(n/2) * hyperg1F1(-n/2, 1/2, x^2) 11 | end 12 | 13 | local function demo_gen(hermiteFF) 14 | local w = window('v...') 15 | 16 | local p = plot('Hermite(2, x)') 17 | p:addline(fxline(|x| hermiteFF(2, x), -10, 10), 'red') 18 | w:attach(p, '1') 19 | 20 | local p = plot('Hermite(4, x)') 21 | p:addline(fxline(|x| hermiteFF(4, x), -10, 10), 'blue') 22 | w:attach(p, '2') 23 | 24 | local p = plot('Hermite(16, x)') 25 | p:addline(fxline(|x| hermiteFF(16, x), -10, 10, 512), 'green') 26 | w:attach(p, '3') 27 | end 28 | 29 | demo1 = function() demo_gen(hermiteLp) end 30 | demo2 = function() demo_gen(hermiteFp) end 31 | 32 | return {'Special Functions', { 33 | { 34 | name = 'sf1', 35 | f = demo1, 36 | description = 'Hermite function using Laguerre polynomials' 37 | }, 38 | { 39 | name = 'sf2', 40 | f = demo2, 41 | description = 'Hermite function using Hypergeometric 1F1 function' 42 | }, 43 | }} 44 | -------------------------------------------------------------------------------- /data/expr-actions.lua: -------------------------------------------------------------------------------- 1 | 2 | local type = type 3 | 4 | local function mult(a, b) 5 | if a == 1 then return b end 6 | if b == 1 then return a end 7 | return {operator= '*', a, b} 8 | end 9 | 10 | local function infix_action(sym, a, b) 11 | if sym == '*' then 12 | return mult(a, b) 13 | else 14 | return {operator= sym, a, b} 15 | end 16 | end 17 | 18 | local function prefix_action(sym, a) 19 | return {operator= sym, a} 20 | end 21 | 22 | local function enum_action(id) 23 | return "%" .. id 24 | end 25 | 26 | local function func_eval_action(func_name, arg_expr) 27 | return {func = func_name, arg = arg_expr} 28 | end 29 | 30 | local function ident_action(id) return id end 31 | 32 | local function literal_action(name) 33 | return {literal= name} 34 | end 35 | 36 | -- return true iff expr is a variable (with enums or not). 37 | -- if it is a variable returns, in addition, the var_name and the enumeration flag 38 | local function is_variable(expr) 39 | if type(expr) == 'string' then 40 | local esc_name = string.match(expr, "^%%(.*)") 41 | return true, esc_name or expr, (esc_name ~= nil) 42 | else 43 | return false 44 | end 45 | end 46 | 47 | local function is_number(expr) 48 | return type(expr) == 'number' 49 | end 50 | 51 | return { 52 | infix = infix_action, 53 | ident = ident_action, 54 | literal = literal_action, 55 | prefix = prefix_action, 56 | enum = enum_action, 57 | func_eval = func_eval_action, 58 | number = function(x) return x end, 59 | exprlist = function(a, ls) if ls then ls[#ls+1] = a else ls = {a} end; return ls end, 60 | schema = function(x, y, conds, enums) return {x= x, y= y, conds= conds, enums= enums} end, 61 | 62 | is_variable = is_variable, 63 | is_number = is_number, 64 | } 65 | -------------------------------------------------------------------------------- /data/gdt-factors.lua: -------------------------------------------------------------------------------- 1 | local AST = require 'expr-actions' 2 | 3 | local function expr_find_factors_rec(t, expr, factors) 4 | if AST.is_number(expr) then 5 | return expr 6 | elseif AST.is_variable(expr) then 7 | local _, var_name, force_enum = AST.is_variable(expr) 8 | if force_enum or t:col_type(var_name) == 'factor' then 9 | factors[#factors+1] = var_name 10 | return 1 11 | else 12 | return expr 13 | end 14 | elseif expr.operator == '*' then 15 | local a, b = expr[1], expr[2] 16 | local sa1 = expr_find_factors_rec(t, a, factors) 17 | local sa2 = expr_find_factors_rec(t, b, factors) 18 | return AST.infix('*', sa1, sa2) 19 | else 20 | return expr 21 | end 22 | end 23 | 24 | local function compute_factors(t, expr_list) 25 | local els = {} 26 | for i, e in ipairs(expr_list) do 27 | local et, factors = {}, {} 28 | et.scalar = expr_find_factors_rec(t, e, factors) 29 | if #factors > 0 then et.factor = factors end 30 | els[i] = et 31 | end 32 | return els 33 | end 34 | 35 | return {compute= compute_factors} 36 | -------------------------------------------------------------------------------- /data/gdt-from-table.lua: -------------------------------------------------------------------------------- 1 | local function gdt_from_table(data, headers) 2 | local n, m = #data, #headers 3 | local t = gdt.alloc(n, headers) 4 | for i = 1, n do 5 | local line = data[i] 6 | for j = 1, m do 7 | t:set(i, j, line[j]) 8 | end 9 | end 10 | return t 11 | end 12 | 13 | gdt.from_table = gdt_from_table 14 | -------------------------------------------------------------------------------- /data/gsl-check.lua: -------------------------------------------------------------------------------- 1 | 2 | local ffi = require 'ffi' 3 | local gsl = require 'gsl' 4 | 5 | local function gsl_check(status) 6 | if status ~= 0 then 7 | local msg = ffi.string(gsl.gsl_strerror(status)) 8 | error(msg, 2) 9 | end 10 | end 11 | 12 | return gsl_check 13 | -------------------------------------------------------------------------------- /data/help.lua: -------------------------------------------------------------------------------- 1 | local ffi = require 'ffi' 2 | 3 | local help_files = {'graphics', 'matrix', 'iter', 'integ', 'ode', 'nlfit', 'vegas', 'rng', 'fft'} 4 | 5 | local cdata_table = {'matrix', 'complex matrix', 'complex'} 6 | 7 | local function help_init( ... ) 8 | local REG = debug.getregistry() 9 | REG['GSL.help_hook'] = {} 10 | end 11 | 12 | local function open_module(modname) 13 | local fullname = string.format('help/%s', modname) 14 | local m = require(fullname) 15 | return m 16 | end 17 | 18 | local function search_help(func) 19 | for k, modname in ipairs(help_files) do 20 | local mt = getmetatable(func) 21 | local module = open_module(modname) 22 | if module[func] then 23 | local help_text = module[func] 24 | return help_text 25 | end 26 | end 27 | end 28 | 29 | help_init() 30 | 31 | -- declare a global function 32 | function help(x) 33 | local txt 34 | if type(x) == 'function' then 35 | txt = search_help(x) 36 | elseif type(x) == 'userdata' then 37 | local mt = getmetatable(x) 38 | if mt then txt = search_help(mt) end 39 | elseif type(x) == 'cdata' then 40 | local cname = gsl_type(x) 41 | if cname then txt = search_help(cname) end 42 | end 43 | print(txt or "No help found for the given function") 44 | end 45 | -------------------------------------------------------------------------------- /data/help/fft.lua: -------------------------------------------------------------------------------- 1 | local M = { 2 | [num.fft] = [[ 3 | num.fft(x[, in_place]) 4 | 5 | Perform the Fourier transform of the real-valued column matrix "x" 6 | and returns the result as an half-complex array. If "in_place" is 7 | "true" then the original data is altered and the resulting array 8 | will point to the same underlying data of the original vector. 9 | ]], 10 | 11 | [num.fftinv] = [[ 12 | num.fftinv(hc[, in_place]) 13 | 14 | Return a column matrix that contains the inverse Fourier transform 15 | of the given half-complex vector. If "in_place" is "true" then the 16 | original data is altered and the resulting vector will point to the 17 | same underlying data of the original vector. 18 | ]] 19 | } 20 | 21 | return M -------------------------------------------------------------------------------- /data/help/integ.lua: -------------------------------------------------------------------------------- 1 | local M = { 2 | [num.integ] = [[ 3 | num.integ(f, a, b[, epsabs, epsrel]) 4 | 5 | Compute the definite integral of the function "f" in the interval 6 | specified by "a" and "b" within the requested precision given by 7 | "epsabs" and "epsrel". This function always uses the adaptive QAG 8 | algorithm internally. 9 | ]], 10 | 11 | [num.quad_prepare] = [[ 12 | num.quad_prepare {method= , order= , limits= } 13 | 14 | Returns a function that can perform a numeric integration based on 15 | the method and parameters specified. 16 | 17 | *method* 18 | The quadrature algorithm. Available algorithms are "qng" and 19 | "qag", the default is "qag". 20 | 21 | *order* 22 | The order of the integration rule. The default value is 21. 23 | 24 | *limits* 25 | The maximum number of subdivisions for adaptive algorithms. 26 | The default value is 64. 27 | ]], 28 | 29 | [num.linfit] = [[ 30 | num.linfit(X, y[, w]) 31 | 32 | Perform a linear fit for the observations "y" using the model 33 | matrix "X". It returns a vector with the coefficients of the fit, 34 | the residual chi square and the covariance matrix. You can 35 | optionally provide the weights "w" of the observations to obtain a 36 | weighted linear fit. The argument "y" should be a column matrix of 37 | length N while the model "X" should be a N x M matrix where M is 38 | the number of basis in the linear model. 39 | ]] 40 | } 41 | 42 | return M 43 | -------------------------------------------------------------------------------- /data/help/iter.lua: -------------------------------------------------------------------------------- 1 | local M = { 2 | 3 | [iter.sequence] = [[ 4 | iter.sequence(f, a, b) 5 | iter.sequence(f, b) 6 | 7 | Return an iterator that gives the value (or the values) returned 8 | by the evaluation of "f(i)" where "i" is an integer that goes 9 | from "a" to "b". In the second form, the generated values start 10 | from one. 11 | ]], 12 | 13 | [iter.sample] = [[ 14 | iter.sample(f, xi, xs, n) 15 | 16 | Return an iterator that gives the couple "x, f(x)" for "x" going 17 | from "xi" to "xs" with "n" uniformly spaced intervals. If "f" 18 | returns multiple values, only the first one is retained. 19 | ]], 20 | 21 | [iter.isample] = [[ 22 | iter.isample(f, a, b) 23 | iter.isample(f, b) 24 | 25 | Return an iterator that gives the couple "i, f(i)" where "i" is an 26 | integer going from "a" to "b". In the second form, the sequence 27 | will start from one. If "f" returns multiple values, only the first 28 | one is retained. 29 | ]], 30 | 31 | [iter.ilist] = [[ 32 | iter.ilist(f, a, b) 33 | iter.ilist(f, b) 34 | 35 | Returns a list with the elements "f(i)" where "i" is an integer 36 | going from a to b. In the second form, the sequence will start from 37 | one. 38 | ]], 39 | 40 | [iter.isum] = [[ 41 | iter.isum(f, a, b) 42 | iter.isum(f, b) 43 | 44 | Returns the sum of "f(i)" for all integers "i" from a to b. In the 45 | second form, the sequence will start from one. 46 | ]] 47 | } 48 | 49 | return M 50 | -------------------------------------------------------------------------------- /data/help/nlfit.lua: -------------------------------------------------------------------------------- 1 | 2 | local REG = debug.getregistry() 3 | NLFIT = REG['GSL.NLINFIT'] 4 | 5 | local M = { 6 | [num.nlinfit] = [[ 7 | num.nlinfit {n= , p= } 8 | 9 | Create a non-linear fit solver object for a system of dimension "n" 10 | with "p" fitting parameters. 11 | ]], 12 | 13 | [NLFIT.set] = [[ 14 | :set(fdf, x0) 15 | 16 | Associate the non-linear fit solver with the user-defined function 17 | fdf and set the initial condition for the fit parameters to x0. 18 | The function fdf will be called in the form 19 | 20 | fdf(x, f, J) 21 | 22 | where x is a column matrix with the fit parameters, f is either 23 | nil or a column matrix of dimension n to store the values f(x_i) - 24 | y_i. J is either nil or a matrix of dimension n x p to store the 25 | Jacobian of f versus the fit parameters: 26 | 27 | J[i, j] = d f_i / d x_j 28 | 29 | The function fdf should set all the elements of f and J if they 30 | are not nil. 31 | ]], 32 | 33 | [NLFIT.iterate] = [[ 34 | :iterate() 35 | 36 | Advance the solver with a single step. It returns "continue" if 37 | it did not reach the optimal point and "success" otherwise. 38 | ]], 39 | 40 | [NLFIT.test] = [[ 41 | :test(eps_abs, eps_err) 42 | 43 | Check if the search converged for the given absolute error eps_abs 44 | and relative error eps_rel. 45 | ]], 46 | } 47 | 48 | return M 49 | -------------------------------------------------------------------------------- /data/help/ode.lua: -------------------------------------------------------------------------------- 1 | 2 | local function get_ode() 3 | local REG = debug.getregistry() 4 | return REG['GSL.help_hook'].ODE 5 | end 6 | 7 | local ODE = get_ode() 8 | 9 | local M = { 10 | [num.ode] = [[ 11 | num.ode {N= , eps_abs= , eps_rel= } 12 | 13 | Return an ODE object to numerically integrate an ordinary 14 | differential equation. N is the dimension of the system and 15 | eps_abs, eps_rel are the requested absolute and relative 16 | precision, respectively. 17 | ]] 18 | } 19 | 20 | if ODE then 21 | M[ODE.init] = [[ 22 | :init(t0, h0, f, y0_1, y0_2, ..., y0_N) 23 | 24 | Initialize the state of the solver to the time t0 with initial 25 | values y0_1, y0_2, ..., y0_N. The second argument h0 is the initial 26 | step size that the integrator will try. The function f is the 27 | function that defines the ODE system. It will be called as "f(t, 28 | y_1, y_2, ..., y_N)" where t is the time and y_1, y_2, ... are the 29 | values of the N independent values conventionally denoted here by 30 | y. The function f should return N values that correspond to values 31 | f_i(t, y_1, ..., y_N) for each component f_i of the ODE system 32 | function. 33 | ]] 34 | 35 | M[ODE.step] = [[ 36 | :step(t1) 37 | 38 | Advance the solution of the system by a step chosen adaptively 39 | based on the previous step size. The new values (t, y) are stored 40 | internally by the solver and can be retrieved as properties with 41 | the name "t" and "y" where the latter is a column matrix of size N. 42 | The new values of t will be less than or equal to the value given 43 | by t1. If the value .t is less than t1, then the function can be 44 | called again to further advance the ODE system. 45 | ]] 46 | 47 | M[ODE.evolve] = [[ 48 | evolve(t1, t_step) 49 | 50 | Returns a Lua iterator that advances the ODE system at each 51 | iteration of a step t_step until the value t1 is reached. The 52 | iterator returns the value t itself and all the system variables 53 | y0, y1, ... up to y_N. 54 | ]] 55 | end 56 | 57 | return M 58 | -------------------------------------------------------------------------------- /data/help/rng.lua: -------------------------------------------------------------------------------- 1 | local RNG = rng.new() 2 | 3 | local M = { 4 | [rng.new] = [[ 5 | rng.new([name]) 6 | 7 | This function returns a "random number generator" object of the 8 | specified type "name". If you do not specify a particular 9 | generator, the default "taus2" generator will be used. 10 | ]], 11 | [rng.list] = [[ 12 | rng.list() 13 | 14 | Return an array with a list of all the supported generator types. 15 | ]], 16 | [RNG.get] = [[ 17 | :get() 18 | 19 | This function returns a real number uniformly distributed in the 20 | range [0,1). The range includes 0.0 but excludes 1.0. Some 21 | generators compute this ratio internally so that they can provide 22 | floating point numbers with more than 32 bits of randomness. 23 | ]], 24 | [RNG.getint] = [[ 25 | :getint(n) 26 | 27 | This function returns a random integer from 0 to n-1 inclusive by 28 | scaling down and/or discarding samples from the generator R. All 29 | integers in the range [0,n-1] are produced with equal probability. 30 | ]], 31 | [RNG.set] = [[ 32 | :set(seed) 33 | 34 | This method sets the seed of the generator to the given integer 35 | value. 36 | ]], 37 | } 38 | 39 | return M 40 | 41 | -------------------------------------------------------------------------------- /data/help/vegas.lua: -------------------------------------------------------------------------------- 1 | local M = { 2 | [num.vegas_prepare] = [[ 3 | num.vegas_prepare(spec) 4 | 5 | Prepare a VEGAS Monte Carlo integrator, vegas_integ. spec is a 6 | table which should contain the field N (number of dimensions of the 7 | function). 8 | 9 | vegas_prepare returns the integrator: 10 | 11 | vegas_integ(f, a, b[, calls, options]) 12 | 13 | Use the VEGAS Monte Carlo algorithm to integrate the function f 14 | over the N-dimensional hypercubic region defined by the lower and 15 | upper limits in the vectors a and b. The integration uses a fixed 16 | number of function calls "calls". 17 | 18 | The function returns the result of the integration, the error 19 | estimate and the number of runs needed to reach the desired 20 | chi-squared. 21 | 22 | The fourth return value is a continuation function that takes a 23 | number of calls as an argument. This function can be invoked to 24 | recalculate the integral with a higher number of calls, to increase 25 | precision. The continuation function returns the new result, error 26 | and number of runs. Note that this function discards the previous 27 | results, but retains the optimized grid. Typically, the 28 | continuation function is called with a multiple of the original 29 | number of calls, to reduce the error. 30 | 31 | ]], } 32 | 33 | return M 34 | -------------------------------------------------------------------------------- /data/integ-init.lua: -------------------------------------------------------------------------------- 1 | 2 | local template = require 'template' 3 | local check = require 'check' 4 | 5 | function num.quad_prepare(options) 6 | local known_methods = {qng= true, qag= true} 7 | 8 | local method = options.method or 'qag' 9 | local order = options.order or 21 10 | local limit = options.limit or 64 11 | 12 | if not known_methods[method] then 13 | error('the method ' .. method .. ' is unknown') 14 | end 15 | 16 | check.integer(limit) 17 | 18 | if limit < 8 then limit = 8 end 19 | 20 | local q = template.load(method, {limit= limit, order= order}) 21 | 22 | return q 23 | end 24 | 25 | local q_default 26 | 27 | function num.integ(f, a, b, epsabs, epsrel) 28 | epsabs = epsabs or 1e-8 29 | epsrel = epsrel or 1e-8 30 | 31 | check.number(a) 32 | check.number(b) 33 | 34 | if not q_default then 35 | q_default = template.load('qag', {limit= 64, order= 21}) 36 | end 37 | 38 | local result = q_default (f, a, b, epsabs, epsrel) 39 | 40 | return result 41 | end 42 | -------------------------------------------------------------------------------- /data/linfit.lua: -------------------------------------------------------------------------------- 1 | 2 | local ffi = require 'ffi' 3 | local gsl = require 'gsl' 4 | local gsl_check = require 'gsl-check' 5 | 6 | local workspace 7 | local workspace_n 8 | local workspace_p 9 | 10 | local function get_workspace(n, p) 11 | local ws 12 | if n == workspace_n and p == workspace_p then 13 | ws = workspace 14 | else 15 | ws = ffi.gc(gsl.gsl_multifit_linear_alloc(n, p), 16 | gsl.gsl_multifit_linear_free) 17 | 18 | workspace_n = n 19 | workspace_p = p 20 | workspace = ws 21 | end 22 | return ws 23 | end 24 | 25 | function num.linfit(X, y, w) 26 | local n, p = matrix.dim(X) 27 | local ws = get_workspace(n, p) 28 | local c = matrix.alloc(p, 1) 29 | local cov = matrix.alloc(p, p) 30 | local yv = gsl.gsl_matrix_column (y, 0) 31 | local cv = gsl.gsl_matrix_column (c, 0) 32 | 33 | local chisq = ffi.new('double[1]') 34 | 35 | if w then 36 | local wv = gsl.gsl_matrix_column (w, 0) 37 | gsl_check(gsl.gsl_multifit_wlinear(X, wv, yv, cv, cov, chisq, ws)) 38 | else 39 | gsl_check(gsl.gsl_multifit_linear(X, yv, cv, cov, chisq, ws)) 40 | end 41 | 42 | return c, chisq[0], cov 43 | end 44 | -------------------------------------------------------------------------------- /data/lm-expr.lua: -------------------------------------------------------------------------------- 1 | local format = string.format 2 | 3 | local function as_char(v, prio) 4 | if type(v) == 'table' and v.name then 5 | return (v.prio < prio and format("(%s)", v.name) or v.name) 6 | end 7 | return tostring(v) 8 | end 9 | 10 | local var_name 11 | 12 | local var_name_mt = { 13 | __add = function(a, b) return var_name(format("%s + %s", as_char(a, 0), as_char(b, 0)), 0) end, 14 | __mul = function(a, b) return var_name(format("%s * %s", as_char(a, 2), as_char(b, 2)), 2) end, 15 | __sub = function(a, b) return var_name(format("%s - %s", as_char(a, 0), as_char(b, 0)), 0) end, 16 | __div = function(a, b) return var_name(format("%s / %s", as_char(a, 2), as_char(b, 2)), 2) end, 17 | __pow = function(a, b) return var_name(format("%s^%s", as_char(a, 10), as_char(b, 10)), 10) end, 18 | __unm = function(a) return var_name(format("-%s", as_char(a, 1)), 1) end, 19 | } 20 | 21 | var_name = function (name, prio) 22 | local t = {prio= prio or 10, name= name} 23 | return setmetatable(t, var_name_mt) 24 | end 25 | 26 | return var_name 27 | -------------------------------------------------------------------------------- /data/lm-helpers.lua: -------------------------------------------------------------------------------- 1 | local LM = {} 2 | 3 | local var_name = require 'lm-expr' 4 | 5 | local factor_mt 6 | 7 | local function mul_factor(a, b) 8 | local c = {value= a.value .. ":" .. b.value} 9 | return setmetatable(c, factor_mt) 10 | end 11 | 12 | factor_mt = { 13 | __mul = mul_factor, 14 | } 15 | 16 | function LM.factor(name) 17 | local t = {name= name, value = ""} 18 | return setmetatable(t, factor_mt) 19 | end 20 | 21 | function LM.eval_test(...) 22 | local inf = {np = select('#', ...)} 23 | inf.class = {} 24 | for k= 1, inf.np do 25 | local v = select(k, ...) 26 | inf.class[k] = (type(v) == 'number' and 1 or 0) 27 | end 28 | return inf 29 | end 30 | 31 | function LM.eval_func(inf, pt, i, ...) 32 | for k = 1, inf.np do 33 | local x = select(k, ...) 34 | local value = (inf.class[k] == 1 and x or x.value) 35 | gdt.set(pt, i, k, value) 36 | end 37 | end 38 | 39 | LM.var_name = var_name 40 | 41 | local function expr_to_name(expr) 42 | if type(expr) == 'table' then 43 | return expr.name 44 | else 45 | local base = '(average)' 46 | local minus = expr < 0 and '- ' or '' 47 | if expr == 1 or expr == -1 then 48 | return string.format("%s%s", minus, base) 49 | else 50 | return string.format("%s%s / %g", minus, base, math.abs(expr)) 51 | end 52 | end 53 | end 54 | 55 | function LM.find_names(...) 56 | local n = select("#", ...) 57 | local names = {} 58 | for k = 1, n do 59 | local expr = select(k, ...) 60 | names[k] = expr_to_name(expr) 61 | end 62 | return names 63 | end 64 | 65 | return LM 66 | -------------------------------------------------------------------------------- /data/pcolormesh.lua: -------------------------------------------------------------------------------- 1 | local plot_utils = require "plot-utils" 2 | 3 | local color_map = graph.color_function("coolwarm") 4 | 5 | function pcolormesh(xs, ys, zs) 6 | local XN, YN 7 | if zs == nil then 8 | zs = xs, ys 9 | YN, XN = zs:dim() 10 | xs = matrix.new(XN, 1, |i| i) 11 | ys = matrix.new(YN, 1, |i| i) 12 | else 13 | XN, YN = #xs, #ys 14 | end 15 | 16 | local x1, x2 = (3 * xs[1] - xs[2]) / 2, (3 * xs[XN] - xs[XN - 1]) / 2 17 | local y1, y2 = (3 * ys[1] - ys[2]) / 2, (3 * ys[YN] - ys[YN - 1]) / 2 18 | 19 | local p = graph.plot() 20 | p:add(graph.rect(x1, y1, x2, y2), 'black') 21 | 22 | local z_min_raw, z_max_raw = zs:get(1, 1), zs:get(1, 1) 23 | for i = 1, XN do 24 | for j = 1, YN do 25 | local z = zs:get(j, i) 26 | if z < z_min_raw then z_min_raw = z end 27 | if z > z_max_raw then z_max_raw = z end 28 | end 29 | end 30 | 31 | local z_step, zi0, zi1 = plot_utils.find_scale_limits(z_min_raw, z_max_raw, 12) 32 | local z_min, z_max = z_step * zi0, z_step * zi1 33 | 34 | for i = 1, XN do 35 | for j = 1, YN do 36 | local z = zs:get(j, i) 37 | local color = color_map((z - z_min) / (z_max - z_min)) 38 | local xr1 = (i > 1 and (xs[i] + xs[i - 1]) / 2 or (3 * xs[i] - xs[i + 1]) / 2) 39 | local yr1 = (j > 1 and (ys[j] + ys[j - 1]) / 2 or (3 * ys[j] - ys[j + 1]) / 2) 40 | local xr2 = (i < XN and (xs[i] + xs[i + 1]) / 2 or (3 * xs[i] - xs[i - 1]) / 2) 41 | local yr2 = (j < YN and (ys[j] + ys[j + 1]) / 2 or (3 * ys[j] - ys[j - 1]) / 2) 42 | p:add(graph.rect(xr1, yr1, xr2, yr2), color) 43 | end 44 | end 45 | 46 | local zlevels = { } 47 | for k = zi0, zi1 do 48 | zlevels[k - zi0] = z_step * k 49 | end 50 | p:set_legend(plot_utils.create_colormap_legend(zi1 - zi0, zlevels, color_map)) 51 | p:show() 52 | return p 53 | end 54 | 55 | matrix.plot = pcolormesh 56 | 57 | -------------------------------------------------------------------------------- /data/plot-utils.lua: -------------------------------------------------------------------------------- 1 | local plot_utils = { } 2 | 3 | -- Compute two values "ref", "base" such that: 4 | -- 5 | -- ref * base is close to delta 6 | -- ref is a integer power of 10 7 | -- base is one of 1, 2 and 5 8 | function plot_utils.decimal_scale_round(delta) 9 | local log_delta = math.log10(delta) 10 | local ref = 10^(math.floor(log_delta)) 11 | local r_delta = delta / ref 12 | local base_dist, base_value 13 | for _, base in ipairs {1, 2, 5, 10} do 14 | local dist = math.abs(r_delta - base) 15 | if not base_dist or dist < base_dist then 16 | base_dist = dist 17 | base_value = base 18 | end 19 | end 20 | if base_value == 10 then 21 | ref = ref * 10 22 | base_value = 1 23 | end 24 | return ref, base_value 25 | end 26 | 27 | function plot_utils.find_scale_limits(value_min, value_max, n_intervals) 28 | local ref, base = plot_utils.decimal_scale_round((value_max - value_min) / n_intervals) 29 | local delta_round = ref * base 30 | local vindex_min = math.floor(value_min / delta_round) 31 | local vindex_max = math.ceil (value_max / delta_round) 32 | return delta_round, vindex_min, vindex_max 33 | end 34 | 35 | function plot_utils.create_colormap_legend(nlevels, zlevels, color) 36 | local bs = 25 37 | local p = graph.plot() 38 | local tk = graph.path() 39 | local ln = graph.path(0, 0) 40 | ln:line_to(bs, 0) 41 | for k = 0, nlevels do 42 | local y = k * bs 43 | 44 | if k < nlevels then 45 | ln:move_to(0, y) 46 | ln:line_to(0, y + bs) 47 | ln:line_to(bs, y + bs) 48 | ln:line_to(bs, y) 49 | 50 | p:add(graph.rect(0, y, bs, y + bs), color((k+1)/(nlevels+1))) 51 | end 52 | 53 | tk:move_to(bs, y) 54 | tk:line_to(bs+5, y) 55 | 56 | local txt = string.format("%g", zlevels[k]) 57 | p:add(graph.textshape(bs+10, y - 3, txt, 12), 'black') 58 | end 59 | p:addline(ln, 'black') 60 | p:addline(tk, 'black') 61 | p.units, p.clip = false, false 62 | return p 63 | end 64 | 65 | return plot_utils 66 | 67 | -------------------------------------------------------------------------------- /data/plot3d.lua: -------------------------------------------------------------------------------- 1 | 2 | local Pre3d = require 'pre3d.pre3d' 3 | local ShapeUtils = require 'pre3d.pre3d_shape_utils' 4 | 5 | local pi = math.pi 6 | local rgb = graph.rgb 7 | 8 | local function opt_gener(options, defaults) 9 | return function(name) 10 | local t = (options and options[name]) and options or defaults 11 | return t[name] 12 | end 13 | end 14 | 15 | local function set_transform(ct, rx, ry, dz) 16 | ct:reset() 17 | ct:rotateZ(0) 18 | ct:rotateX(rx) 19 | ct:rotateY(ry) 20 | ct:translate(0, 0, dz and -dz or -80) 21 | end 22 | 23 | local function render_shape(shape, plt, stroke) 24 | local renderer = Pre3d.Renderer(plt) 25 | 26 | renderer.draw_overdraw = true 27 | renderer.draw_backfaces = true 28 | renderer.fill_rgba = rgb(0x4A, 0x92, 0xBF) 29 | renderer.fill_rgba_backside = rgb(0xBF, 0x92, 0x4A) 30 | if stroke then renderer.stroke_rgba = rgb(50, 50, 50) end 31 | renderer.set_light_intensity = true 32 | 33 | renderer.camera.focal_length = 30; 34 | 35 | set_transform(renderer.camera.transform, -pi/2 + pi/16, -pi/16) 36 | 37 | renderer:bufferShape(shape) 38 | renderer:drawBuffer() 39 | renderer:emptyBuffer() 40 | 41 | return renderer 42 | end 43 | 44 | function graph.plot3d(f, x1, y1, x2, y2, options) 45 | local opt = opt_gener(options, {title= 'Pre3d', gridx= 20, gridy= 20}) 46 | 47 | local plt = graph.plot(opt 'title') 48 | local nx = opt 'gridx' 49 | local ny = opt 'gridy' 50 | 51 | local shape = ShapeUtils.makeXYFunction(f, x1, y1, x2, y2, nx, ny) 52 | 53 | render_shape(shape, plt, opt 'stroke') 54 | 55 | plt:show() 56 | return plt 57 | end 58 | 59 | function graph.surfplot(fs, u1, v1, u2, v2, options) 60 | local opt = opt_gener(options, {title= 'Pre3d', gridu= 20, gridv= 20}) 61 | 62 | local plt = graph.plot(opt 'title') 63 | local nu = opt 'gridu' 64 | local nv = opt 'gridv' 65 | 66 | local x, y, z = fs[1], fs[2], fs[3] 67 | local shape = ShapeUtils.makeUVSurface(x, y, z, u1, v1, u2, v2, nu, nv) 68 | 69 | render_shape(shape, plt, opt 'stroke') 70 | 71 | plt:show() 72 | return plt 73 | end 74 | -------------------------------------------------------------------------------- /data/project.lua: -------------------------------------------------------------------------------- 1 | local std_package_path, std_working_dir = package.path, filesystem.getcwd() 2 | 3 | local function deactivate() 4 | package.path = std_package_path 5 | filesystem.chdir(std_working_dir) 6 | end 7 | 8 | local function run(path, filename) 9 | if not filename then 10 | filename = path 11 | path = filename:match("(.*[/\\])") 12 | end 13 | if path then 14 | filesystem.chdir(path) 15 | package.path = std_package_path .. "?.lua;" .. package.path 16 | end 17 | dofile(filename) 18 | deactivate() 19 | end 20 | 21 | local function activate(dirname) 22 | local path = dirname:match("(.*)[/\\]?$") 23 | if path then 24 | filesystem.chdir(path) 25 | local dirsep = package.config:sub(1, 1) 26 | package.path = std_package_path .. dirsep .. "?.lua;" .. package.path 27 | end 28 | end 29 | 30 | return { 31 | run = run, 32 | activate = activate, 33 | deactivate = deactivate, 34 | } 35 | 36 | -------------------------------------------------------------------------------- /data/rnd.lua: -------------------------------------------------------------------------------- 1 | local template = require 'template' 2 | template.load('rnd-defs', {}) 3 | -------------------------------------------------------------------------------- /data/rng.lua: -------------------------------------------------------------------------------- 1 | 2 | local gsl = require 'gsl' 3 | local ffi = require 'ffi' 4 | 5 | local format, tonumber = string.format, tonumber 6 | 7 | local M = {} 8 | 9 | local rng_type = ffi.typeof('gsl_rng') 10 | 11 | local function rng_getint(r, seed) 12 | return tonumber(gsl.gsl_rng_uniform_int(r, seed)) 13 | end 14 | 15 | local rng_mt = { 16 | __tostring = function(s) 17 | return format("", s) 18 | end, 19 | 20 | __index = { 21 | getint = rng_getint, 22 | get = gsl.gsl_rng_uniform, 23 | set = gsl.gsl_rng_set, 24 | }, 25 | } 26 | 27 | ffi.metatype(rng_type, rng_mt) 28 | 29 | local function rng_type_lookup(s) 30 | if s then 31 | local ts = gsl.gsl_rng_types_setup() 32 | while ts[0] ~= nil do 33 | local t = ts[0] 34 | if ffi.string(t.name) == s then 35 | return t 36 | end 37 | ts = ts+1 38 | end 39 | error('unknown generator type: ' .. s) 40 | else 41 | return gsl.gsl_rng_default 42 | end 43 | end 44 | 45 | function M.new(s) 46 | local T = rng_type_lookup(s) 47 | return ffi.gc(gsl.gsl_rng_alloc(T), gsl.gsl_rng_free) 48 | end 49 | 50 | function M.list() 51 | local t = {} 52 | local ts = gsl.gsl_rng_types_setup() 53 | while ts[0] ~= nil do 54 | t[#t+1] = ffi.string(ts[0].name) 55 | ts = ts+1 56 | end 57 | return t 58 | end 59 | 60 | return M 61 | -------------------------------------------------------------------------------- /data/sf.lua: -------------------------------------------------------------------------------- 1 | local template = require 'template' 2 | template.load('sf-defs', {}) 3 | -------------------------------------------------------------------------------- /data/start.lua: -------------------------------------------------------------------------------- 1 | -- load initialization files for GSL Shell 2 | 3 | do 4 | EXEDIR = EXEFILE:match("^(.+)[/\\][^/\\]+$") 5 | local prefix = EXEDIR:match("^(.+)[/\\]bin$") 6 | if prefix then 7 | DATADIR = prefix .. '/share/gsl-shell' 8 | package.path = DATADIR .. '/?.lua;' .. package.path 9 | package.path = DATADIR .. '/?/init.lua;' .. package.path 10 | else 11 | DATADIR = EXEDIR .. '/lua' 12 | end 13 | end 14 | package.path = DATADIR .. '/templates/?.lua.in;' .. package.path 15 | 16 | require('base') 17 | iter = require('iter') 18 | matrix = require('matrix') 19 | complex = require('complex') 20 | eigen = require('eigen') 21 | num = require('num') 22 | rng = require('rng') 23 | require('rnd') 24 | require('integ-init') 25 | require('fft-init') 26 | if graph then 27 | require('graph-init') 28 | end 29 | randist = require('randist') 30 | require('import') 31 | require('sf') 32 | require('help') 33 | require('vegas') 34 | gdt = require('gdt') 35 | require('gdt-parse-csv') 36 | if graph then 37 | require('contour') 38 | require('gdt-hist') 39 | require('gdt-plot') 40 | end 41 | require('gdt-lm') 42 | require('gdt-interp') 43 | require('gdt-from-table') 44 | require('gdt-integrate') 45 | require('gdt-subsample') 46 | require('linfit') 47 | project = require('project') 48 | 49 | num.bspline = require 'bspline' 50 | 51 | local demomod 52 | 53 | function demo(name) 54 | if not demomod then demomod = require 'demo-init' end 55 | local entry = demomod.load(name) 56 | if not entry then 57 | demomod.list() 58 | else 59 | print(entry.description) 60 | entry.f() 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /data/time.lua: -------------------------------------------------------------------------------- 1 | 2 | local windows = jit.os == 'Windows' 3 | 4 | local ffi = require 'ffi' 5 | if windows then 6 | ffi.cdef[[ 7 | int GetTickCount(void); 8 | ]] 9 | else 10 | ffi.cdef[[ 11 | struct timeval { 12 | long tv_sec; 13 | long tv_usec; 14 | }; 15 | 16 | int gettimeofday(struct timeval * tp, void *tzp); 17 | ]] 18 | end 19 | 20 | local function mtime() 21 | if windows then 22 | return ffi.C.GetTickCount() 23 | else 24 | local tv = ffi.new('struct timeval[1]') 25 | ffi.C.gettimeofday(tv, nil) 26 | return tv[0].tv_sec * 1000 + (tv[0].tv_usec / 1000) 27 | end 28 | end 29 | 30 | return {ms= mtime} 31 | -------------------------------------------------------------------------------- /doc/gsl-shell-index/acknowledgments.rst: -------------------------------------------------------------------------------- 1 | Acknowledgments 2 | --------------- 3 | 4 | If GSL Shell exists is thanks to the many high quality free software projects on which it is based. 5 | 6 | The GSL library is an highly valuable library with a well designed API, good C coding and a complete and accurate documentation. 7 | It is the merit of the GSL library if many numerical algorithms are easily available for non-specialist FORTRAN programmers. 8 | 9 | The AGG library is another outstanding free software library that does leverage the C++ template systems to achieve graphical results of excellent quality with very good execution performances. 10 | 11 | Last, but not least, the LuaJIT2 made a really big difference with its outstanding JIT code generator. 12 | Thanks to LuaJIT2 it is possible to easily write code in Lua and achieve performances close to optimized C code. 13 | 14 | Luckily some people have kindly contributed some valuable implementations for GSL Shell, so many thanks to Lesley and Benjamin for their previous help. 15 | 16 | Finally I would like to thanks the Lua and LuaJIT mailing list, Mike Pall and the Lua authors for their advices and helps. 17 | 18 | Many thanks also to my wife, Gosia, for her patience and her support. 19 | -------------------------------------------------------------------------------- /doc/gsl-shell-index/authors.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _authors: 3 | 4 | Authors 5 | ======= 6 | 7 | The main author of GSL Shell is **Francesco Abbate**. He was so fearless that he learnt a completely undocumented library based on tons of C++ templates just to have nice looking plots. He jumped on the wagon of LuaJIT2 and throw away almost everything he did in two years of hard work to restart from zero with LuaJIT2 and the FFI interface. 8 | 9 | The VEGAS algorithm implementation is from **Lesley De Cruz**. Since he joined the project the author feels less lonely and knows that the user base of GSL Shell is of at least two people (including the authors). 10 | 11 | The new implementation of the Special Function and Eigensystem modules are from **Benjamin von Ardenne**. The author suspect it is a pseudonym of Lesley so that the author have the impression of having a huge user base (three users). 12 | 13 | The smart auto-complete function is based on the work of **Jesus Romero Hebrero**. Desperate about the bad English of Francesco he is currently striving to learn Italian and works on an integrated editor in the spare time. 14 | -------------------------------------------------------------------------------- /doc/gsl-shell-index/email-gslshell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/gsl-shell-index/email-gslshell.png -------------------------------------------------------------------------------- /doc/gsl-shell-index/gsl-shell-benchmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/gsl-shell-index/gsl-shell-benchmark.png -------------------------------------------------------------------------------- /doc/gsl-shell-index/why-donate.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: lua 2 | 3 | .. _why-donate: 4 | 5 | Why donate 6 | ========== 7 | 8 | GSL Shell is developed mainly by me, Francesco Abbate. The goal of this project is to develop an high quality free software for numerical computations and graphics. By high quality I mean: 9 | 10 | * *lightweight*, it should not require a ton of resources and take several minutes to start. Well written software can be small and the resources can be left to users for doing more useful things. 11 | * *well designed*, the interface should be designed so that it is simple to use but yet powerful and flexible to let you write complex functions with a compact syntax 12 | * *efficient*, most of the functions should be performed by using the computer resources in an optimal or near-optimal way 13 | * *reliable*, it should not crash or leak memory, quality before all as the most important parameter 14 | 15 | If you believe that this project is interesting and you want to support its development, then please donate. 16 | 17 | `Paypal `_ is the preferred way to donate and works for anyone no matter where they are from. 18 | 19 | .. raw:: html 20 | :file: donate.html 21 | 22 | What feature you would like to add 23 | ---------------------------------- 24 | 25 | If you donate you can also choose which feature should be implemented in GSL shell in the next development cycle. You can choose between the following items and communicate your choice to the author by email: 26 | 27 | * development of a full featured, openGL based, 3D graphics module 28 | * develoment of a Graphical User Interface module to generate easily user interface to interact with plots by using GSL Shell/Lua functions 29 | * developement of a most versatile plot class that allows to create customized axes labels and legends. 30 | * development of a postscript backend to generate image in PostScript or EPS format 31 | 32 | You can express in your choice also a feature that is not listed here. 33 | 34 | -------------------------------------------------------------------------------- /doc/user-manual/contour-plot-hyper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/contour-plot-hyper.png -------------------------------------------------------------------------------- /doc/user-manual/contour.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: lua 2 | 3 | .. include:: 4 | 5 | .. currentmodule:: graph 6 | 7 | Contour Plots 8 | ============= 9 | 10 | Overview 11 | -------- 12 | 13 | GSL shell offers a contour plot function to draw contour curves of bidimensional functions. The current algorithm works correctly only for continuous functions and it may give bad results if the function has discontinuities. 14 | 15 | Here is an example of its utilization to plot the function :math:`f(x,y) = x^2 - y^2`:: 16 | 17 | contour.plot(|x,y| x^2 - y^2, -8, -8, 8, 8) 18 | 19 | .. figure:: contour-plot-hyper.png 20 | 21 | .. module:: contour 22 | 23 | .. function:: plot(f, xmin, ymin, xmax, ymax[, options]) 24 | 25 | Plot a contour plot of the function ``f`` in the rectangle delimited by (xmin, ymin), (xmax, ymax) and return the plot itself. 26 | 27 | The ``options`` argument is an optional table that can contain the following fields: 28 | 29 | * ``gridx``, number of subdivision along x 30 | * ``gridy``, number of subdivision along y 31 | * ``levels``, number of contour levels or a list of the level values in monotonic order. 32 | * ``colormap`` a function that returns a color for the contour region. The argument of the function will be a number between 0 and 1. 33 | * ``show``, specify if the plot should be shown. By default it is ``true``. 34 | 35 | .. function:: polar_plot(f, R[, options]]) 36 | 37 | Plot a contour plot of the function ``f(x, y)`` over the circular domain of radius ``R`` and centered at the origin. The ``options`` table accepts the same fields as the function :func:`contour`. 38 | 39 | Example:: 40 | 41 | use 'math' 42 | 43 | p = contour.polar_plot(|x,y| cos(x)+cos(y)+0.1*x+0.3*y, 8) 44 | p.title = 'cos(x) + cos(y) + 0.1*x + 0.3*y' 45 | 46 | .. figure:: polar-contour-example-cos-cos.png 47 | -------------------------------------------------------------------------------- /doc/user-manual/cspline-example-bell-curve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/cspline-example-bell-curve.png -------------------------------------------------------------------------------- /doc/user-manual/csv.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: lua 2 | 3 | .. _csv-section: 4 | 5 | Comma Separated Values Parsing Utilities 6 | ======================================== 7 | 8 | .. module:: csv 9 | 10 | The module ``csv`` offers a few useful functions to read data files in 'csv' format. This latter is a quite popular format used to easily save simple tabular data as comma-separated values with several lines. This format can be used to exchange data with spreadsheets applications. 11 | 12 | .. function:: read(filename) 13 | 14 | Reads the given filename and returns a table that stores the values from the given file (``filename`` argument). The table returned is in the form ``{{row1_v1, row1_v2, ...}, {row2_v1, row2_v2, ...}, ...}`` so that you can obtain the number of lines read by using the ``#`` operator (number of elements in a table). The table can contain both numeric values or strings in accordance with the csv specifications. Each row can potentially contain a different number of elements. The user can check the number of elements of each row if needed. 15 | 16 | Here an example of utilization:: 17 | 18 | csv = require 'csv' 19 | 20 | -- load some data and save the results in a table 21 | t = csv.read('examples/data/sige-sims-prof.csv') 22 | 23 | -- if the data contains only numbers it can be easily converted 24 | -- intro matrix form 25 | m = matrix.def(t) 26 | 27 | -- using the matrix m is very easy to plot the data 28 | p = graph.plot("SiGe SIMS profile") 29 | p:addline(graph.xyline(m:col(1), m:col(2)), 'blue') 30 | p:show() 31 | 32 | Please note that the function returns a table, not a matrix. If the table is in rectangular form and if it contains only numbers, it can easily be converted into a matrix using the function :func:`matrix` as shown in the example above. 33 | 34 | .. function:: line(str) 35 | 36 | This function splits the string ``str`` using commas as separators in accordance with the csv format specifications. This function can be useful to build a customized csv parser. 37 | -------------------------------------------------------------------------------- /doc/user-manual/example-bessJ-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/example-bessJ-plot.png -------------------------------------------------------------------------------- /doc/user-manual/example-bsplines-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/example-bsplines-plot.png -------------------------------------------------------------------------------- /doc/user-manual/example-linfit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/example-linfit.png -------------------------------------------------------------------------------- /doc/user-manual/example-vtiled-plots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/example-vtiled-plots.png -------------------------------------------------------------------------------- /doc/user-manual/examples-airy-functions-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/examples-airy-functions-plot.png -------------------------------------------------------------------------------- /doc/user-manual/examples-legendre-polynomials.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/examples-legendre-polynomials.png -------------------------------------------------------------------------------- /doc/user-manual/examples-levy-c-curve-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/examples-levy-c-curve-1.png -------------------------------------------------------------------------------- /doc/user-manual/examples-levy-c-curve-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/examples-levy-c-curve-2.png -------------------------------------------------------------------------------- /doc/user-manual/examples-von-koch-complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/examples-von-koch-complete.png -------------------------------------------------------------------------------- /doc/user-manual/examples-von-koch-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/examples-von-koch-plot.png -------------------------------------------------------------------------------- /doc/user-manual/fft-example-power-spectrum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/fft-example-power-spectrum.png -------------------------------------------------------------------------------- /doc/user-manual/fft-example-time-signal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/fft-example-time-signal.png -------------------------------------------------------------------------------- /doc/user-manual/filesystem.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: lua 2 | 3 | .. _import-section: 4 | 5 | Filesystem Functions 6 | ==================== 7 | 8 | The module :mod:`filesystem` contains some functions for basic filesystem operations. 9 | 10 | Overview 11 | -------- 12 | 13 | .. module:: filesystem 14 | 15 | .. function:: getcwd() 16 | 17 | Returns the name of the current working directory. 18 | 19 | .. function:: chdir(dirname) 20 | 21 | Change the working directory to `dirname`. 22 | 23 | .. function:: list_dir(dirname) 24 | 25 | Returns a table with the name of the files or directory in the directory `dirname`. 26 | 27 | .. function:: get_file_info(filename) 28 | 29 | Returns a table with `filename` file's or directory's information. 30 | The table will include the fields `type`. It will have the value `file` or `dir`. 31 | Other fields will be `modified` and `size` and, on linux only, `symlink`. 32 | 33 | -------------------------------------------------------------------------------- /doc/user-manual/gdt-boxplot-example-exam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-boxplot-example-exam.png -------------------------------------------------------------------------------- /doc/user-manual/gdt-hist-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-hist-example.png -------------------------------------------------------------------------------- /doc/user-manual/gdt-lm-plot-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-lm-plot-example.png -------------------------------------------------------------------------------- /doc/user-manual/gdt-plot-exam-by-sex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-plot-exam-by-sex.png -------------------------------------------------------------------------------- /doc/user-manual/gdt-plot-exam-m2-final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-plot-exam-m2-final.png -------------------------------------------------------------------------------- /doc/user-manual/gdt-plot-exam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-plot-exam.png -------------------------------------------------------------------------------- /doc/user-manual/gdt-plot-perf-filter-mandel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-plot-perf-filter-mandel.png -------------------------------------------------------------------------------- /doc/user-manual/gdt-reduce-exam-example-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/gdt-reduce-exam-example-plot.png -------------------------------------------------------------------------------- /doc/user-manual/general.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: lua 2 | 3 | .. _import-section: 4 | 5 | General Purpose Functions 6 | ========================= 7 | 8 | Overview 9 | -------- 10 | 11 | .. function:: use(name) 12 | 13 | Makes the functions defined in the module "name" accessible in the global namespace. 14 | If the function :func:`use` is used in a separate file, its effect is limited to the file itself and the functions that it calls. 15 | When the function is used from the interactive shell, the global environment is affected. 16 | 17 | As a special case When called with 'strict' as its argument the use of undeclared global variables will be checked. 18 | When active all global variables must be declared through a regular assignment (even assigning nil will do) in a main chunk before being used anywhere or assigned to inside a function. 19 | 20 | The 'strict' mode is encouraged since it can prevent many common errors of unintentional use of global variables. 21 | 22 | .. function:: restore_env() 23 | 24 | This function restores the original environment by removing the effect of all the :func:`use` calls made before. 25 | 26 | .. function:: gsl_type(x) 27 | 28 | This function is an extension of the standard Lua function "type". 29 | It does returns the same string of the "type" function except when the argument is a GSL object. 30 | When this happens it does return a string corresponding to its actual type instead of "userdata" or "cdata". 31 | For complex number and real or complex matrix it does return respectively "complex", "matrix" and "complex matrix". 32 | 33 | .. function:: help(obj) 34 | 35 | Print some help, if available, about the given object or function. 36 | In the first line it will be shown how the function should be called. 37 | If the function have some optional parameters these will be shown inside square brackets. 38 | -------------------------------------------------------------------------------- /doc/user-manual/graphics-categories-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/graphics-categories-example.png -------------------------------------------------------------------------------- /doc/user-manual/graphics-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/graphics-example-1.png -------------------------------------------------------------------------------- /doc/user-manual/graphics-example-ibars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/graphics-example-ibars.png -------------------------------------------------------------------------------- /doc/user-manual/graphics-example-yellow-area.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/graphics-example-yellow-area.png -------------------------------------------------------------------------------- /doc/user-manual/index.rst: -------------------------------------------------------------------------------- 1 | ################################## 2 | Welcome to GSL shell documentation 3 | ################################## 4 | 5 | GSL shell is an interactive command line interface that provides easy access 6 | to the GNU Scientific Library (GSL) collection of mathematical methods for 7 | numerical computations. 8 | 9 | GSL shell can be used interactively to perform calculations with matrices or 10 | vectors but it also allows for complex user-defined functions with the Lua 11 | scripting interpreter. 12 | 13 | Lua is a very interesting and easy to learn scripting language that features 14 | advanced functionalities like closures and metamethods. Lua is very 15 | easy to learn and will give you the power of defining your own complex routines 16 | to use the GSL library more effectively. 17 | 18 | `GSL Shell github project `_. 19 | 20 | Contents: 21 | 22 | .. toctree:: 23 | :maxdepth: 2 24 | 25 | intro.rst 26 | general.rst 27 | project.rst 28 | filesystem.rst 29 | complex.rst 30 | matrices.rst 31 | gdt.rst 32 | lua-base.rst 33 | linalg.rst 34 | eigen.rst 35 | random.rst 36 | randist.rst 37 | pdf.rst 38 | linfit.rst 39 | nlinfit.rst 40 | bsplines.rst 41 | fft.rst 42 | ode.rst 43 | integ.rst 44 | sf.rst 45 | vegas.rst 46 | graphics.rst 47 | plot3d.rst 48 | contour.rst 49 | csv.rst 50 | record.rst 51 | interp2d.rst 52 | examples.rst 53 | gsl-ffi.rst 54 | -------------------------------------------------------------------------------- /doc/user-manual/intro-example.lua: -------------------------------------------------------------------------------- 1 | use 'math' 2 | use 'iter' 3 | 4 | local function getunitsphere(n) 5 | return function(x) 6 | local s = 0 7 | for k= 1, n do s = s + x[k]^2 end 8 | return s < 1 and 1 or 0 9 | end 10 | end 11 | 12 | local ln = graph.path(1, 2) -- 1-sphere = [-1, 1] (length 2) 13 | local max_dim = 14 14 | 15 | --Calculating the volume of d-dimensional sphere 16 | for d=2, max_dim do 17 | --Intializing work varaibles 18 | local a, b = ilist(|| 0, d), ilist(|| 1, d) 19 | local calls, n = d*1e4,1 20 | local vegas_integ = num.vegas_prepare({N=d}) 21 | 22 | --Obtaining monte carlo vegas callback 23 | local res,sig,num,cont = vegas_integ(getunitsphere(d),a,b,calls) 24 | local fmt = "Volume = %.3f +/- %.3f " 25 | print(string.format(fmt,res*2^d,sig*2^d)) 26 | 27 | --Increasing the number of calls to reach a satisfying result 28 | while(sig/res > 0.005) do 29 | print("Increasing accuracy, doubling number of calls...") 30 | res,sig,num = cont(calls*(2^n)) 31 | print(string.format(fmt,res*2^d,sig*2^d)) 32 | n=n+1 33 | end 34 | ln:line_to(d,res*2^d) 35 | end 36 | 37 | --plotting a comparison of the numerical result with the analytical solution 38 | local p = graph.plot('Volume of a unit n-sphere') 39 | p.clip, p.pad = false, true 40 | p:addline(graph.fxline(|n| math.pi^(n/2) / sf.gamma(1+n/2), 1, max_dim)) 41 | p:add(ln, "blue", {{'marker', size=8}}) 42 | p.xtitle="n" 43 | p.ytitle="V" 44 | p:show() 45 | -------------------------------------------------------------------------------- /doc/user-manual/intro-first-step-plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/intro-first-step-plot-1.png -------------------------------------------------------------------------------- /doc/user-manual/intro-first-step-plot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/intro-first-step-plot-2.png -------------------------------------------------------------------------------- /doc/user-manual/intro-first-step-plot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/intro-first-step-plot-3.png -------------------------------------------------------------------------------- /doc/user-manual/lmfit-enso-dataset-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/lmfit-enso-dataset-plot.png -------------------------------------------------------------------------------- /doc/user-manual/nlinfit-example-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/nlinfit-example-plot.png -------------------------------------------------------------------------------- /doc/user-manual/ode-integration-quasi-spiral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/ode-integration-quasi-spiral.png -------------------------------------------------------------------------------- /doc/user-manual/plot-intro-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/plot-intro-example.png -------------------------------------------------------------------------------- /doc/user-manual/plot3d-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/plot3d-example-1.png -------------------------------------------------------------------------------- /doc/user-manual/polar-contour-example-cos-cos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/polar-contour-example-cos-cos.png -------------------------------------------------------------------------------- /doc/user-manual/project.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: lua 2 | 3 | .. _project-section: 4 | 5 | Projects Utility Functions 6 | ========================== 7 | 8 | .. module:: project 9 | 10 | The module ``project`` offers a few useful functions to execute the entry point of a project organized like a 11 | set of Lua scripts in a folder. 12 | 13 | .. function:: run([path, ]filename) 14 | 15 | Move into the directory `path`, add it into the `package.path` and execute the given `filename` using 16 | the Lua function `dofile`. When the script has completed the execution restore the original `package.path` 17 | and goes back to the previous working directory. 18 | 19 | If the function is called with a single argument the directory containing `filename` will be used for `path`. 20 | 21 | The advantage over a simple `dofile` is that the Lua scripts presents in the project's directory will be 22 | available to be loaded using the `require` function. In this way there is no need to give explicit path of 23 | the modules' filename. 24 | 25 | .. function:: activate(path) 26 | 27 | It acts like the function :func:`project.run` but do not execute any file. 28 | 29 | -------------------------------------------------------------------------------- /doc/user-manual/sf-bessel-Y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/sf-bessel-Y.png -------------------------------------------------------------------------------- /doc/user-manual/sf-besselJ-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/sf-besselJ-functions.png -------------------------------------------------------------------------------- /doc/user-manual/sige-plot-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/sige-plot-example.png -------------------------------------------------------------------------------- /doc/user-manual/simpler-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/simpler-example-1.png -------------------------------------------------------------------------------- /doc/user-manual/simpler-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/simpler-example-2.png -------------------------------------------------------------------------------- /doc/user-manual/simpler-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/simpler-example-3.png -------------------------------------------------------------------------------- /doc/user-manual/split-window-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/split-window-example.png -------------------------------------------------------------------------------- /doc/user-manual/square-circle-homeomorphism.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/square-circle-homeomorphism.png -------------------------------------------------------------------------------- /doc/user-manual/surfplot-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/surfplot-example-1.png -------------------------------------------------------------------------------- /doc/user-manual/vegas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/vegas.png -------------------------------------------------------------------------------- /doc/user-manual/zernicke-contour-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/zernicke-contour-3-1.png -------------------------------------------------------------------------------- /doc/user-manual/zernicke-contour-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/zernicke-contour-5-1.png -------------------------------------------------------------------------------- /doc/user-manual/zernicke-contour-5-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/zernicke-contour-5-5.png -------------------------------------------------------------------------------- /doc/user-manual/zernicke-contour-8-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/doc/user-manual/zernicke-contour-8-2.png -------------------------------------------------------------------------------- /examples/am-women-weight.csv: -------------------------------------------------------------------------------- 1 | height,weight 2 | 1.47,52.21 3 | 1.5,53.12 4 | 1.52,54.48 5 | 1.55,55.84 6 | 1.57,57.2 7 | 1.6,58.57 8 | 1.63,59.93 9 | 1.65,61.29 10 | 1.68,63.11 11 | 1.7,64.47 12 | 1.73,66.28 13 | 1.75,68.1 14 | 1.78,69.92 15 | 1.8,72.19 16 | 1.83,74.46 17 | -------------------------------------------------------------------------------- /examples/exam.csv: -------------------------------------------------------------------------------- 1 | student,teacher,sex,m1,m2,final 2 | S-1,john,male,56,42,58 3 | S-2,john,male,96,90,91 4 | S-3,john,male,70,59,65 5 | S-4,john,male,82,75,78 6 | S-5,john,male,85,90,92 7 | S-6,john,male,69,60,65 8 | S-7,john,female,82,78,60 9 | S-8,john,female,84,81,82 10 | S-9,john,female,89,80,68 11 | S-10,john,female,90,93,91 12 | S-11,jane,male,42,46,65 13 | S-12,jane,male,28,15,34 14 | S-13,jane,male,49,68,75 15 | S-14,jane,male,36,30,48 16 | S-15,jane,male,58,58,62 17 | S-16,jane,male,72,70,84 18 | S-17,jane,female,65,61,70 19 | S-18,jane,female,68,75,71 20 | S-19,jane,female,62,50,55 21 | S-20,jane,female,71,72,87 22 | -------------------------------------------------------------------------------- /examples/metro-lm-example.csv: -------------------------------------------------------------------------------- 1 | tool,x,y 2 | tool A,0,2.74018 3 | tool A,0.1,2.79357 4 | tool A,0.2,3.44232 5 | tool A,0.3,3.28009 6 | tool A,0.4,3.47926 7 | tool A,0.5,2.91675 8 | tool A,0.6,2.70099 9 | tool A,0.7,3.33622 10 | tool A,0.8,3.64827 11 | tool A,0.9,4.04807 12 | tool A,1,3.89471 13 | tool A,1.1,3.63103 14 | tool A,1.2,3.93961 15 | tool A,1.3,4.31451 16 | tool A,1.4,4.62932 17 | tool A,1.5,4.33553 18 | tool A,1.6,4.42859 19 | tool A,1.7,4.74213 20 | tool A,1.8,4.65904 21 | tool A,1.9,4.73167 22 | tool A,2,5.28375 23 | tool A,2.1,5.10972 24 | tool A,2.2,5.25315 25 | tool A,2.3,5.18494 26 | tool A,2.4,5.40486 27 | tool A,2.5,5.71938 28 | tool A,2.6,5.83402 29 | tool A,2.7,5.71478 30 | tool A,2.8,6.01673 31 | tool A,2.9,6.62267 32 | tool B,0,2.93806 33 | tool B,0.1,3.04179 34 | tool B,0.2,3.19853 35 | tool B,0.3,2.59698 36 | tool B,0.4,3.65323 37 | tool B,0.5,3.58917 38 | tool B,0.6,3.65215 39 | tool B,0.7,4.0545 40 | tool B,0.8,4.43318 41 | tool B,0.9,3.96232 42 | tool B,1,4.55483 43 | tool B,1.1,4.85793 44 | tool B,1.2,4.2206 45 | tool B,1.3,4.37105 46 | tool B,1.4,5.30121 47 | tool B,1.5,4.5291 48 | tool B,1.6,5.44066 49 | tool B,1.7,5.45493 50 | tool B,1.8,5.04739 51 | tool B,1.9,5.18871 52 | tool B,2,5.77607 53 | tool B,2.1,5.43785 54 | tool B,2.2,5.6261 55 | tool B,2.3,5.99969 56 | tool B,2.4,6.04199 57 | tool B,2.5,6.02576 58 | tool B,2.6,6.52659 59 | tool B,2.7,6.24416 60 | tool B,2.8,6.58541 61 | tool B,2.9,6.00753 62 | tool C,0,0.928787 63 | tool C,0.1,1.22095 64 | tool C,0.2,1.21612 65 | tool C,0.3,1.19774 66 | tool C,0.4,1.06587 67 | tool C,0.5,2.11497 68 | tool C,0.6,1.84543 69 | tool C,0.7,2.29749 70 | tool C,0.8,2.16594 71 | tool C,0.9,1.90343 72 | tool C,1,2.59502 73 | tool C,1.1,2.0701 74 | tool C,1.2,2.67219 75 | tool C,1.3,2.31895 76 | tool C,1.4,2.65437 77 | tool C,1.5,3.24886 78 | tool C,1.6,3.03933 79 | tool C,1.7,4.04153 80 | tool C,1.8,3.70028 81 | tool C,1.9,3.80688 82 | tool C,2,3.60024 83 | tool C,2.1,3.20495 84 | tool C,2.2,3.73881 85 | tool C,2.3,3.89652 86 | tool C,2.4,3.1759 87 | tool C,2.5,3.81583 88 | tool C,2.6,3.47146 89 | tool C,2.7,3.9396 90 | tool C,2.8,4.22132 91 | tool C,2.9,4.23473 92 | -------------------------------------------------------------------------------- /examples/perf-julia.csv: -------------------------------------------------------------------------------- 1 | test,language,time.c 2 | fib,Fortran,0.28 3 | parse_int,Fortran,9.22 4 | quicksort,Fortran,1.65 5 | mandel,Fortran,0.76 6 | pi_sum,Fortran,1 7 | rand_mat_stat,Fortran,2.23 8 | rand_mat_mul,Fortran,1.14 9 | fib,Julia,1.97 10 | parse_int,Julia,1.72 11 | quicksort,Julia,1.37 12 | mandel,Julia,1.45 13 | pi_sum,Julia,1 14 | rand_mat_stat,Julia,1.95 15 | rand_mat_mul,Julia,1 16 | fib,Python,46.03 17 | parse_int,Python,25.29 18 | quicksort,Python,69.2 19 | mandel,Python,34.88 20 | pi_sum,Python,33.64 21 | rand_mat_stat,Python,29.01 22 | rand_mat_mul,Python,1.75 23 | fib,Matlab,1587.03 24 | parse_int,Matlab,846.67 25 | quicksort,Matlab,133.46 26 | mandel,Matlab,74.61 27 | pi_sum,Matlab,1.46 28 | rand_mat_stat,Matlab,7.71 29 | rand_mat_mul,Matlab,1.08 30 | fib,Octave,2748.74 31 | parse_int,Octave,7364.87 32 | quicksort,Octave,3341.94 33 | mandel,Octave,988.74 34 | pi_sum,Octave,457.26 35 | rand_mat_stat,Octave,31.04 36 | rand_mat_mul,Octave,1.93 37 | fib,R,275.63 38 | parse_int,R,353.48 39 | quicksort,R,708.76 40 | mandel,R,184.71 41 | pi_sum,R,253.45 42 | rand_mat_stat,R,12.66 43 | rand_mat_mul,R,9.58 44 | fib,JavaScript,2.09 45 | parse_int,JavaScript,2.55 46 | quicksort,JavaScript,4.95 47 | mandel,JavaScript,7.62 48 | pi_sum,JavaScript,1.12 49 | rand_mat_stat,JavaScript,5.53 50 | rand_mat_mul,JavaScript,45.82 51 | -------------------------------------------------------------------------------- /include/completion.h: -------------------------------------------------------------------------------- 1 | #ifndef GSL_SHELL_COMPLETION_H 2 | #define GSL_SHELL_COMPLETION_H 3 | 4 | extern void initialize_readline(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/defs.h.in: -------------------------------------------------------------------------------- 1 | 2 | /* defs.h 3 | * 4 | * Copyright (C) 2009 Francesco Abbate 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or (at 9 | * your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef DEFS_H 22 | #define DEFS_H 23 | 24 | #undef __BEGIN_DECLS 25 | #undef __END_DECLS 26 | #ifdef __cplusplus 27 | # define __BEGIN_DECLS extern "C" { 28 | # define __END_DECLS } 29 | #else 30 | # define __BEGIN_DECLS /* empty */ 31 | # define __END_DECLS /* empty */ 32 | #endif 33 | 34 | #define LUA_INDEX_CONVENTION 35 | #define GSL_SHELL_RELEASE "@version@" 36 | #define GSL_SHELL_COPYRIGHT "@copyright@" 37 | 38 | #ifdef _WIN32 39 | #ifndef __cplusplus 40 | #undef bool 41 | typedef int bool; 42 | #define false 0 43 | #define true 1 44 | #endif 45 | #else 46 | /* linux */ 47 | #include 48 | #endif 49 | 50 | #define likely(x) __builtin_expect(!!(x), 1) 51 | #define unlikely(x) __builtin_expect(!!(x), 0) 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /include/gsl-shell.h: -------------------------------------------------------------------------------- 1 | #ifndef GSL_SHELL_INCLUDED 2 | #define GSL_SHELL_INCLUDED 3 | 4 | #include "defs.h" 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | extern lua_State *globalL; 10 | 11 | __END_DECLS 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /include/lua-filesystem.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_FILESYSTEM_H 2 | #define LUA_FILESYSTEM_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include 9 | 10 | extern int luaopen_filesystem (lua_State *L); 11 | 12 | __END_DECLS 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/lua-graph.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_GRAPH_H 2 | #define LUA_GRAPH_H 3 | 4 | #include 5 | 6 | #include "defs.h" 7 | 8 | __BEGIN_DECLS 9 | 10 | #include 11 | 12 | extern void graph_close_windows (lua_State *L); 13 | extern int register_graph (lua_State *L); 14 | extern void gsl_shell_close_with_graph (struct gsl_shell_state* gs, int send_close_req); 15 | 16 | extern int initialize_fonts(lua_State* L); 17 | 18 | extern pthread_mutex_t agg_mutex[1]; 19 | 20 | #define AGG_LOCK() pthread_mutex_lock (agg_mutex); 21 | #define AGG_UNLOCK() pthread_mutex_unlock (agg_mutex); 22 | 23 | __END_DECLS 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/lua-gsl.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_GSL_H 2 | #define LUA_GSL_H 3 | 4 | #include 5 | 6 | #include "defs.h" 7 | 8 | __BEGIN_DECLS 9 | 10 | #include 11 | 12 | struct gsl_shell_state { 13 | lua_State *L; 14 | pthread_mutex_t exec_mutex; 15 | pthread_mutex_t shutdown_mutex; 16 | int is_shutting_down; 17 | }; 18 | 19 | extern void gsl_shell_open (struct gsl_shell_state *gs); 20 | extern void gsl_shell_free (struct gsl_shell_state *gs); 21 | extern void gsl_shell_init (struct gsl_shell_state *gs); 22 | 23 | extern void run_start_script(lua_State *L); 24 | 25 | extern int luaopen_gsl (lua_State *L); 26 | 27 | extern struct gsl_shell_state* global_state; 28 | 29 | __END_DECLS 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/meson.build: -------------------------------------------------------------------------------- 1 | configure_file(input : 'defs.h.in', output : 'defs.h', configuration : conf_data) 2 | 3 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('gsl-shell', ['cpp', 'c'], version : '2.3.7', default_options : ['cpp_std=c++11', 'c_std=gnu11']) 2 | 3 | gsl_shell_defines = [ 4 | # '-DDISABLE_GAMMA_CORR', 5 | # '-DDISABLE_SUBPIXEL_AA', 6 | # '-DUSE_READLINE', 7 | ] 8 | 9 | conf_data = configuration_data() 10 | conf_data.set('version', meson.project_version()) 11 | conf_data.set('copyright', 'Copyright (C) 2009-2022 Francesco Abbate') 12 | 13 | if host_machine.system() == 'darwin' 14 | gsl_shell_defines += '-DDARWIN_MACOSX' 15 | endif 16 | 17 | gsl_shell_link_args = [] 18 | cc = meson.get_compiler('c') 19 | if cc.get_id() == 'gcc' and get_option('buildtype') == 'release' 20 | gsl_shell_link_args += ['-static-libgcc', '-static-libstdc++'] 21 | endif 22 | 23 | gsl_shell_include = include_directories('include', 'src/gdt', 'src/agg-plot', 'src/lua-gsl') 24 | cpp_utils_include = include_directories('src/cpp-utils') 25 | 26 | threads_dep = dependency('threads') 27 | freetype_dep = dependency('freetype2') 28 | libagg_dep = dependency('libagg', fallback: ['libagg', 'libagg_dep']) 29 | 30 | fox_project = subproject('fox', default_options: ['apps=false', 'default_library=static', 'opengl=false']) 31 | fox_dep = fox_project.get_variable('libfox_dep') 32 | 33 | luajit_proj = subproject('luajit', default_options: ['default_library=static', 'app=false', 'portable=true', 'shortfnsyn=true']) 34 | luajit_dep = luajit_proj.get_variable('lua_dep') 35 | 36 | libgsl_options = ['default_library=static', 'blas=' + get_option('blas')] 37 | foreach module_name : ['siman', 'wavelet', 'sparse', 'ode', 'monte', 'integ', 'min', 'fit'] 38 | libgsl_options += module_name + '=false' 39 | endforeach 40 | 41 | libgsl_proj = subproject('gsl', default_options: libgsl_options) 42 | libgsl_dep = libgsl_proj.get_variable('libgsl_dep').as_link_whole() 43 | 44 | gsl_shell_bindir = 'bin' 45 | gsl_shell_datadir = 'share/gsl-shell' 46 | install_subdir('data', strip_directory : true, install_dir : gsl_shell_datadir) 47 | 48 | subdir('include') 49 | subdir('src') 50 | 51 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('blas', type : 'string', value : 'internal', description: 'cblas library to use for GSL') 2 | 3 | -------------------------------------------------------------------------------- /resources/gsl-shell-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/resources/gsl-shell-128.png -------------------------------------------------------------------------------- /resources/gsl-shell-256.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/resources/gsl-shell-256.gif -------------------------------------------------------------------------------- /resources/gsl-shell-32.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/resources/gsl-shell-32.gif -------------------------------------------------------------------------------- /resources/gsl-shell.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=GSL Shell 3 | Comment=Mathematical Shell using Lua and GSL library 4 | Keywords=mathematics;gsl;lua;statistics;graphics; 5 | Exec=gsl-shell-gui %u 6 | X-MultipleArgs=false 7 | Icon=gsl-shell 8 | Terminal=false 9 | Type=Application 10 | Categories=Development; 11 | Actions=OpenWindow; 12 | 13 | X-Desktop-File-Install-Version=0.21 14 | 15 | [Desktop Action OpenWindow] 16 | Name=Open New Window 17 | Exec=gsl-shell-gui 18 | 19 | -------------------------------------------------------------------------------- /resources/lhelper.build: -------------------------------------------------------------------------------- 1 | lhelper install libagg 2 | lhelper install freetype2 3 | lhelper install fox 4 | lhelper install openblas 5 | lhelper install gsl -shared -blas=openblas 2.1-ms 6 | 7 | -------------------------------------------------------------------------------- /scripts/dos2unix.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import re 4 | import sys 5 | 6 | def dos2unix(filename): 7 | tmp_filename = filename + '.tmp' 8 | 9 | try: 10 | fsrc = open(filename, "rb") 11 | fdst = open(tmp_filename, "wb") 12 | for ln in fsrc: 13 | lnu = re.sub(r'\015\n', '\n', ln) 14 | fdst.write(lnu) 15 | fsrc.close() 16 | fdst.close() 17 | except OSError as err: 18 | print 'Error', err.strerror 19 | else: 20 | try: 21 | os.unlink(filename) 22 | os.rename(tmp_filename, filename) 23 | except OSError as err: 24 | print 'Error', err.strerror 25 | 26 | for filename in sys.argv[1:]: 27 | inf = os.popen("file " + filename, "r") 28 | for ln in inf: 29 | if re.search(r'with CRLF line terminators', ln): 30 | dos2unix(filename) 31 | break 32 | else: 33 | print "File ", filename, "not in DOS format" 34 | 35 | -------------------------------------------------------------------------------- /scripts/repackage-appimage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | set -e 3 | 4 | archive_file="$(realpath "$1")" 5 | 6 | workdir=".repackage" 7 | rm -fr "$workdir" && mkdir "$workdir" && pushd "$workdir" 8 | 9 | ARCH="x86_64" 10 | 11 | create_appimage() { 12 | rm -fr GSLShell.AppDir 13 | 14 | echo "Creating GSLShell.AppDir..." 15 | 16 | mkdir -p GSLShell.AppDir/usr 17 | tar xf "$1" -C GSLShell.AppDir/usr --strip-components=1 18 | mv GSLShell.AppDir/usr/gsl-shell.desktop GSLShell.AppDir 19 | mv GSLShell.AppDir/usr/gsl-shell.svg GSLShell.AppDir 20 | cp AppRun GSLShell.AppDir/ 21 | pushd GSLShell.AppDir 22 | strip AppRun 23 | popd 24 | 25 | echo "Generating AppImage..." 26 | local appimg_basename="$(basename "$1")" 27 | local appimg_dirname="$(dirname "$1")" 28 | local appimage_name="${appimg_dirname}/${appimg_basename/gsl-shell-/GSLShell-}" 29 | appimage_name="${appimage_name/-linux/}" 30 | appimage_name="${appimage_name/%.tar.gz/.AppImage}" 31 | 32 | ./appimagetool GSLShell.AppDir "$appimage_name" 33 | } 34 | 35 | setup_appimagetool() { 36 | if ! which appimagetool > /dev/null ; then 37 | if [ ! -e appimagetool ]; then 38 | if ! wget -O appimagetool "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-${ARCH}.AppImage" ; then 39 | echo "Could not download the appimagetool for the arch '${ARCH}'." 40 | exit 1 41 | else 42 | chmod 0755 appimagetool 43 | fi 44 | fi 45 | fi 46 | } 47 | 48 | download_appimage_apprun() { 49 | if [ ! -e AppRun ]; then 50 | if ! wget -O AppRun "https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-${ARCH}" ; then 51 | echo "Could not download AppRun for the arch '${ARCH}'." 52 | exit 1 53 | else 54 | chmod 0755 AppRun 55 | fi 56 | fi 57 | } 58 | 59 | setup_appimagetool 60 | download_appimage_apprun 61 | create_appimage "$archive_file" 62 | 63 | -------------------------------------------------------------------------------- /scripts/run-local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | 5 | exe_name=gsl-shell-gui 6 | 7 | pargs=() 8 | while [[ "$#" -gt 0 ]]; do 9 | case $1 in 10 | -console) 11 | exe_name=gsl-shell 12 | ;; 13 | -unix) 14 | use_unix=yes 15 | ;; 16 | -*) 17 | echo "error: unknown option \"$1\"" 18 | exit 1 19 | ;; 20 | *) 21 | pargs+=("$1") 22 | ;; 23 | esac 24 | shift 25 | done 26 | 27 | if [ "${#pargs[@]}" -lt 1 ]; then 28 | echo "usage: $0 [options] " 29 | exit 1 30 | fi 31 | 32 | ext="" 33 | if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then 34 | ext=".exe" 35 | fi 36 | 37 | builddir="${pargs[0]}" 38 | 39 | rundir=".run" 40 | if [ -z ${use_unix+x} ]; then 41 | bindir="$rundir" 42 | datadir="$rundir/lua" 43 | else 44 | bindir="$rundir/bin" 45 | datadir="$rundir/share/gsl-shell" 46 | fi 47 | 48 | ninja -C "$builddir" 49 | 50 | rm -fr "$rundir" 51 | mkdir -p "$bindir" "$datadir" 52 | cp "$builddir/src/console/gsl-shell$ext" "$bindir" 53 | cp "$builddir/src/fox-gui/gsl-shell-gui$ext" "$bindir" 54 | cp -r data/. "$datadir" 55 | 56 | "$bindir/$exe_name" 57 | 58 | -------------------------------------------------------------------------------- /scripts/ubuntu-build.yml: -------------------------------------------------------------------------------- 1 | image: ubuntu/18.04 2 | secrets: 3 | - 4 | packages: 5 | # xorg-dev can be used instead of the detailed list of x11 libraries 6 | # fuse needed to create appimage 7 | [python3-pip, fuse, make, ninja-build, pkg-config, libx11-dev, libxext-dev, libxrandr-dev, libxrender-dev, libxcursor-dev, libxfixes-dev, libxi-dev, libxft-dev, gcc, g++, gfortran] 8 | sources: 9 | - https://github.com/franko/gsl-shell 10 | - https://github.com/franko/lhelper 11 | tasks: 12 | - enable-local: | 13 | echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.buildenv" 14 | ssh-keyscan lhelper.cc >> ~/.ssh/known_hosts 15 | - prepare-setup: | 16 | pip3 install --user meson 17 | - lhelper-install: | 18 | cd lhelper 19 | bash install "$HOME/.local" 20 | - build: | 21 | cd gsl-shell 22 | lhelper create --upload build 23 | source "$(lhelper env-source build)" 24 | bash scripts/build-package.sh -appimage -name=dynamic -openblas -unix 25 | - build-gslcblas: | 26 | cd gsl-shell 27 | lhelper create --upload build-gslcblas 28 | source "$(lhelper env-source build-gslcblas)" 29 | bash scripts/build-package.sh -appimage -unix 30 | - build-openblas-static: | 31 | cd gsl-shell 32 | lhelper create --upload build-openblas-static 33 | source "$(lhelper env-source build-openblas-static)" 34 | bash scripts/build-package.sh -appimage -openblas -unix 35 | - build-cpu-specific: | 36 | cd gsl-shell 37 | for cpu_target in nehalem haswell skylake; do 38 | ( 39 | export CPU_TYPE=x86-64 40 | export CPU_TARGET="$cpu_target" 41 | lhelper create --upload build-openblas-static 42 | source "$(lhelper env-source build-openblas-static)" 43 | bash scripts/build-package.sh -appimage -name=$cpu_target -openblas -unix 44 | ) 45 | done 46 | - package-all: | 47 | cd gsl-shell 48 | tar cf gsl-shell-linux.tar gsl-shell-*.tar.gz *.AppImage 49 | artifacts: 50 | - gsl-shell/gsl-shell-linux.tar 51 | 52 | -------------------------------------------------------------------------------- /scripts/unix2dos.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | for fn in sys.argv[1:]: 5 | new_name = fn + ".new_" 6 | 7 | fin = open(fn, "rb") 8 | fout = open(new_name, "wb") 9 | 10 | for line in fin: 11 | nline = line.replace("\n", "\015\n") 12 | fout.write(nline) 13 | 14 | fin.close() 15 | fout.close() 16 | 17 | os.remove(fn) 18 | os.rename(new_name, fn) 19 | 20 | -------------------------------------------------------------------------------- /src/agg-plot/agg-parse-trans.h: -------------------------------------------------------------------------------- 1 | #ifndef AGG_PARSE_TRANS_H 2 | #define AGG_PARSE_TRANS_H 3 | 4 | extern "C" { 5 | #include "lua.h" 6 | } 7 | 8 | #include "lua-cpp-utils.h" 9 | #include "sg_object.h" 10 | #include "agg_color_rgba.h" 11 | 12 | extern sg_object* parse_graph_args (lua_State *L, agg::rgba8& color, 13 | gslshell::ret_status& st, int layer_index); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/agg-plot/agg-pixfmt-config.h: -------------------------------------------------------------------------------- 1 | #ifndef AGG_PIXFMT_CONFIG_H 2 | #define AGG_PIXFMT_CONFIG_H 3 | 4 | #include "platform/agg_platform_support.h" 5 | #include "agg_gamma_lut.h" 6 | #include "agg_pixfmt_rgb24_lcd.h" 7 | #include "agg_font_freetype.h" 8 | 9 | namespace gslshell 10 | { 11 | typedef agg::gamma_lut gamma_type; 12 | 13 | const agg::pix_format_e pixel_format = agg::pix_format_rgb24; 14 | const bool flip_y = true; 15 | 16 | extern unsigned bpp; 17 | extern agg::pix_format_e sys_pixel_format; 18 | extern unsigned sys_bpp; 19 | 20 | extern gamma_type gamma; 21 | extern agg::lcd_distribution_lut subpixel_lut; 22 | 23 | extern agg::font_engine_freetype_int32& font_engine(); 24 | extern agg::font_cache_manager& font_manager(); 25 | 26 | extern const char *get_font_name(); 27 | extern const char *get_fox_console_font_name(); 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/agg-plot/bitmap-plot.cpp: -------------------------------------------------------------------------------- 1 | 2 | extern "C" { 3 | #include "lua.h" 4 | #include "lauxlib.h" 5 | } 6 | 7 | #include "bitmap-plot.h" 8 | #include "lua-cpp-utils.h" 9 | #include "lua-plot-cpp.h" 10 | #include "gs-types.h" 11 | #include "canvas.h" 12 | #include "colors.h" 13 | #include "agg-pixfmt-config.h" 14 | #include "platform_support_ext.h" 15 | 16 | void 17 | bitmap_save_image_cpp (sg_plot *p, const char *fn, unsigned w, unsigned h, 18 | gslshell::ret_status& st) 19 | { 20 | agg::rendering_buffer rbuf_tmp; 21 | unsigned row_size = w * (gslshell::bpp / 8); 22 | unsigned buf_size = h * row_size; 23 | 24 | unsigned char* buffer = new(std::nothrow) unsigned char[buf_size]; 25 | if (!buffer) 26 | { 27 | st.error("cannot allocate memory", "plot save"); 28 | return; 29 | } 30 | 31 | rbuf_tmp.attach(buffer, w, h, gslshell::flip_y ? row_size : -row_size); 32 | 33 | canvas can(rbuf_tmp, w, h, colors::white); 34 | agg::trans_affine mtx(w, 0.0, 0.0, h, 0.0, 0.0); 35 | 36 | agg::rect_base r = rect_of_slot_matrix(mtx); 37 | can.clear_box(r); 38 | 39 | p->draw(can, mtx, NULL); 40 | 41 | bool success = platform_support_ext::save_image_file (rbuf_tmp, fn, gslshell::pixel_format); 42 | 43 | if (! success) 44 | st.error("cannot save image file", "plot save"); 45 | 46 | delete [] buffer; 47 | } 48 | 49 | int 50 | bitmap_save_image (lua_State *L) 51 | { 52 | sg_plot *p = object_check(L, 1, GS_PLOT); 53 | const char *fn = luaL_checkstring (L, 2); 54 | int w = luaL_optint (L, 3, 480), h = luaL_optint (L, 4, 480); 55 | 56 | if (w <= 0 || w > 1024 * 8) 57 | luaL_error (L, "width out of range"); 58 | 59 | if (h <= 0 || h > 1024 * 8) 60 | luaL_error (L, "height out of range"); 61 | 62 | gslshell::ret_status st; 63 | bitmap_save_image_cpp (p, fn, w, h, st); 64 | if (st.error_msg()) 65 | return luaL_error (L, "%s in %s", st.error_msg(), st.context()); 66 | 67 | return 0; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/agg-plot/bitmap-plot.h: -------------------------------------------------------------------------------- 1 | #ifndef BITMAP_PLOT_H 2 | #define BITMAP_PLOT_H 3 | 4 | extern "C" { 5 | 6 | #include "lua.h" 7 | 8 | extern int bitmap_save_image (lua_State *L); 9 | 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/agg-plot/canvas-window-cpp.h: -------------------------------------------------------------------------------- 1 | #ifndef CANVAS_WINDOW_CPP_H 2 | #define CANVAS_WINDOW_CPP_H 3 | 4 | #include 5 | #include 6 | 7 | #include "agg-pixfmt-config.h" 8 | #include "platform_support_ext.h" 9 | #include "agg_trans_affine.h" 10 | #include "agg_color_rgba.h" 11 | 12 | extern "C" { 13 | #include "lua.h" 14 | #include "lauxlib.h" 15 | } 16 | 17 | #include "defs.h" 18 | #include "canvas.h" 19 | #include "utils.h" 20 | #include "lua-gsl.h" 21 | 22 | class canvas_window : public platform_support_ext { 23 | protected: 24 | canvas *m_canvas; 25 | agg::rgba8 m_bgcolor; 26 | 27 | agg::trans_affine m_matrix; 28 | 29 | pthread_t m_thread; 30 | gsl_shell_state* m_gsl_shell; 31 | 32 | public: 33 | 34 | struct thread_info { 35 | lua_State *L; 36 | canvas_window *win; 37 | int window_id; 38 | 39 | thread_info (lua_State *L, canvas_window *win) : L(L), win(win) {}; 40 | }; 41 | 42 | enum win_status_e { not_ready, running, error, closed }; 43 | 44 | enum win_status_e status; 45 | 46 | canvas_window(gsl_shell_state* gs, agg::rgba8 bgcol): 47 | platform_support_ext(gslshell::pixel_format, true), 48 | m_canvas(NULL), m_bgcolor(bgcol), m_matrix(), m_gsl_shell(gs), 49 | status(not_ready) 50 | { }; 51 | 52 | virtual ~canvas_window() 53 | { 54 | if (m_canvas) 55 | delete m_canvas; 56 | }; 57 | 58 | virtual void on_init(); 59 | virtual void on_resize(int sx, int sy); 60 | 61 | void shutdown_close(bool send_close_request); 62 | gsl_shell_state* state() { 63 | return m_gsl_shell; 64 | } 65 | 66 | bool start_new_thread (std::unique_ptr& inf); 67 | 68 | void scale (agg::trans_affine& m) { 69 | trans_affine_compose (m, m_matrix); 70 | }; 71 | }; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/agg-plot/canvas_svg.cpp: -------------------------------------------------------------------------------- 1 | #include "canvas_svg.h" 2 | 3 | const double canvas_svg::default_stroke_width = 1.0; 4 | 5 | template <> 6 | void canvas_svg::draw(sg_object& vs, agg::rgba8 c) 7 | { 8 | int id = m_current_id ++; 9 | str s = vs.write_svg(id, c, m_height); 10 | canvas_svg::writeln(m_output, s, " "); 11 | } 12 | 13 | template <> 14 | void canvas_svg::draw_outline(sg_object& vs, agg::rgba8 c) 15 | { 16 | int id = m_current_id ++; 17 | str path; 18 | svg_property_list* ls = vs.svg_path(path, m_height); 19 | str s = svg_stroke_path(path, canvas_svg::default_stroke_width, id, c, ls); 20 | svg_property_list::free(ls); 21 | canvas_svg::writeln(m_output, s, " "); 22 | } 23 | -------------------------------------------------------------------------------- /src/agg-plot/categories.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_CATEGORIES_H 2 | #define AGGPLOT_CATEGORIES_H 3 | 4 | #include "strpp.h" 5 | #include "units.h" 6 | #include "utils.h" 7 | 8 | struct category_item { 9 | double value; 10 | str text; 11 | category_item(double v, const char*t) : value(v), text(t) {} 12 | }; 13 | 14 | class category_map : public ptr_list { 15 | 16 | typedef category_item item; 17 | 18 | public: 19 | class iterator : public label_iterator { 20 | public: 21 | iterator(const category_map& cat) : m_index(0), m_cat(cat) { } 22 | 23 | virtual bool next(double& val, const char*& text) 24 | { 25 | if (m_index >= m_cat.size()) 26 | return false; 27 | 28 | item* it = m_cat[m_index]; 29 | val = it->value; 30 | text = it->text.cstr(); 31 | m_index++; 32 | return true; 33 | } 34 | 35 | private: 36 | unsigned m_index; 37 | const category_map& m_cat; 38 | }; 39 | 40 | public: 41 | void add_item(double v, const char* name) { 42 | add(new item(v, name)); 43 | } 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/agg-plot/colors.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "lua-cpp-utils.h" 5 | #include "colors.h" 6 | 7 | static agg::rgba8 8 | rgba8_lookup (lua_State *L, const char *color_str) 9 | { 10 | const char *p = color_str; 11 | const int a = 255; 12 | 13 | if (strcmp (p, "white") == 0) 14 | return agg::rgba8(255, 255, 255, a); 15 | 16 | int val = 180; 17 | int r = 0, g = 0, b = 0; 18 | 19 | if (strncmp (p, "light", 5) == 0) 20 | { 21 | val = 255; 22 | p += 5; 23 | } 24 | else if (strncmp (p, "dark", 4) == 0) 25 | { 26 | val = 120; 27 | p += 4; 28 | } 29 | 30 | if (strcmp (p, "red") == 0) 31 | r = val; 32 | else if (strcmp (p, "green") == 0) 33 | g = val; 34 | else if (strcmp (p, "blue") == 0) 35 | b = val; 36 | else if (strcmp (p, "cyan") == 0) 37 | g = b = val; 38 | else if (strcmp (p, "magenta") == 0) 39 | r = b = val; 40 | else if (strcmp (p, "yellow") == 0) 41 | r = g = val; 42 | else if (strcmp (p, "gray") == 0) 43 | r = g = b = val; 44 | 45 | return agg::rgba8(r, g, b, a); 46 | } 47 | 48 | agg::rgba8 49 | color_arg_lookup (lua_State *L, int index) 50 | { 51 | if (lua_isnoneornil (L, index)) 52 | return colors::cdefault; 53 | 54 | if (lua_isnumber(L, index)) 55 | { 56 | unsigned int col = (unsigned int) lua_tointeger (L, index); 57 | agg::int8u r = (col & 0xff000000) >> 24; 58 | agg::int8u g = (col & 0x00ff0000) >> 16; 59 | agg::int8u b = (col & 0x0000ff00) >> 8; 60 | agg::int8u a = (col & 0x000000ff); 61 | 62 | return agg::rgba8(r, g, b, a); 63 | } 64 | 65 | const char *cstr = lua_tostring (L, index); 66 | 67 | if (!cstr) 68 | luaL_error (L, "invalid color specification"); 69 | 70 | return rgba8_lookup (L, cstr); 71 | } 72 | 73 | agg::rgba8 colors::white(0xff, 0xff, 0xff); 74 | agg::rgba8 colors::black(0, 0, 0); 75 | 76 | agg::rgba8 colors::cdefault(180, 0, 0, 255); 77 | -------------------------------------------------------------------------------- /src/agg-plot/colors.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_COLORS_H 2 | #define AGGPLOT_COLORS_H 3 | 4 | extern "C" { 5 | #include "lua.h" 6 | } 7 | 8 | #include "defs.h" 9 | #include "agg_color_rgba.h" 10 | 11 | extern agg::rgba8 color_arg_lookup (lua_State *L, int index); 12 | 13 | namespace colors { 14 | 15 | extern agg::rgba8 white; 16 | extern agg::rgba8 black; 17 | 18 | extern agg::rgba8 cdefault; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/agg-plot/factor_labels.h: -------------------------------------------------------------------------------- 1 | #include "agg_array.h" 2 | #include "utils.h" 3 | #include "strpp.h" 4 | 5 | class factor_labels 6 | { 7 | public: 8 | factor_labels(double delta): m_mark_delta(delta) {} 9 | 10 | double mark(int k) const { return m_mark_index[k] * m_mark_delta; } 11 | const char *label_text(int k) const { return m_label_text[k]->cstr(); } 12 | int labels_number() const { return m_label_text.size(); } 13 | 14 | void add_mark(int index, const char *text) 15 | { 16 | m_mark_index.add(index); 17 | if (text) 18 | { 19 | str* text_str = new str(text); 20 | m_label_text.add(text_str); 21 | } 22 | } 23 | 24 | private: 25 | double m_mark_delta; 26 | agg::pod_bvector m_mark_index; 27 | ptr_list m_label_text; 28 | }; 29 | -------------------------------------------------------------------------------- /src/agg-plot/fonts.cpp: -------------------------------------------------------------------------------- 1 | 2 | extern "C" { 3 | #include 4 | #include 5 | } 6 | 7 | #include "agg-pixfmt-config.h" 8 | 9 | extern "C" int initialize_fonts(lua_State* L); 10 | 11 | agg::font_engine_freetype_int32 global_font_eng; 12 | agg::font_cache_manager global_font_man(global_font_eng); 13 | 14 | int initialize_fonts(lua_State* L) 15 | { 16 | const char* font_name = gslshell::get_font_name(); 17 | if (!font_name) { 18 | return 1; 19 | } 20 | agg::glyph_rendering gren = agg::glyph_ren_outline; 21 | if (!global_font_eng.load_font(font_name, 0, gren)) 22 | luaL_error(L, "cannot load truetype font: %s", font_name); 23 | global_font_eng.hinting(true); 24 | return 0; 25 | } 26 | 27 | agg::font_engine_freetype_int32& gslshell::font_engine() 28 | { 29 | return global_font_eng; 30 | } 31 | 32 | agg::font_cache_manager& gslshell::font_manager() 33 | { 34 | return global_font_man; 35 | } 36 | -------------------------------------------------------------------------------- /src/agg-plot/gamma.cpp: -------------------------------------------------------------------------------- 1 | #include "agg-pixfmt-config.h" 2 | 3 | #ifndef DISABLE_GAMMA_CORR 4 | gslshell::gamma_type gslshell::gamma(1.5); 5 | #endif 6 | // Original values for the subpixel color filter. These are quite conservative 7 | // to avoid color fringes. 8 | // agg::lcd_distribution_lut gslshell::subpixel_lut(3./9., 2./9., 1./9.); 9 | 10 | // Slightly more agressive values with more weight to primary channel. 11 | // Some people may notice colorer fringes but fonts looks sharper. 12 | agg::lcd_distribution_lut gslshell::subpixel_lut(0.448, 0.184, 0.092); 13 | -------------------------------------------------------------------------------- /src/agg-plot/lua-cpp-utils.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_CPP_UTILS_H 2 | #define LUA_CPP_UTILS_H 3 | 4 | #include 5 | 6 | #include "defs.h" 7 | #include "lua-defs.h" 8 | __BEGIN_DECLS 9 | #include "lua.h" 10 | __END_DECLS 11 | 12 | #include "gs-types.h" 13 | 14 | namespace gslshell { 15 | 16 | class ret_status { 17 | bool m_success; 18 | const char *m_error_msg; 19 | const char *m_context; 20 | 21 | public: 22 | ret_status() : m_success(true) {}; 23 | 24 | void success() { 25 | m_success = true; 26 | } 27 | void error(const char *msg, const char *ctx) 28 | { 29 | m_success = false; 30 | m_error_msg = msg; 31 | m_context = ctx; 32 | }; 33 | 34 | const char *error_msg() const { 35 | return (m_success ? 0 : m_error_msg); 36 | }; 37 | const char *context() const { 38 | return (m_success ? 0 : m_context); 39 | }; 40 | }; 41 | } 42 | 43 | inline void* operator new(size_t nbytes, lua_State *L, enum gs_type_e tp) 44 | { 45 | void* p = lua_newuserdata(L, nbytes); 46 | gs_set_metatable (L, tp); 47 | return p; 48 | } 49 | 50 | template 51 | T* push_new_object (lua_State *L, enum gs_type_e tp) 52 | { 53 | return new(L, tp) T(); 54 | } 55 | 56 | template 57 | T* push_new_object (lua_State *L, enum gs_type_e tp, init_type& init) 58 | { 59 | return new(L, tp) T(init); 60 | } 61 | 62 | template 63 | int object_free (lua_State *L, int index, enum gs_type_e tp) 64 | { 65 | T *obj = (T *) gs_check_userdata (L, index, tp); 66 | obj->~T(); 67 | return 0; 68 | } 69 | 70 | template 71 | T* object_check (lua_State *L, int index, enum gs_type_e tp) 72 | { 73 | return (T *) gs_check_userdata (L, index, tp); 74 | } 75 | 76 | template 77 | T* object_cast (lua_State *L, int index, enum gs_type_e tp) 78 | { 79 | return (T *) gs_is_userdata (L, index, tp); 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/agg-plot/lua-draw.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_DRAW_H 2 | #define LUA_DRAW_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | #include "lua.h" 8 | __END_DECLS 9 | 10 | #ifdef __cplusplus 11 | 12 | #include "agg_color_rgba.h" 13 | 14 | #include "sg_object.h" 15 | #include "path.h" 16 | 17 | extern int agg_text_new (lua_State *L); 18 | extern int agg_path_new (lua_State *L); 19 | 20 | extern draw::path* check_agg_path (lua_State *L, int index); 21 | 22 | #endif 23 | 24 | __BEGIN_DECLS 25 | 26 | extern void draw_register (lua_State *L); 27 | 28 | __END_DECLS 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/agg-plot/lua-plot-cpp.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_LUA_PLOT_CPP_H 2 | #define AGGPLOT_LUA_PLOT_CPP_H 3 | 4 | #include "lua-plot.h" 5 | 6 | extern "C" { 7 | #include "lua.h" 8 | } 9 | 10 | #include "plot-auto.h" 11 | #include "resource-manager.h" 12 | 13 | typedef plot sg_plot; 14 | typedef plot_auto sg_plot_auto; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/agg-plot/lua-plot.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_LUA_PLOT_H 2 | #define AGGPLOT_LUA_PLOT_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include "lua.h" 9 | 10 | extern void plot_register (lua_State *L); 11 | 12 | extern void plot_lua_add_ref (lua_State* L, int plot_index, int ref_index); 13 | 14 | __END_DECLS 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/agg-plot/lua-text.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_LUA_TEXT_H 2 | #define AGGPLOT_LUA_TEXT_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include 9 | 10 | extern void text_register (lua_State *L); 11 | 12 | __END_DECLS 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/agg-plot/markers.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_MARKERS_H 2 | #define AGGPLOT_MARKERS_H 3 | 4 | #include "sg_object.h" 5 | 6 | extern sg_object* new_marker_symbol(const char *name); 7 | extern sg_object* new_marker_symbol(int n); 8 | extern sg_object* new_marker_symbol_raw(const char *req_name); 9 | extern const char* marker_lookup(int n); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/agg-plot/meson.build: -------------------------------------------------------------------------------- 1 | if host_machine.system() == 'windows' 2 | platform_sources = ['support_win32.cpp', 'agg_platform_support_win32.cpp', 'agg_win32_bmp.cpp'] 3 | else 4 | platform_sources = ['support_x11.cpp', 'agg_platform_support_x11.cpp'] 5 | endif 6 | 7 | aggplot_sources = platform_sources + [ 8 | 'printf_check.cpp', 9 | 'fonts.cpp', 10 | 'gamma.cpp', 11 | 'agg_font_freetype.cpp', 12 | 'plot.cpp', 13 | 'plot-auto.cpp', 14 | 'utils.cpp', 15 | 'units.cpp', 16 | 'colors.cpp', 17 | 'markers.cpp', 18 | 'draw_svg.cpp', 19 | 'canvas_svg.cpp', 20 | 'lua-draw.cpp', 21 | 'lua-text.cpp', 22 | 'text.cpp', 23 | 'agg-parse-trans.cpp', 24 | 'window_registry.cpp', 25 | 'window.cpp', 26 | 'lua-plot.cpp', 27 | 'canvas-window.cpp', 28 | 'bitmap-plot.cpp', 29 | 'lua-graph.cpp', 30 | ] 31 | 32 | libaggplot = static_library('aggplot', 33 | aggplot_sources, 34 | dependencies: [libagg_dep, threads_dep, freetype_dep, luajit_dep], 35 | include_directories: [gsl_shell_include, cpp_utils_include], 36 | cpp_args: gsl_shell_defines, 37 | ) 38 | 39 | -------------------------------------------------------------------------------- /src/agg-plot/path.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_PATH_H 2 | #define AGGPLOT_PATH_H 3 | 4 | #include "sg_object.h" 5 | 6 | #include "agg_path_storage.h" 7 | #include "agg_ellipse.h" 8 | 9 | namespace draw { 10 | 11 | typedef sg_object_gen path; 12 | typedef sg_object_gen ellipse; 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/agg-plot/pixel_fmt.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_PIXEL_FMT_H 2 | #define AGGPLOT_PIXEL_FMT_H 3 | 4 | #include "agg-pixfmt-config.h" 5 | 6 | #include "agg_pixfmt_rgb.h" 7 | 8 | typedef gslshell::gamma_type gamma_type; 9 | 10 | struct pixel_gamma : public agg::pixfmt_rgb24_gamma 11 | { 12 | pixel_gamma(agg::rendering_buffer& ren_buf): 13 | agg::pixfmt_rgb24_gamma(ren_buf, gslshell::gamma) 14 | { } 15 | }; 16 | 17 | struct pixel_gamma_lcd : public agg::pixfmt_rgb24_lcd_gamma 18 | { 19 | pixel_gamma_lcd(agg::rendering_buffer& ren_buf): 20 | agg::pixfmt_rgb24_lcd_gamma(ren_buf, gslshell::subpixel_lut, gslshell::gamma) 21 | { } 22 | }; 23 | 24 | struct pixel_simple : public agg::pixfmt_rgb24 25 | { 26 | pixel_simple(agg::rendering_buffer& ren_buf): 27 | agg::pixfmt_rgb24(ren_buf) 28 | { } 29 | }; 30 | 31 | struct pixel_lcd : public agg::pixfmt_rgb24_lcd 32 | { 33 | pixel_lcd(agg::rendering_buffer& ren_buf): 34 | agg::pixfmt_rgb24_lcd(ren_buf, gslshell::subpixel_lut) 35 | { } 36 | }; 37 | 38 | #ifdef DISABLE_GAMMA_CORR 39 | typedef pixel_simple pixel_type; 40 | typedef pixel_lcd pixel_lcd_type; 41 | #else 42 | typedef pixel_gamma pixel_type; 43 | typedef pixel_gamma_lcd pixel_lcd_type; 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/agg-plot/platform_support_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_PLATFORM_SUPPORT_H 2 | #define AGGPLOT_PLATFORM_SUPPORT_H 3 | 4 | #include "agg_basics.h" 5 | #include "platform/agg_platform_support.h" 6 | #include "rendering_buffer_utils.h" 7 | 8 | class platform_support_ext : public agg::platform_support { 9 | public: 10 | platform_support_ext (agg::pix_format_e format, bool flip_y) 11 | : agg::platform_support(format, flip_y) 12 | { }; 13 | 14 | void lock(); 15 | void unlock(); 16 | 17 | bool is_mapped(); 18 | void close_request(); 19 | void update_region (const agg::rect_base& r); 20 | void do_window_update (); 21 | 22 | static void prepare(); 23 | 24 | static bool save_image_file (agg::rendering_buffer& src, const char *fn, 25 | agg::pix_format_e src_pixfmt_tag); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/agg-plot/plot-auto.h: -------------------------------------------------------------------------------- 1 | 2 | /* plot-auto.h 3 | * 4 | * Copyright (C) 2009, 2010 Francesco Abbate 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or (at 9 | * your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef AGGPLOT_PLOT_AUTO_H 22 | #define AGGPLOT_PLOT_AUTO_H 23 | 24 | #include "plot.h" 25 | #include "rect.h" 26 | 27 | #include "agg_array.h" 28 | #include "agg_basics.h" 29 | 30 | class plot_auto : public plot { 31 | public: 32 | plot_auto() : 33 | plot(true), m_bbox_updated(true), m_enlarged_layer(false) 34 | { }; 35 | 36 | virtual ~plot_auto() { }; 37 | 38 | virtual void add(sg_object* vs, agg::rgba8& color, bool outline); 39 | virtual void before_draw() 40 | { 41 | plot::before_draw(); 42 | if (!m_bbox_updated) 43 | check_bounding_box(); 44 | }; 45 | 46 | virtual bool push_layer(); 47 | virtual bool pop_layer(); 48 | virtual void clear_current_layer(); 49 | 50 | private: 51 | void calc_layer_bounding_box(item_list* layer, opt_rect& rect); 52 | void set_opt_limits(const opt_rect& r); 53 | 54 | void check_bounding_box(); 55 | void calc_bounding_box(); 56 | bool fit_inside(sg_object *obj) const; 57 | 58 | // bounding box 59 | bool m_bbox_updated; 60 | bool m_enlarged_layer; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/agg-plot/printf_check.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "printf_check.h" 3 | 4 | static const char* match_plain_chars(const char *p) 5 | { 6 | for (/* */; *p; p++) { 7 | for (/* */; *p != '%'; p++) { 8 | if (*p == 0) 9 | return 0; 10 | } 11 | p ++; 12 | if (*p != '%') 13 | return p; 14 | } 15 | return 0; 16 | } 17 | 18 | static const char* match_integer(const char* p) 19 | { 20 | if (int(*p) >= int('1') && int(*p) <= int('9')) 21 | p++; 22 | while (int(*p) >= int('0') && int(*p) <= int('9')) 23 | p++; 24 | 25 | return p; 26 | } 27 | 28 | int check_printf_argument(const char *label, const char*& tail, arg_type_e& arg_type) 29 | { 30 | const char* p = match_plain_chars(label); 31 | 32 | if (!p) return 0; 33 | 34 | if (*p) 35 | { 36 | const char c = *p; 37 | if (c == '0' || c == '-' || c == '+' || c == ' ' || c == '#' || c == '\'') 38 | { 39 | p ++; 40 | if (*p == 0) goto error_exit; 41 | } 42 | } 43 | else 44 | goto error_exit; 45 | 46 | p = match_integer(p); 47 | if (*p == 0) goto error_exit; 48 | 49 | if (*p == '.') 50 | { 51 | p++; 52 | if (*p == 0) goto error_exit; 53 | p = match_integer(p); 54 | if (*p == 0) goto error_exit; 55 | } 56 | 57 | if (*p == 'l') { 58 | p++; 59 | if (*p == 0) goto error_exit; 60 | } 61 | 62 | if (*p) 63 | { 64 | const char s = *p; 65 | if (s == 'd' || s == 'i' || s == 'd' || s == 'u' || s == 'x' || s == 'X' || s == 'o') { 66 | tail = p + 1; 67 | arg_type = argument_int; 68 | return 1; 69 | } else if (s == 'f' || s == 'g' || s == 'e' || s == 'E' || s == 'G') { 70 | tail = p + 1; 71 | arg_type = argument_double; 72 | return 1; 73 | } 74 | } 75 | 76 | error_exit: 77 | return (-1); 78 | } 79 | -------------------------------------------------------------------------------- /src/agg-plot/printf_check.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_PRINTF_CHECK_H 2 | #define AGGPLOT_PRINTF_CHECK_H 3 | 4 | enum arg_type_e { 5 | argument_int, 6 | argument_double, 7 | }; 8 | 9 | extern int check_printf_argument(const char *label, const char*& tail, arg_type_e& arg_type); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/agg-plot/rect.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_RECT_H 2 | #define AGGPLOT_RECT_H 3 | 4 | #include 5 | #include "agg_basics.h" 6 | 7 | enum set_oper_e { rect_union, rect_intersect }; 8 | 9 | template 10 | class opt_rect { 11 | typedef agg::rect_base rect_type; 12 | 13 | bool m_defined; 14 | rect_type m_rect; 15 | 16 | public: 17 | opt_rect() : m_defined(false) {}; 18 | opt_rect(T x1, T y1, T x2, T y2) : m_defined(true), m_rect(x1, y1, x2, y2) {}; 19 | 20 | void clear() { 21 | m_defined = false; 22 | }; 23 | 24 | void set(const rect_type& r) { 25 | m_defined = true; 26 | m_rect = r; 27 | }; 28 | 29 | void set(T x1, T y1, T x2, T y2) { 30 | m_defined = true; 31 | m_rect.x1 = x1; 32 | m_rect.y1 = y1; 33 | m_rect.x2 = x2; 34 | m_rect.y2 = y2; 35 | }; 36 | 37 | bool is_defined() const { 38 | return m_defined; 39 | }; 40 | 41 | const rect_type& rect() const 42 | { 43 | assert (m_defined); 44 | return m_rect; 45 | } 46 | 47 | void operator = (const opt_rect& src) 48 | { 49 | m_defined = src.m_defined; 50 | if (m_defined) 51 | m_rect = src.m_rect; 52 | } 53 | 54 | void operator = (const rect_type& src) 55 | { 56 | m_defined = true; 57 | m_rect = src; 58 | } 59 | 60 | template 61 | void add(const rect_type& r) 62 | { 63 | if (op == rect_union) 64 | m_rect = (m_defined ? agg::unite_rectangles(m_rect, r) : r); 65 | else 66 | m_rect = (m_defined ? agg::intersect_rectangles(m_rect, r) : r); 67 | 68 | m_defined = true; 69 | } 70 | 71 | template 72 | void add(const opt_rect& optr) 73 | { 74 | if (optr.m_defined) 75 | this->add(optr.m_rect); 76 | } 77 | }; 78 | 79 | template 80 | agg::rect_base rect_of_slot_matrix (const agg::trans_affine& mtx) 81 | { 82 | T dx = T(mtx.sx + mtx.tx), dy = T(mtx.sy + mtx.ty); 83 | return agg::rect_base(T(mtx.tx), T(mtx.ty), dx, dy); 84 | } 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/agg-plot/resource-manager.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_RESOURCE_MANAGER_H 2 | #define AGGPLOT_RESOURCE_MANAGER_H 3 | 4 | class manage_owner { 5 | public: 6 | template 7 | static void acquire(T* p) { }; 8 | 9 | template 10 | static void dispose(T* p) { 11 | delete p; 12 | }; 13 | }; 14 | 15 | class manage_not_owner { 16 | public: 17 | template 18 | static void acquire(T* p) { }; 19 | 20 | template 21 | static void dispose(T* p) { }; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/agg-plot/sg_marker.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_SG_MARKER_H 2 | #define AGGPLOT_SG_MARKER_H 3 | 4 | #include "agg_conv_transform.h" 5 | #include "agg_trans_affine.h" 6 | 7 | #include "sg_object.h" 8 | #include "markers.h" 9 | #include "utils.h" 10 | 11 | typedef agg::conv_transform conv_type; 12 | 13 | namespace draw { 14 | 15 | class marker_a : public sg_adapter { 16 | 17 | public: 18 | marker_a(double x, double y, sg_object* sym, double size): 19 | sg_adapter(sym, m_trans), 20 | m_trans(size), m_symbol(sym), m_x(x), m_y(y) 21 | { 22 | // the following is needed to adjust the approximation_scale of the 23 | // symbol 24 | m_symbol->apply_transform(identity_matrix, size); 25 | } 26 | 27 | virtual void apply_transform(const agg::trans_affine& m, double as) 28 | { 29 | double *tx = &m_trans.tx, *ty = &m_trans.ty; 30 | *tx = m_x; 31 | *ty = m_y; 32 | m.transform(tx, ty); 33 | } 34 | 35 | virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) 36 | { 37 | *x1 = *x2 = m_x; 38 | *y1 = *y2 = m_y; 39 | } 40 | 41 | protected: 42 | agg::trans_affine_scaling m_trans; 43 | sg_object* m_symbol; 44 | double m_x, m_y; 45 | }; 46 | 47 | class marker : public marker_a { 48 | public: 49 | marker(double x, double y, sg_object* s, double sz) : marker_a(x, y, s, sz) {} 50 | ~marker() { 51 | delete m_symbol; 52 | } 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/agg-plot/support_win32.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "agg-pixfmt-config.h" 6 | 7 | const char *ttf_names[] = {"calibri.ttf", "arial.ttf", 0}; 8 | const char *console_font_names[] = {"consolas", "lucida console", "fixedsys", 0}; 9 | const char *console_font_filenames[] = {"consola.ttf", "lucon.ttf", "cvgafix.fon", 0}; 10 | 11 | const char *gslshell::get_font_name() 12 | { 13 | static TCHAR pf[MAX_PATH + 32]; 14 | SHGetFolderPath(0, CSIDL_FONTS, NULL, 0, pf); 15 | unsigned len = strlen(pf); 16 | pf[len++] = '\\'; 17 | for (int k = 0; ttf_names[k]; k++) 18 | { 19 | const char* font_name = ttf_names[k]; 20 | memcpy(pf + len, font_name, (strlen(font_name) + 1) * sizeof(char)); 21 | struct _stat inf[1]; 22 | int status = _stat(pf, inf); 23 | if (status == 0) 24 | return pf; 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | const char* gslshell::get_fox_console_font_name() 31 | { 32 | static TCHAR pf[MAX_PATH + 32]; 33 | SHGetFolderPath(0, CSIDL_FONTS, NULL, 0, pf); 34 | unsigned len = strlen(pf); 35 | pf[len++] = '\\'; 36 | for (int k = 0; console_font_filenames[k]; k++) 37 | { 38 | const char* filename = console_font_filenames[k]; 39 | memcpy(pf + len, filename, (strlen(filename) + 1) * sizeof(char)); 40 | struct _stat inf[1]; 41 | int status = _stat(pf, inf); 42 | if (status == 0) 43 | return console_font_names[k]; 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/agg-plot/support_x11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "agg-pixfmt-config.h" 4 | 5 | #ifdef DARWIN_MACOSX 6 | const char *ttf_names[] = {"Arial.ttf", "Trebuchet MS.ttf", "Courier New.ttf", 0}; 7 | const char *ttf_system_dir[] = {"/Library/Fonts", 0}; 8 | #define CONSOLE_FONT_NAME "Monaco" 9 | #else 10 | const char *ttf_names[] = { 11 | "ubuntu-font-family/Ubuntu-R.ttf", 12 | "freefont/FreeSans.ttf", "freefont-ttf/FreeSans.ttf", "FreeSans.ttf", 13 | "ttf-dejavu/DejaVuSans.ttf", "dejavu/DejaVuSans.ttf", "DejaVuSans.ttf", 14 | "liberation/LiberationSans-Regular.ttf", 0}; 15 | const char *ttf_system_dir[] = {"/usr/share/fonts/truetype", "/usr/share/fonts", "/usr/share/fonts/TTF", 0}; 16 | #define CONSOLE_FONT_NAME "monospace" 17 | #endif 18 | 19 | const char *gslshell::get_font_name() 20 | { 21 | for (int i = 0; ttf_system_dir[i]; i++) 22 | { 23 | const char* ttf_dir = ttf_system_dir[i]; 24 | unsigned len = strlen(ttf_dir); 25 | static char pf[256]; 26 | memcpy(pf, ttf_dir, len); 27 | char* base_ptr = pf + len; 28 | if (pf[len - 1] != '/') { 29 | *base_ptr = '/'; 30 | base_ptr ++; 31 | } 32 | for (int k = 0; ttf_names[k]; k++) 33 | { 34 | const char* font_name = ttf_names[k]; 35 | memcpy(base_ptr, font_name, (strlen(font_name) + 1) * sizeof(char)); 36 | struct stat inf[1]; 37 | int status = stat(pf, inf); 38 | if (status == 0) 39 | return pf; 40 | } 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | const char* gslshell::get_fox_console_font_name() 47 | { 48 | return CONSOLE_FONT_NAME; 49 | } 50 | -------------------------------------------------------------------------------- /src/agg-plot/text.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_TEXT_H 2 | #define AGGPLOT_TEXT_H 3 | 4 | #include "agg_trans_affine.h" 5 | 6 | #include "sg_object.h" 7 | #include "text_label.h" 8 | 9 | namespace draw { 10 | 11 | class text : public sg_object 12 | { 13 | agg::trans_affine m_matrix; 14 | 15 | double m_x, m_y; 16 | double m_angle; 17 | 18 | double m_hjustif; 19 | double m_vjustif; 20 | 21 | text_label m_text_label; 22 | 23 | public: 24 | text(const char* text, double size = 10.0, double hjustif = 0.0, double vjustif = 0.0): 25 | m_x(0.0), m_y(0.0), m_angle(0.0), 26 | m_hjustif(hjustif), m_vjustif(vjustif), m_text_label(text, round(size)) 27 | { 28 | m_text_label.model_mtx(m_matrix); 29 | } 30 | 31 | virtual void rewind(unsigned path_id) 32 | { 33 | m_text_label.rewind(m_hjustif, m_vjustif); 34 | } 35 | 36 | virtual unsigned vertex(double* x, double* y) 37 | { 38 | return m_text_label.vertex(x, y); 39 | } 40 | 41 | void angle(double th) 42 | { 43 | double c = cos(th), s = sin(th); 44 | 45 | m_angle = th; 46 | 47 | m_matrix.sx = c; 48 | m_matrix.shx = -s; 49 | m_matrix.shy = s; 50 | m_matrix.sy = c; 51 | } 52 | 53 | double angle() const { 54 | return m_angle; 55 | }; 56 | 57 | const char * get_text() const { 58 | return m_text_label.text().cstr(); 59 | } 60 | 61 | double text_height() const { 62 | return m_text_label.get_text_height(); 63 | } 64 | 65 | void set_point(double x, double y) 66 | { 67 | m_x = x; 68 | m_y = y; 69 | 70 | m_matrix.tx = m_x; 71 | m_matrix.ty = m_y; 72 | } 73 | 74 | void hjustif(double hj) { 75 | m_hjustif = hj; 76 | } 77 | void vjustif(double vj) { 78 | m_vjustif = vj; 79 | } 80 | 81 | virtual void apply_transform(const agg::trans_affine& m, double as); 82 | virtual void bounding_box(double *x1, double *y1, double *x2, double *y2); 83 | 84 | virtual str write_svg(int id, agg::rgba8 c, double h); 85 | }; 86 | } 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/agg-plot/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | agg::trans_affine identity_matrix; 4 | 5 | /* Mnemonic: a.premultiply(b) means a * b in terms of matrix multiplication */ 6 | 7 | void 8 | trans_affine_compose (agg::trans_affine& a, const agg::trans_affine& b) 9 | { 10 | double a_tx = a.tx, a_ty = a.ty; 11 | 12 | a.premultiply(b); 13 | 14 | a.tx = b.sx * a_tx + b.shx * a_ty + b.tx; 15 | a.ty = b.shy * a_tx + b.sy * a_ty + b.ty; 16 | } 17 | 18 | agg::trans_affine affine_matrix(const agg::rect_i& r) 19 | { 20 | double w = r.x2 - r.x1, h = r.y2 - r.y1; 21 | double tx = r.x1, ty = r.y1; 22 | return agg::trans_affine(w, 0.0, 0.0, h, tx, ty); 23 | } 24 | -------------------------------------------------------------------------------- /src/agg-plot/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_UTILS_H 2 | #define AGGPLOT_UTILS_H 3 | 4 | #include "agg_trans_affine.h" 5 | #include "agg_array.h" 6 | 7 | #ifndef M_PI 8 | #define M_PI 3.14159265358979323846 9 | #endif 10 | 11 | #ifdef min 12 | #undef min 13 | #endif 14 | 15 | #ifdef max 16 | #undef max 17 | #endif 18 | 19 | 20 | template 21 | T min(T a, T b) 22 | { 23 | return (a < b) ? a : b; 24 | }; 25 | 26 | template 27 | T max(T a, T b) 28 | { 29 | return (a > b) ? a : b; 30 | }; 31 | 32 | template 33 | class ptr_list { 34 | public: 35 | ~ptr_list() { 36 | clear(); 37 | } 38 | 39 | void add(T* p) { 40 | m_list.add(p); 41 | } 42 | 43 | T* operator [] (unsigned k) const { 44 | return m_list[k]; 45 | } 46 | 47 | T* at(unsigned k) const { 48 | return m_list[k]; 49 | } 50 | 51 | unsigned size() const { 52 | return m_list.size(); 53 | } 54 | 55 | void clear() 56 | { 57 | unsigned n = m_list.size(); 58 | for (unsigned k = 0; k < n; k++) 59 | delete m_list[k]; 60 | m_list.clear(); 61 | } 62 | 63 | private: 64 | agg::pod_bvector m_list; 65 | }; 66 | 67 | inline bool is_unit_matrix(const agg::trans_affine& m, double eps = 1.0e-5) 68 | { 69 | return (fabs(m.sx - 1.0) < eps && fabs(m.shx) < eps && 70 | fabs(m.shy) < eps && fabs(m.sy - 1.0) < eps); 71 | } 72 | 73 | extern void trans_affine_compose (agg::trans_affine& a, 74 | const agg::trans_affine& b); 75 | 76 | extern agg::trans_affine affine_matrix(const agg::rect_i& r); 77 | 78 | extern agg::trans_affine identity_matrix; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/agg-plot/window.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_WINDOW_H 2 | #define AGGPLOT_WINDOW_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include "lua.h" 9 | 10 | extern void window_register (lua_State *L); 11 | 12 | extern int window_slot_update (lua_State *L); 13 | extern int window_slot_refresh (lua_State *L); 14 | extern int window_save_slot_image (lua_State *L); 15 | extern int window_restore_slot_image (lua_State *L); 16 | extern int window_update (lua_State *L); 17 | extern int window_new (lua_State *L); 18 | extern int window_show (lua_State *L); 19 | extern int window_attach (lua_State *L); 20 | extern int window_close (lua_State *L); 21 | extern int window_close_wait (lua_State *L); 22 | extern int window_wait (lua_State *L); 23 | 24 | __END_DECLS 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/agg-plot/window_hooks.h: -------------------------------------------------------------------------------- 1 | #ifndef AGGPLOT_WINDOW_HOOKS_H 2 | #define AGGPLOT_WINDOW_HOOKS_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include "lua.h" 9 | 10 | struct window_hooks { 11 | int (*create)(lua_State* L); 12 | int (*show)(lua_State* L); 13 | int (*attach)(lua_State* L); 14 | int (*update)(lua_State* L); 15 | int (*refresh)(lua_State* L); 16 | int (*close)(lua_State* L); 17 | int (*wait)(lua_State* L); 18 | int (*save_image)(lua_State* L); 19 | int (*restore_image)(lua_State* L); 20 | 21 | void (*register_module)(lua_State* L); 22 | }; 23 | 24 | extern struct window_hooks app_window_hooks[1]; 25 | 26 | __END_DECLS 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/agg-plot/window_registry.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOW_REGISTRY_H 2 | #define WINDOW_REGISTRY_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include "lua.h" 9 | #include "lauxlib.h" 10 | 11 | extern void window_registry_prepare (lua_State *L); 12 | 13 | extern int window_index_add (lua_State *L, int index); 14 | extern void window_index_get (lua_State *L, int id); 15 | extern void window_index_remove (lua_State *L, int id); 16 | extern void window_index_apply_all (lua_State *L, lua_CFunction f); 17 | extern int window_index_count (lua_State *L); 18 | 19 | extern void window_refs_add (lua_State *L, int index, int key_index, 20 | int value_index); 21 | extern void window_refs_remove (lua_State *L, int index, int key_index); 22 | extern void window_refs_lookup_apply (lua_State *L, int value_index, 23 | lua_CFunction func); 24 | 25 | __END_DECLS 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/console/meson.build: -------------------------------------------------------------------------------- 1 | # Readline not supported with meson build. 2 | 3 | executable('gsl-shell', 'gsl-shell-jit.c', 4 | dependencies: [libgsl_dep, libagg_dep, threads_dep, freetype_dep, luajit_dep], 5 | include_directories: gsl_shell_include, 6 | cpp_args: gsl_shell_defines, 7 | link_with: [libluagsl, libaggplot, libgdt], 8 | link_args: gsl_shell_link_args, 9 | export_dynamic: true, 10 | win_subsystem: 'console', 11 | install: true, 12 | install_dir: gsl_shell_bindir, 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /src/cpp-utils/list.h: -------------------------------------------------------------------------------- 1 | #ifndef CPP_LIST_H 2 | #define CPP_LIST_H 3 | 4 | template 5 | class list { 6 | T m_content; 7 | list* m_next; 8 | 9 | public: 10 | list(const T& c, list* next = 0) : m_content(c), m_next(next) { }; 11 | list( T& c, list* next = 0) : m_content(c), m_next(next) { }; 12 | 13 | T& content() { return m_content; }; 14 | const T& content() const { return m_content; }; 15 | 16 | static list* push_back(list* head, list* n) 17 | { 18 | list* k = head; 19 | 20 | if (! k) 21 | return n; 22 | 23 | while (k->m_next) 24 | k = k->m_next; 25 | k->m_next = n; 26 | 27 | return head; 28 | } 29 | 30 | static int length(list* ls) 31 | { 32 | int n = 0; 33 | for ( ; ls; ls = ls->next()) 34 | n++; 35 | return n; 36 | } 37 | 38 | static void free(list* p) 39 | { 40 | list* n; 41 | for (/* */; p; p = n) 42 | { 43 | n = p->m_next; 44 | delete p; 45 | } 46 | } 47 | 48 | static list* pop(list* p) 49 | { 50 | list* tail = p->next(); 51 | delete p; 52 | return tail; 53 | } 54 | 55 | list* next() { return m_next; }; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/cpp-utils/pthreadpp.h: -------------------------------------------------------------------------------- 1 | #ifndef CPP_PTHREADPP_H 2 | #define CPP_PTHREADPP_H 3 | 4 | #include 5 | 6 | /* Simple C++ wrapper around basic mutex/condition operations. 7 | The added value of the wrapper is more clean C++ code with automatic 8 | initialization/deallocation of resources. */ 9 | 10 | namespace pthread { 11 | 12 | class mutex { 13 | public: 14 | mutex() { pthread_mutex_init(&m_mutex, NULL); } 15 | ~mutex() { pthread_mutex_destroy(&m_mutex); } 16 | 17 | void lock() { pthread_mutex_lock(&m_mutex); } 18 | void unlock() { pthread_mutex_unlock(&m_mutex); } 19 | 20 | pthread_mutex_t* mutex_ptr() { return &m_mutex; } 21 | 22 | private: 23 | mutex(const mutex&); 24 | mutex& operator= (const mutex&); 25 | 26 | pthread_mutex_t m_mutex; 27 | }; 28 | 29 | class auto_lock { 30 | public: 31 | auto_lock(mutex& m): m_mutex(m) { m_mutex.lock(); } 32 | ~auto_lock() { m_mutex.unlock(); } 33 | private: 34 | mutex& m_mutex; 35 | }; 36 | 37 | /* Since the official documentation recommend to use pthread conditions 38 | always in pair with a mutex we let a condtion inherit from a mutex. 39 | In this way a C++ "cond" instance can perform both mutex and condition 40 | operations. */ 41 | class cond : public mutex { 42 | public: 43 | cond() { pthread_cond_init(&m_cond, NULL); } 44 | ~cond() { pthread_cond_destroy(&m_cond); } 45 | 46 | void signal() { pthread_cond_signal(&m_cond); } 47 | void wait() { pthread_cond_wait(&m_cond, mutex_ptr()); } 48 | 49 | private: 50 | pthread_cond_t m_cond; 51 | }; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/cpp-utils/shared_vector.h: -------------------------------------------------------------------------------- 1 | #ifndef CPPUTILS_SHARED_VECTOR_H 2 | #define CPPUTILS_SHARED_VECTOR_H 3 | 4 | #include "pthreadpp.h" 5 | #include "agg_array.h" 6 | 7 | template 8 | class shared_vector : public agg::pod_bvector 9 | { 10 | public: 11 | shared_vector(): agg::pod_bvector() { } 12 | 13 | void lock() { m_mutex.lock(); } 14 | void unlock() { m_mutex.unlock(); } 15 | 16 | private: 17 | agg::pod_bvector m_data; 18 | pthread::mutex m_mutex; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/cpp-utils/tree.h: -------------------------------------------------------------------------------- 1 | #ifndef CPP_TREE_H 2 | #define CPP_TREE_H 3 | 4 | #include "list.h" 5 | 6 | namespace tree { 7 | 8 | template 9 | struct node { 10 | virtual list* tree() { return 0; }; 11 | virtual list* tree(tree_data_type& data) { return 0; }; 12 | 13 | virtual base_type* content() = 0; 14 | virtual void content(const base_type& src) = 0; 15 | 16 | virtual ~node() {}; 17 | }; 18 | 19 | template 20 | class leaf : public node { 21 | base_type m_content; 22 | 23 | public: 24 | leaf() : m_content() {}; 25 | 26 | virtual base_type* content() { return &m_content; }; 27 | virtual void content(const base_type& src) { m_content = src; }; 28 | }; 29 | 30 | template 31 | class tree_node : public node { 32 | 33 | typedef node node_type; 34 | typedef list node_list; 35 | 36 | node_list *m_head; 37 | tree_data_type m_data; 38 | 39 | public: 40 | tree_node() : m_head(0), m_data() {}; 41 | 42 | template 43 | tree_node(const init_type& init_val) : m_head(0), m_data(init_val) {}; 44 | 45 | ~tree_node() 46 | { 47 | node_list *n; 48 | for (node_list *p = m_head; p; p = n) 49 | { 50 | n = p->next(); 51 | delete p->content(); 52 | delete p; 53 | } 54 | }; 55 | 56 | virtual node_list* tree() { return m_head; }; 57 | virtual node_list* tree(tree_data_type& data) 58 | { 59 | data = m_data; 60 | return m_head; 61 | }; 62 | 63 | virtual base_type* content() { return 0; }; 64 | virtual void content(const base_type& src) { }; 65 | 66 | void add(node_type* child) 67 | { 68 | node_list *t = new node_list(child); 69 | m_head = node_list::push_back(m_head, t); 70 | } 71 | }; 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/fox-gui/.gitignore: -------------------------------------------------------------------------------- 1 | gsl-shell-gui 2 | gsl-shell-gui.exe -------------------------------------------------------------------------------- /src/fox-gui/fox_gsl_shell.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "fox_gsl_shell.h" 3 | #include "gsl_shell_app.h" 4 | #include "lua_plot_window.h" 5 | #include "window_registry.h" 6 | #include "lua-graph.h" 7 | 8 | void fox_gsl_shell::init() 9 | { 10 | gsl_shell_thread::init(); 11 | } 12 | 13 | void fox_gsl_shell::close() 14 | { 15 | graph_close_windows(L); 16 | gsl_shell_thread::close(); 17 | } 18 | 19 | void 20 | fox_gsl_shell::before_eval() 21 | { 22 | m_window_close_queue.lock(); 23 | unsigned n = m_window_close_queue.size(); 24 | for (unsigned k = 0; k < n; k++) 25 | { 26 | window_index_remove (L, m_window_close_queue[k]); 27 | } 28 | m_window_close_queue.clear(); 29 | m_window_close_queue.unlock(); 30 | } 31 | 32 | void 33 | fox_gsl_shell::quit_callback() 34 | { 35 | if (m_app_channel) { 36 | m_app_channel->message(m_app, m_close_selector, (void *) this, sizeof(int)); 37 | } 38 | } 39 | 40 | void 41 | fox_gsl_shell::restart_callback() 42 | { 43 | m_app->lock(); 44 | m_app->send_request({gsl_shell_app::clear_console_rq}); 45 | m_app->unlock(); 46 | } 47 | 48 | void 49 | fox_gsl_shell::window_close_notify(int window_id) 50 | { 51 | m_window_close_queue.lock(); 52 | m_window_close_queue.add(window_id); 53 | m_window_close_queue.unlock(); 54 | } 55 | -------------------------------------------------------------------------------- /src/fox-gui/fox_gsl_shell.h: -------------------------------------------------------------------------------- 1 | #ifndef FOX_GSL_SHELL_H 2 | #define FOX_GSL_SHELL_H 3 | 4 | #include 5 | #include "agg_array.h" 6 | 7 | #include "gsl_shell_thread.h" 8 | #include "shared_vector.h" 9 | 10 | class gsl_shell_app; 11 | 12 | class fox_gsl_shell : public gsl_shell_thread 13 | { 14 | public: 15 | fox_gsl_shell(gsl_shell_app* app): m_app(app), m_app_channel(nullptr) { } 16 | 17 | virtual void init(); 18 | virtual void close(); 19 | 20 | virtual void before_eval(); 21 | virtual void restart_callback(); 22 | virtual void quit_callback(); 23 | 24 | // Set the channel to communicate with the FXApp and the selector needed for this 25 | // latter to close. 26 | void bind_app_channel(FXSelector close_selector, FXMessageChannel *app_channel) { 27 | m_close_selector = close_selector; 28 | m_app_channel = app_channel; 29 | } 30 | 31 | void window_close_notify(int window_id); 32 | 33 | private: 34 | gsl_shell_app* m_app; 35 | FXSelector m_close_selector; 36 | FXMessageChannel *m_app_channel; 37 | shared_vector m_window_close_queue; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/fox-gui/fx_console.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_FX_CONSOLE_H 2 | #define FOXGUI_FX_CONSOLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "gsl_shell_thread.h" 9 | #include "io_thread.h" 10 | #include "history.h" 11 | 12 | class fx_console : public FXText 13 | { 14 | FXDECLARE(fx_console) 15 | 16 | private: 17 | enum status_e { not_ready, input_mode, output_mode }; 18 | enum text_style_e { plain_style = 0, prompt_style = 1, error_style = 2}; 19 | 20 | static const FXchar* prompt; 21 | 22 | public: 23 | fx_console(FXApp *app, gsl_shell_thread* gs, io_redirect* lua_io, FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=3,FXint pr=3,FXint pt=2,FXint pb=2); 24 | 25 | ~fx_console(); 26 | 27 | // prepare to accept input 28 | void init(); 29 | void prepare_input(); 30 | void show_errors(); 31 | 32 | FXint get_input_length(); 33 | long update_editable(); 34 | void update_input_line(const char* line); 35 | 36 | virtual void create(); 37 | 38 | long on_key_press(FXObject*,FXSelector,void*); 39 | long on_left_btn_press(FXObject*,FXSelector,void*); 40 | long on_cmd_delete(FXObject*,FXSelector,void*); 41 | long on_cmd_insert_string(FXObject*,FXSelector,void*); 42 | long on_lua_output(FXObject*,FXSelector,void*); 43 | 44 | enum 45 | { 46 | ID_READ_INPUT = FXText::ID_LAST, 47 | ID_LUA_OUTPUT, 48 | ID_LAST, 49 | }; 50 | 51 | protected: 52 | fx_console() {} 53 | 54 | private: 55 | void init_styles(); 56 | 57 | private: 58 | FXint m_input_begin; 59 | FXString m_input; 60 | status_e m_status; 61 | gsl_shell_thread* m_engine; 62 | io_redirect* m_lua_io; 63 | FXMessageChannel *m_io_channel; 64 | 65 | lua_io_thread* m_lua_io_thread; 66 | FXMutex m_lua_io_mutex; 67 | FXString m_lua_io_buffer; 68 | FXString m_input_acc; 69 | 70 | FXString m_saved_line; 71 | history m_history; 72 | 73 | static FXHiliteStyle m_styles[2]; 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/fox-gui/fx_plot_canvas.cpp: -------------------------------------------------------------------------------- 1 | #include "util/agg_color_conv_rgb8.h" 2 | 3 | #include "fx_plot_canvas.h" 4 | #include "rendering_buffer_utils.h" 5 | #include "fatal.h" 6 | #include "lua-graph.h" 7 | #include "window_surface.h" 8 | 9 | FXDEFMAP(fx_plot_canvas) fx_plot_canvas_map[]= 10 | { 11 | FXMAPFUNC(SEL_PAINT, 0, fx_plot_canvas::on_cmd_paint), 12 | }; 13 | 14 | FXIMPLEMENT(fx_plot_canvas,FXCanvas,fx_plot_canvas_map,ARRAYNUMBER(fx_plot_canvas_map)); 15 | 16 | fx_plot_canvas::fx_plot_canvas(FXComposite* p, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h): 17 | FXCanvas(p, tgt, sel, opts, x, y, w, h) 18 | { 19 | } 20 | 21 | void fx_plot_canvas::update_region(const agg::rect_i& r) 22 | { 23 | FXshort ww = r.x2 - r.x1, hh= r.y2 - r.y1; 24 | if (ww <= 0 || hh <= 0) return; 25 | 26 | const window_surface::image& src_img = m_surface->get_image(); 27 | 28 | FXImage img(getApp(), NULL, IMAGE_OWNED|IMAGE_SHMI|IMAGE_SHMP, ww, hh); 29 | 30 | const unsigned fox_pixel_size = 4; 31 | 32 | agg::rendering_buffer dest; 33 | dest.attach((agg::int8u*) img.getData(), ww, hh, -ww * fox_pixel_size); 34 | 35 | rendering_buffer_ro src; 36 | rendering_buffer_get_const_view(src, src_img, r, window_surface::image_pixel_width); 37 | 38 | my_color_conv(&dest, &src, color_conv_rgb24_to_bgra32()); 39 | 40 | img.create(); 41 | 42 | FXDCWindow dc(this); 43 | dc.drawImage(&img, r.x1, getHeight() - r.y2); 44 | } 45 | 46 | long fx_plot_canvas::on_cmd_paint(FXObject *, FXSelector, void *ptr) 47 | { 48 | int ww = getWidth(), hh = getHeight(); 49 | 50 | if (!m_surface->canvas_size_match(ww, hh)) 51 | { 52 | m_surface->resize(ww, hh); 53 | m_surface->draw_image_buffer(); 54 | } 55 | 56 | agg::rect_i r(0, 0, ww, hh); 57 | update_region(r); 58 | return 1; 59 | } 60 | -------------------------------------------------------------------------------- /src/fox-gui/fx_plot_canvas.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_FX_PLOT_CANVAS_H 2 | #define FOXGUI_FX_PLOT_CANVAS_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | class window_surface; 11 | 12 | class fx_plot_canvas : public FXCanvas 13 | { 14 | FXDECLARE(fx_plot_canvas) 15 | public: 16 | fx_plot_canvas(FXComposite* p, FXObject* tgt=NULL, FXSelector sel=0, FXuint opts=FRAME_NORMAL, 17 | FXint x=0, FXint y=0, FXint w=0, FXint h=0); 18 | 19 | void update_region(const agg::rect_i& r); 20 | 21 | void attach_surface(window_surface* surf) { m_surface = surf; } 22 | 23 | long on_cmd_paint(FXObject *, FXSelector, void *); 24 | 25 | protected: 26 | fx_plot_canvas() {} 27 | 28 | private: 29 | window_surface* m_surface; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/fox-gui/fx_plot_window.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "fx_plot_window.h" 3 | #include "lua_plot_window.h" 4 | 5 | FXDEFMAP(fx_plot_window) fx_plot_window_map[]= 6 | { 7 | }; 8 | 9 | FXIMPLEMENT(fx_plot_window,FXMainWindow,fx_plot_window_map,ARRAYNUMBER(fx_plot_window_map)) 10 | 11 | fx_plot_window::fx_plot_window(FXApp* app, const FXString& name, FXIcon *ic, FXIcon *mi, FXint w, FXint h): 12 | FXMainWindow(app, name, ic, mi, DECOR_ALL, 0, 0, w, h), 13 | m_lua_window(0), m_surface(&m_display_window) 14 | { 15 | m_menu_bar = new FXMenuBar(this, LAYOUT_SIDE_TOP|LAYOUT_FILL_X); 16 | 17 | m_plot_menu = new FXMenuPane(this); 18 | new FXMenuCommand(m_plot_menu, "&Close\tCtl-C", NULL, this, ID_CLOSE); 19 | new FXMenuTitle(m_menu_bar, "&Plot", NULL, m_plot_menu); 20 | 21 | FXVerticalFrame* frame = new FXVerticalFrame(this, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y); 22 | 23 | // Sunken border for text widget 24 | FXHorizontalFrame *cbox = new FXHorizontalFrame(frame, FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0); 25 | 26 | m_canvas = new fx_plot_canvas(cbox, NULL, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y); 27 | m_display_window.attach(m_canvas); 28 | m_canvas->attach_surface(&m_surface); 29 | } 30 | 31 | fx_plot_window::~fx_plot_window() 32 | { 33 | delete m_canvas; 34 | delete m_plot_menu; 35 | 36 | if (m_lua_window) 37 | set_lua_status(closed); 38 | } 39 | -------------------------------------------------------------------------------- /src/fox-gui/fx_plot_window.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_FX_PLOT_WINDOW_H 2 | #define FOXGUI_FX_PLOT_WINDOW_H 3 | 4 | #include 5 | 6 | #include "gsl_shell_app.h" 7 | #include "fx_plot_canvas.h" 8 | 9 | #include "window_surface.h" 10 | 11 | class fx_plot_window; 12 | 13 | __BEGIN_DECLS 14 | 15 | enum window_status_e { not_ready, running, closed }; 16 | 17 | struct lua_fox_window 18 | { 19 | fx_plot_window* window; 20 | gsl_shell_app* app; 21 | enum window_status_e status; 22 | }; 23 | 24 | __END_DECLS 25 | 26 | class fox_display_window : public display_window { 27 | public: 28 | fox_display_window(): m_fox_canvas(0) {} 29 | 30 | void attach(fx_plot_canvas* can) { m_fox_canvas = can; } 31 | 32 | virtual void update_region(const agg::rect_i& r) { m_fox_canvas->update_region(r); } 33 | private: 34 | fx_plot_canvas* m_fox_canvas; 35 | }; 36 | 37 | class fx_plot_window : public FXMainWindow 38 | { 39 | FXDECLARE(fx_plot_window) 40 | public: 41 | fx_plot_window(FXApp* a, const FXString& name, FXIcon *ic=NULL, FXIcon *mi=NULL, FXint w=0, FXint h=0); 42 | 43 | ~fx_plot_window(); 44 | 45 | fx_plot_canvas* canvas() 46 | { 47 | return m_canvas; 48 | } 49 | gsl_shell_app* get_app() 50 | { 51 | return (gsl_shell_app*) getApp(); 52 | } 53 | 54 | window_surface& surface() { return m_surface; } 55 | 56 | void set_lua_window(lua_fox_window* w) { m_lua_window = w; } 57 | 58 | void set_lua_status(window_status_e s) { m_lua_window->status = s; } 59 | 60 | int lua_id; // the following is used by Lua to keep trace of the window 61 | 62 | protected: 63 | fx_plot_window(): m_surface(&m_display_window) {} 64 | 65 | private: 66 | FXMenuBar* m_menu_bar; 67 | FXMenuPane* m_plot_menu; 68 | fx_plot_canvas* m_canvas; 69 | lua_fox_window* m_lua_window; 70 | fox_display_window m_display_window; 71 | window_surface m_surface; 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/fox-gui/gsl-shell-fox.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #include 3 | #endif 4 | 5 | #include 6 | #include "gsl_shell_window.h" 7 | #include "gsl_shell_app.h" 8 | #include "window_hooks.h" 9 | #include "lua_plot_window.h" 10 | 11 | struct window_hooks app_window_hooks[1] = {{ 12 | fox_window_new, fox_window_show, fox_window_attach, 13 | fox_window_slot_update, fox_window_slot_refresh, 14 | fox_window_close, fox_window_close, 15 | fox_window_save_slot_image, fox_window_restore_slot_image, 16 | fox_window_register, 17 | } 18 | }; 19 | 20 | int 21 | main (int argc, char *argv[]) 22 | { 23 | #if defined(_WIN32) 24 | HINSTANCE lib = LoadLibrary("user32.dll"); 25 | int (*SetProcessDPIAware)() = (int (*)()) GetProcAddress(lib, "SetProcessDPIAware"); 26 | SetProcessDPIAware(); 27 | #endif 28 | gsl_shell_app app; 29 | app.init(argc, argv); 30 | app.create(); 31 | return app.run(); 32 | } 33 | -------------------------------------------------------------------------------- /src/fox-gui/gsl_shell_app.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_GSL_SHELL_APP_H 2 | #define FOXGUI_GSL_SHELL_APP_H 3 | 4 | #include 5 | 6 | #include "agg_array.h" 7 | #include "fox_gsl_shell.h" 8 | #include "fx_console.h" 9 | #include "redirect.h" 10 | 11 | class gsl_shell_app : public FXApp 12 | { 13 | FXDECLARE(gsl_shell_app) 14 | public: 15 | enum lua_request_e { 16 | no_rq = 0, 17 | create_window_rq, 18 | close_window_rq, 19 | clear_console_rq, 20 | }; 21 | 22 | struct lua_request { 23 | lua_request_e cmd; 24 | FXMainWindow* win; 25 | }; 26 | 27 | gsl_shell_app(); 28 | ~gsl_shell_app(); 29 | 30 | virtual void create(); 31 | 32 | void lock() 33 | { 34 | mutex().lock(); 35 | } 36 | void unlock() 37 | { 38 | mutex().unlock(); 39 | } 40 | 41 | void send_request(lua_request request); 42 | 43 | long on_lua_request(FXObject*,FXSelector,void*); 44 | long on_window_close(FXObject*,FXSelector,void*); 45 | long on_console_close(FXObject*,FXSelector,void*); 46 | long on_lua_quit(FXObject*,FXSelector,void*); 47 | long on_restart_lua_request(FXObject*,FXSelector,void*); 48 | long on_lua_interrupt(FXObject*,FXSelector,void*); 49 | 50 | FXIcon* gsl_shell_icon; 51 | FXIcon* gsl_shell_mini; 52 | FXIcon* plot_icon; 53 | 54 | enum 55 | { 56 | ID_LUA_REQUEST = FXApp::ID_LAST, 57 | ID_CONSOLE_CLOSE, 58 | ID_LUA_RESTART, 59 | ID_LUA_INTERRUPT, 60 | ID_LUA_QUIT, 61 | ID_LAST 62 | }; 63 | 64 | static float get_dpi_scale(); 65 | 66 | private: 67 | void wait_action(); 68 | 69 | fox_gsl_shell m_engine; 70 | FXMessageChannel m_engine_channel; 71 | FXMessageChannel m_request_channel; 72 | FXCondition m_request_treated; 73 | bool m_request_done; 74 | fx_console* m_console; 75 | io_redirect m_redirect; 76 | }; 77 | 78 | extern gsl_shell_app* global_app; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/fox-gui/gsl_shell_interp.h: -------------------------------------------------------------------------------- 1 | #ifndef GSL_SHELL_INTERP_H 2 | #define GSL_SHELL_INTERP_H 3 | 4 | extern "C" { 5 | #include 6 | } 7 | 8 | #include "defs.h" 9 | #include "pthreadpp.h" 10 | #include "lua-gsl.h" 11 | #include "strpp.h" 12 | #include "fatal.h" 13 | 14 | class gsl_shell : public gsl_shell_state 15 | { 16 | public: 17 | enum eval_result_e { eval_success, eval_error, incomplete_input }; 18 | 19 | gsl_shell() 20 | { 21 | gsl_shell_init(this); 22 | } 23 | 24 | virtual ~gsl_shell() 25 | { 26 | if (unlikely(this->L != NULL)) 27 | fatal_exception("warning: attempt to dispose an open Lua state"); 28 | gsl_shell_free(this); 29 | } 30 | 31 | virtual void init(); 32 | virtual void close(); 33 | 34 | int exec(const char* line); 35 | void interrupt(); 36 | 37 | const char* error_msg() const 38 | { 39 | return m_error_msg.cstr(); 40 | } 41 | 42 | private: 43 | int error_report(int status); 44 | 45 | str m_error_msg; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/fox-gui/gsl_shell_thread.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_LUA_ENGINE_H 2 | #define FOXGUI_LUA_ENGINE_H 3 | 4 | extern "C" { 5 | #include "lua.h" 6 | } 7 | 8 | #include "gsl_shell_interp.h" 9 | #include "pthreadpp.h" 10 | #include "str.h" 11 | 12 | class gsl_shell_thread : public gsl_shell 13 | { 14 | enum thread_cmd_e { thread_cmd_exec, thread_cmd_exit, thread_cmd_continue }; 15 | public: 16 | enum engine_status_e { starting, waiting, busy, terminated }; 17 | enum request_e { no_request = 0, exit_request, restart_request, execute_request }; 18 | enum { eot_character = 0x04 }; 19 | 20 | gsl_shell_thread(); 21 | 22 | void set_request(request_e req, const char* line = 0); 23 | 24 | void start(); 25 | void run(); 26 | 27 | virtual void before_eval() { } 28 | virtual void restart_callback() { } 29 | virtual void quit_callback() { } 30 | 31 | void lock() 32 | { 33 | pthread_mutex_lock(&this->exec_mutex); 34 | } 35 | 36 | void unlock() 37 | { 38 | pthread_mutex_unlock(&this->exec_mutex); 39 | } 40 | 41 | int eval_status() const 42 | { 43 | return m_eval_status; 44 | } 45 | 46 | pthread::mutex& eval_mutex() 47 | { 48 | return m_eval; 49 | } 50 | 51 | // asyncronous request 52 | void interrupt_request(); 53 | 54 | private: 55 | thread_cmd_e process_request(); 56 | 57 | pthread_t m_thread; 58 | engine_status_e m_status; 59 | pthread::cond m_eval; 60 | str m_line_pending; 61 | int m_eval_status; 62 | request_e m_request; 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/fox-gui/gsl_shell_window.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_GSL_SHELL_WINDOW_H 2 | #define FOXGUI_GSL_SHELL_WINDOW_H 3 | 4 | #include 5 | 6 | #include "gsl_shell_thread.h" 7 | #include "fx_console.h" 8 | 9 | class gsl_shell_window : public FXMainWindow 10 | { 11 | FXDECLARE(gsl_shell_window) 12 | public: 13 | gsl_shell_window(gsl_shell_thread* gs, io_redirect* lua_io, FXApp* a, const FXString& name, FXIcon *ic=NULL, FXIcon *mi=NULL, FXint w=0, FXint h=0); 14 | 15 | virtual ~gsl_shell_window() 16 | { 17 | delete m_file_menu; 18 | delete m_text_font; 19 | } 20 | 21 | fx_console* console() { return m_text; } 22 | 23 | virtual void create(); 24 | 25 | long on_close(FXObject* obj, FXSelector sel, void* ptr); 26 | long on_change_console(FXObject* obj, FXSelector sel, void* ptr); 27 | long on_cmd_about(FXObject* obj, FXSelector sel, void* ptr); 28 | 29 | enum 30 | { 31 | ID_CONSOLE = FXMainWindow::ID_LAST, 32 | ID_ABOUT, 33 | }; 34 | 35 | protected: 36 | gsl_shell_window() {} 37 | 38 | private: 39 | fx_console* m_text; 40 | FXStatusBar* m_status_bar; 41 | FXMenuBar* m_menu_bar; 42 | FXMenuPane* m_file_menu; 43 | FXMenuPane* m_help_menu; 44 | FXFont* m_text_font; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/fox-gui/history.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_HISTORY_H 2 | #define FOXGUI_HISTORY_H 3 | 4 | #include "agg_array.h" 5 | #include "strpp.h" 6 | 7 | class history { 8 | public: 9 | history(): m_index(0) {} 10 | 11 | ~history() 12 | { 13 | for (unsigned j = 0; j < m_lines.size(); j++) 14 | delete m_lines[j]; 15 | } 16 | 17 | void add(const char* line) 18 | { 19 | str* s = new str(line); 20 | m_lines.add(s); 21 | m_index = 0; 22 | } 23 | 24 | void remove_last() { m_lines.remove_last(); } 25 | 26 | bool is_first() const { return m_index == 0; } 27 | 28 | const char* previous() 29 | { 30 | if (m_index < (int) m_lines.size()) m_index++; 31 | const char* ln = line(m_index); 32 | return ln; 33 | } 34 | 35 | const char* next() 36 | { 37 | if (m_index > 0) m_index--; 38 | const char* ln = line(m_index); 39 | return ln; 40 | } 41 | 42 | const char* line(int j) 43 | { 44 | int sz = m_lines.size(); 45 | int index = sz - j; 46 | 47 | if (index >= 0 && index < sz) 48 | { 49 | str* s = m_lines[unsigned(index)]; 50 | return s->cstr(); 51 | } 52 | return 0; 53 | } 54 | 55 | private: 56 | agg::pod_bvector m_lines; 57 | int m_index; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/fox-gui/image_buf.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_IMAGE_BUF_H 2 | #define FOXGUI_IMAGE_BUF_H 3 | 4 | #include 5 | 6 | #include "defs.h" 7 | 8 | #include "agg_rendering_buffer.h" 9 | #include "rendering_buffer_utils.h" 10 | 11 | template 12 | struct image_gen : agg::rendering_buffer 13 | { 14 | image_gen() { } 15 | image_gen(unsigned w, unsigned h) 16 | { 17 | init(w, h); 18 | } 19 | 20 | ~image_gen() 21 | { 22 | dispose(); 23 | } 24 | 25 | bool defined() const 26 | { 27 | return (buf() != 0); 28 | } 29 | 30 | bool resize(unsigned w, unsigned h) 31 | { 32 | dispose(); 33 | return init(w, h); 34 | } 35 | 36 | void clear() 37 | { 38 | dispose(); 39 | attach(NULL, 0, 0, 0); 40 | } 41 | 42 | bool ensure_size(unsigned w, unsigned h) 43 | { 44 | if (!defined() || width() != w || height() != h) 45 | return resize(w, h); 46 | return true; 47 | } 48 | 49 | static bool match(const image_gen& a, const image_gen& b) 50 | { 51 | if (!a.defined() || !b.defined()) 52 | return false; 53 | return (a.width() == b.width() && a.height() == b.height()); 54 | } 55 | 56 | static void copy_region(image_gen& dest_img, const image_gen& src_img, const agg::rect_i r) 57 | { 58 | rendering_buffer_ro src; 59 | rendering_buffer_get_const_view(src, src_img, r, PixelSize); 60 | 61 | agg::rendering_buffer dest; 62 | rendering_buffer_get_view(dest, dest_img, r, PixelSize); 63 | 64 | dest.copy_from(src); 65 | } 66 | 67 | private: 68 | bool init(unsigned w, unsigned h) 69 | { 70 | agg::int8u* data = new(std::nothrow) agg::int8u[w * h * PixelSize]; 71 | if (likely(data)) 72 | { 73 | int stride = (FlipY ? - w * PixelSize : w * PixelSize); 74 | attach(data, w, h, stride); 75 | } 76 | return (data != 0); 77 | } 78 | 79 | void dispose() 80 | { 81 | agg::int8u* data = buf(); 82 | delete[] data; 83 | } 84 | }; 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/fox-gui/io_thread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "io_thread.h" 5 | 6 | static void* io_thread_run(void* data) 7 | { 8 | lua_io_thread* thread = (lua_io_thread*) data; 9 | thread->run(); 10 | return 0; 11 | } 12 | 13 | void lua_io_thread::run() 14 | { 15 | char buffer[128]; 16 | 17 | while (1) 18 | { 19 | int nr = m_redirect->read(buffer, 127); 20 | if (nr < 0) 21 | { 22 | fprintf(stderr, "ERROR on read: %d.\n", errno); 23 | break; 24 | } 25 | if (nr == 0) 26 | break; 27 | 28 | buffer[nr] = 0; 29 | 30 | m_io_protect->lock(); 31 | m_io_buffer->append((const FXchar*)buffer); 32 | m_io_protect->unlock(); 33 | 34 | m_io_channel->message(m_io_target, m_io_selector, (void *) this, sizeof(int)); 35 | } 36 | } 37 | 38 | void lua_io_thread::start() 39 | { 40 | pthread_attr_t attr[1]; 41 | 42 | pthread_attr_init (attr); 43 | pthread_attr_setdetachstate (attr, PTHREAD_CREATE_DETACHED); 44 | 45 | if (pthread_create (&m_thread, attr, io_thread_run, (void*)this)) 46 | { 47 | fprintf(stderr, "error creating thread"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/fox-gui/io_thread.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_IO_THREAD_H 2 | #define FOXGUI_IO_THREAD_H 3 | 4 | #include 5 | 6 | #include "gsl_shell_thread.h" 7 | #include "redirect.h" 8 | 9 | class lua_io_thread { 10 | public: 11 | lua_io_thread(io_redirect* lua_io, FXObject *io_target, FXSelector io_selector, FXMessageChannel *io_channel, FXMutex* mut, FXString* buf): 12 | m_redirect(lua_io), 13 | m_io_target(io_target), m_io_selector(io_selector), m_io_channel(io_channel), 14 | m_io_protect(mut), m_io_buffer(buf) 15 | { } 16 | 17 | void run(); 18 | void start(); 19 | 20 | private: 21 | pthread_t m_thread; 22 | io_redirect* m_redirect; 23 | FXObject *m_io_target; 24 | FXSelector m_io_selector; 25 | FXMessageChannel *m_io_channel; 26 | FXMutex* m_io_protect; 27 | FXString* m_io_buffer; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fox-gui/lua_plot_window.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_FOX_WINDOW_H 2 | #define FOXGUI_FOX_WINDOW_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include "lua.h" 9 | 10 | extern void fox_window_register (lua_State *L); 11 | 12 | extern int fox_window_new (lua_State *L); 13 | extern int fox_window_attach (lua_State *L); 14 | extern int fox_window_close (lua_State *L); 15 | extern int fox_window_slot_refresh (lua_State *L); 16 | extern int fox_window_slot_update (lua_State *L); 17 | extern int fox_window_save_slot_image (lua_State *L); 18 | extern int fox_window_restore_slot_image (lua_State *L); 19 | extern int fox_window_show (lua_State* L); 20 | 21 | __END_DECLS 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/fox-gui/meson.build: -------------------------------------------------------------------------------- 1 | fox_gui_defines = [] 2 | if host_machine.system() == 'windows' 3 | # The FOX Library needs WIN32 to be defined on windows. 4 | fox_gui_defines += '-DWIN32' 5 | endif 6 | 7 | foxgui_sources = [ 8 | 'io_thread.cpp', 'window_surface.cpp', 'fx_console.cpp', 'redirect.cpp', 9 | 'gsl_shell_interp.cpp', 'gsl_shell_thread.cpp', 'fox_gsl_shell.cpp', 10 | 'gsl_shell_window.cpp', 'window_part.cpp', 'fx_plot_canvas.cpp', 'fx_plot_window.cpp', 11 | 'lua_plot_window.cpp', 'gsl_shell_app.cpp', 'gsl-shell-fox.cpp', 12 | ] 13 | 14 | executable('gsl-shell-gui', 15 | foxgui_sources, 16 | dependencies: [libgsl_dep, libagg_dep, threads_dep, freetype_dep, luajit_dep, fox_dep], 17 | include_directories: [gsl_shell_include, cpp_utils_include], 18 | cpp_args: gsl_shell_defines + fox_gui_defines, 19 | link_with: [libluagsl, libaggplot, libgdt], 20 | link_args: gsl_shell_link_args, 21 | export_dynamic: true, 22 | win_subsystem: 'windows', 23 | install: true, 24 | install_dir: gsl_shell_bindir, 25 | ) 26 | 27 | -------------------------------------------------------------------------------- /src/fox-gui/plot_win.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franko/gsl-shell/f10af7f5201081cd9bca402b8d87143f5e44a4bc/src/fox-gui/plot_win.gif -------------------------------------------------------------------------------- /src/fox-gui/redirect.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXGUI_REDIRECT_H 2 | #define FOXGUI_REDIRECT_H 3 | 4 | class io_redirect 5 | { 6 | public: 7 | io_redirect(int stdout_bufsize, int stdin_bufsize); 8 | 9 | void start(); 10 | void stop(); 11 | int read(char *buffer, int size); 12 | int write(const char *buffer, int size); 13 | 14 | private: 15 | int fd_opipe[2]; 16 | int fd_ipipe[2]; 17 | 18 | int fd_stdout; 19 | int fd_stdin; 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/fox-gui/window_part.h: -------------------------------------------------------------------------------- 1 | 2 | #include "agg_basics.h" 3 | #include "agg_array.h" 4 | #include "agg_trans_affine.h" 5 | 6 | enum split_e { vertical, horizontal, leaf }; 7 | 8 | struct partition { 9 | short split; // should be a split_e enum value 10 | short childs_number; 11 | }; 12 | 13 | class window_part { 14 | typedef float num_type; 15 | typedef agg::rect_base rect_type; 16 | 17 | public: 18 | window_part(); 19 | 20 | bool parse(const char* split); 21 | 22 | int get_slot_index(const char* str); 23 | unsigned get_slot_number() const; 24 | 25 | agg::rect_i rect(unsigned index, int canvas_width, int canvas_height) const; 26 | 27 | private: 28 | void parse_reset(); 29 | void split(); 30 | 31 | int skip_node(int index, int& leaf_count); 32 | int goto_child_index(int pindex, int child_index, int& leaf_count); 33 | 34 | void split_rec(const rect_type& r, unsigned& k); 35 | bool parse_element(const char*& p); 36 | 37 | // The partitions are stored in linear form in m_index. 38 | // Is a node has a child its childs will follow in order 39 | // in the vector. 40 | agg::pod_bvector m_index; 41 | agg::pod_bvector m_rect; 42 | }; 43 | -------------------------------------------------------------------------------- /src/gdt/char_buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef GDT_CHAR_BUFFER_H 2 | #define GDT_CHAR_BUFFER_H 3 | 4 | struct char_buffer { 5 | char *data; 6 | size_t length; 7 | size_t size; 8 | }; 9 | 10 | extern void char_buffer_init(struct char_buffer *b, size_t sz); 11 | extern void char_buffer_free(struct char_buffer *b); 12 | extern int char_buffer_append(struct char_buffer *b, const char *str); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/gdt/gdt_index.h: -------------------------------------------------------------------------------- 1 | #ifndef GDT_INDEX_H 2 | #define GDT_INDEX_H 3 | 4 | #include "defs.h" 5 | #include "char_buffer.h" 6 | 7 | #define INDEX_AUTO 4 8 | 9 | typedef struct { 10 | struct char_buffer names[1]; 11 | int length; 12 | int size; 13 | int index[INDEX_AUTO]; 14 | } gdt_index; 15 | 16 | extern gdt_index * gdt_index_new (int alloc_size); 17 | extern void gdt_index_free (gdt_index *g); 18 | extern gdt_index * gdt_index_resize (gdt_index *g); 19 | extern int gdt_index_add (gdt_index *g, const char *str); 20 | extern const char * gdt_index_get (gdt_index *g, int index); 21 | extern int gdt_index_lookup (gdt_index *g, const char *req); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/gdt/gdt_table_priv.h: -------------------------------------------------------------------------------- 1 | #ifndef GDT_TABLE_PRIV_H 2 | #define GDT_TABLE_PRIV_H 3 | 4 | #include "gdt_index.h" 5 | 6 | enum { 7 | TAG_STRING = 0xffff0000, 8 | TAG_UNDEF = 0xfffe0000, 9 | TAG_NUMBER = 0xfff80000, 10 | }; 11 | 12 | /* NaN encoding is used to discriminate between (double) numbers 13 | and strings or undef values. 14 | For NaN values "hi" is equal to 0xfff80000 and "lo" is 0. 15 | We use values of "hi" higher then 0xfff80000 to tag non-number 16 | values. In the case of strings "lo" is used to store the string 17 | index. */ 18 | typedef union { 19 | double number; 20 | struct { 21 | unsigned int lo; 22 | unsigned int hi; 23 | } word; 24 | } gdt_element; 25 | 26 | typedef struct { 27 | int size; 28 | gdt_element *data; 29 | int ref_count; 30 | } gdt_block; 31 | 32 | struct string_array { 33 | struct char_buffer buffer[1]; 34 | int *offset_data; 35 | int offset_len; 36 | }; 37 | 38 | struct __gdt_table_cursor { 39 | int index; 40 | struct __gdt_table *table; 41 | }; 42 | 43 | #define GDT_HEADER_TEMP_SIZE 16 44 | 45 | struct __gdt_table { 46 | int size1; 47 | int size2; 48 | int tda; 49 | gdt_element *data; 50 | gdt_block *block; 51 | gdt_index *strings; 52 | struct string_array headers[1]; 53 | char header_temp[GDT_HEADER_TEMP_SIZE]; 54 | gdt_table_cursor cursor[1]; 55 | }; 56 | 57 | static const char * gdt_table_element_get_string (const gdt_table *t, const gdt_element *e); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/gdt/meson.build: -------------------------------------------------------------------------------- 1 | gdt_sources = ['char_buffer.c', 'gdt_index.c', 'gdt_table.c'] 2 | 3 | libgdt = static_library('gdt', 4 | gdt_sources, 5 | dependencies: [], 6 | include_directories: gsl_shell_include, 7 | c_args: gsl_shell_defines, 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /src/gdt/xmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef GDT_XMALLOC_H 2 | #define GDT_XMALLOC_H 3 | 4 | #include 5 | #include 6 | #include "defs.h" 7 | 8 | static inline void *xmalloc(size_t sz) 9 | { 10 | void *p = malloc(sz); 11 | if (unlikely(p == NULL)) 12 | { 13 | fputs("not enough virtual memory!\n", stderr); 14 | abort(); 15 | } 16 | return p; 17 | } 18 | 19 | static inline unsigned int round_two_power(unsigned int n) 20 | { 21 | n = n - 1; 22 | n = n | (n >> 1); 23 | n = n | (n >> 2); 24 | n = n | (n >> 4); 25 | n = n | (n >> 8); 26 | n = n | (n >> 16); 27 | n = n + 1; 28 | return n; 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/lua-gsl/fatal.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "fatal.h" 6 | 7 | void 8 | fatal_exception(const char* msg) 9 | { 10 | fputs(msg, stderr); 11 | fputs("\n", stderr); 12 | abort(); 13 | } 14 | -------------------------------------------------------------------------------- /src/lua-gsl/fatal.h: -------------------------------------------------------------------------------- 1 | #ifndef MY_FATAL_H 2 | #define MY_FATAL_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | extern void fatal_exception(const char* msg) __attribute__ ((noreturn)); 9 | 10 | __END_DECLS 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/lua-gsl/gs-types.h: -------------------------------------------------------------------------------- 1 | #ifndef GS_TYPES_H 2 | #define GS_TYPES_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | #include 9 | #include 10 | 11 | enum gs_type_e { 12 | GS_NO_TYPE = -1, 13 | GS_WINDOW = 0, 14 | GS_DRAW_SCALABLE, /* derived types are declared only after their base class */ 15 | GS_DRAW_PATH, 16 | GS_DRAW_ELLIPSE, 17 | GS_DRAW_DRAWABLE, 18 | GS_DRAW_TEXT, 19 | GS_DRAW_TEXTSHAPE, 20 | GS_DRAW_MARKER, 21 | GS_PLOT, 22 | GS_INVALID_TYPE, 23 | }; 24 | 25 | enum fp_check_e { 26 | FP_NO_CHECK = 0, 27 | FP_CHECK_NORMAL = 1 28 | }; 29 | 30 | struct gs_type { 31 | enum gs_type_e tp; 32 | const char * mt_name; 33 | const char * fullname; 34 | enum gs_type_e base_type; 35 | }; 36 | 37 | extern const char * full_type_name (lua_State *L, int narg); 38 | extern const char * type_qualified_name (int type_id); 39 | extern int gs_type_error (lua_State *L, int narg, const char *req_type); 40 | extern void * gs_new_object (size_t nbytes, lua_State *L, enum gs_type_e tp); 41 | extern void * gs_is_userdata (lua_State *L, int index, int type_id); 42 | extern void * gs_check_userdata (lua_State *L, int index, int type_id); 43 | extern int gs_gsl_errorcheck (lua_State *L, const char *routine, int status); 44 | extern void gs_set_metatable (lua_State *L, int type_id); 45 | extern double gs_check_number (lua_State *L, int index, int check_normal); 46 | 47 | extern const struct gs_type gs_type_table[]; 48 | 49 | #define GS_METATABLE(id) gs_type_table[(id)].mt_name 50 | 51 | extern int gs_type_string (lua_State *L); 52 | 53 | __END_DECLS 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/lua-gsl/lua-defs.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_DEFS_H 2 | #define LUA_DEFS_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | #include "lua.h" 8 | __END_DECLS 9 | 10 | #define INDEX_SET_ABS(L, idx) \ 11 | if ((idx) < 0 && (idx) > LUA_REGISTRYINDEX) \ 12 | (idx) = lua_gettop(L) + ((idx)+1) 13 | 14 | #define INDEX_SET_ABS_2(L, idx1, idx2) { \ 15 | int _narg = lua_gettop (L); \ 16 | if ((idx1) < 0 && (idx1) > LUA_REGISTRYINDEX) \ 17 | (idx1) = _narg + ((idx1)+1); \ 18 | if ((idx2) < 0 && (idx2) > LUA_REGISTRYINDEX) \ 19 | (idx2) = _narg + ((idx2)+1); \ 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/lua-gsl/lua-properties.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | void register_properties_index(lua_State* L, const luaL_Reg methods[], 9 | const luaL_Reg getters[], const luaL_Reg setters[]); 10 | 11 | __END_DECLS -------------------------------------------------------------------------------- /src/lua-gsl/lua-utils.h: -------------------------------------------------------------------------------- 1 | 2 | /* lua-utils.h 3 | * 4 | * Copyright (C) 2009 Francesco Abbate 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or (at 9 | * your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef LUA_UTILS_H 22 | #define LUA_UTILS_H 23 | 24 | #include "defs.h" 25 | 26 | __BEGIN_DECLS 27 | 28 | #include "lua.h" 29 | 30 | extern const char * mlua_named_optstring (lua_State *L, int index, 31 | const char *key, 32 | const char * default_value); 33 | 34 | extern const char * mlua_named_string (lua_State *L, int index, 35 | const char *key); 36 | 37 | extern lua_Number mlua_named_optnumber (lua_State *L, int index, 38 | const char *key, 39 | lua_Number default_value); 40 | 41 | extern lua_Number mlua_named_number (lua_State *L, int index, 42 | const char *key); 43 | 44 | 45 | extern int error_return(lua_State* L, const char* error_msg); 46 | extern int type_error_return(lua_State* L, int narg, const char* req_type); 47 | 48 | __END_DECLS 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/lua-gsl/meson.build: -------------------------------------------------------------------------------- 1 | luagsl_sources = [ 2 | 'lua-properties.c', 3 | 'gs-types.c', 4 | 'lua-utils.c', 5 | 'lua-gsl.c', 6 | 'str.c', 7 | 'fatal.c', 8 | 'platform.c', 9 | 'lua-filesystem.c', 10 | ] 11 | 12 | libluagsl = static_library('luagsl', 13 | luagsl_sources, 14 | dependencies: [libgsl_dep, luajit_dep], 15 | include_directories: gsl_shell_include, 16 | c_args: gsl_shell_defines, 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /src/lua-gsl/platform.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef _WIN32 6 | #include 7 | #elif __linux__ 8 | #include 9 | #include 10 | #elif __APPLE__ 11 | #include 12 | #endif 13 | 14 | void get_exe_filename(char *buf, int sz) { 15 | #if _WIN32 16 | int len = GetModuleFileName(NULL, buf, sz - 1); 17 | buf[len] = '\0'; 18 | #elif __linux__ 19 | char path[512]; 20 | sprintf(path, "/proc/%d/exe", getpid()); 21 | int len = readlink(path, buf, sz - 1); 22 | buf[len] = '\0'; 23 | #elif __APPLE__ 24 | /* use realpath to resolve a symlink if the process was launched from one. 25 | ** This happens when Homebrew installs a cack and creates a symlink in 26 | ** /usr/local/bin for launching the executable from the command line. */ 27 | unsigned size = sz; 28 | char exepath[size]; 29 | _NSGetExecutablePath(exepath, &size); 30 | realpath(exepath, buf); 31 | #else 32 | strcpy(buf, "./lite"); 33 | #endif 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/lua-gsl/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_H 2 | #define PLATFORM_H 3 | 4 | #include "defs.h" 5 | 6 | __BEGIN_DECLS 7 | 8 | extern void get_exe_filename(char *buf, int sz); 9 | 10 | __END_DECLS 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /src/lua-gsl/strpp.h: -------------------------------------------------------------------------------- 1 | #ifndef STRPP_H 2 | #define STRPP_H 3 | 4 | #include "str.h" 5 | 6 | class str : public _str { 7 | public: 8 | str(int sz = 64) { str_init(this, sz); } 9 | str(const char *s) { str_init_from_c(this, s); } 10 | str(const str& s) { str_init_from_str(this, &s); } 11 | 12 | ~str() { str_free(this); } 13 | 14 | const str& operator= (const str& s) 15 | { 16 | str_copy(this, &s); 17 | return *this; 18 | } 19 | 20 | const str& operator= (const char* s) 21 | { 22 | str_copy_c(this, s); 23 | return *this; 24 | } 25 | 26 | const char* cstr() const { return CSTR(this); } 27 | unsigned len() const { return this->length; } 28 | 29 | char operator [] (unsigned j) const { return (j < len() ? heap[j] : 0); } 30 | 31 | void append(const str& s, int sep = 0) { str_append(this, &s, sep); } 32 | void append(const char* s, int sep = 0) { str_append_c(this, s, sep); } 33 | 34 | void printf(const char* fmt, ...) { 35 | va_list ap; 36 | va_start (ap, fmt); 37 | str_vprintf (this, fmt, 0, ap); 38 | va_end (ap); 39 | } 40 | 41 | void printf_add(const char* fmt, ...) { 42 | va_list ap; 43 | va_start (ap, fmt); 44 | str_vprintf (this, fmt, 1, ap); 45 | va_end (ap); 46 | } 47 | 48 | static str print(const char* fmt, ...) { 49 | va_list ap; 50 | va_start (ap, fmt); 51 | str s; 52 | str_vprintf (&s, fmt, 0, ap); 53 | va_end (ap); 54 | return s; 55 | } 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/meson.build: -------------------------------------------------------------------------------- 1 | subdir('lua-gsl') 2 | subdir('agg-plot') 3 | subdir('gdt') 4 | subdir('console') 5 | subdir('fox-gui') 6 | 7 | -------------------------------------------------------------------------------- /subprojects/fox.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = fox 3 | url = https://github.com/franko/fox 4 | revision = v1.7.84-lhelper 5 | 6 | -------------------------------------------------------------------------------- /subprojects/gsl.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = gsl 3 | url = https://github.com/franko/gsl 4 | revision = v2.1-modules 5 | 6 | -------------------------------------------------------------------------------- /subprojects/libagg.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = libagg 3 | url = https://github.com/franko/agg 4 | revision = v2.4-lhelper4 5 | -------------------------------------------------------------------------------- /subprojects/luajit.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = luajit 3 | url = https://github.com/franko/luajit 4 | revision = v2.0.5-shortfnsyn 5 | 6 | -------------------------------------------------------------------------------- /tests/eigentests.lua: -------------------------------------------------------------------------------- 1 | a = matrix.unit(5) 2 | 3 | b = matrix.calloc(5,5) 4 | for i = 1,5 do b[i][i] = 1+0i end 5 | 6 | print("Symmetric ", eigen.symm(a, eigen.SORT_ABS_ASC)) 7 | 8 | print("Non Symmetric ", eigen.non_symm(a, eigen.SORT_ABS_ASC)) 9 | 10 | print("Hermitian ", eigen.herm(b, eigen.SORT_ABS_ASC)) 11 | 12 | print("Generalized Symmetric ", eigen.gensymm(a,a, eigen.SORT_ABS_ASC)) 13 | 14 | --print("Generalized Hermitian ", eigen.genherm(b,b, eigen.SORT_ABS_ASC)) 15 | 16 | print("General Non-Symmetric ", eigen.genv(a,a, eigen.SORT_ABS_ASC)) 17 | -------------------------------------------------------------------------------- /tests/linearalgebra-tests.lua: -------------------------------------------------------------------------------- 1 | --Test file for linear algebra functions 2 | local mat = matrix.unit(4) 3 | local mat2 = matrix.def{{4,12,-16},{12,37,-43},{-16,-43,98}} 4 | print("Det: ", matrix.det(mat)) 5 | print("QR: ", matrix.qr(mat)) 6 | print("LU: ", matrix.lu(mat2)) 7 | print("Cholesky: ", matrix.cholesky(mat2) 8 | print("Tridiogonal decomposition: ", matrix.td_decomp(mat)) 9 | print("Hessenberg decomposition: ", matrix.hessenberg_decomp(mat)) 10 | print("Hessenberg-Triangular decomposition: ", matrix.hesstri_decomp(mat,mat)) 11 | 12 | -------------------------------------------------------------------------------- /tests/test-gdt-integrate.lua: -------------------------------------------------------------------------------- 1 | local data1 = gdt.read_string [[ 2 | x y 3 | 0 0 4 | 0.523598775598299 0.5 5 | 1.0471975511966 0.866025403784439 6 | 1.5707963267949 1 7 | 2.0943951023932 0.866025403784439 8 | 2.61799387799149 0.5 9 | 3.14159265358979 0 10 | ]] 11 | 12 | local data2 = gdt.read_string [[ 13 | x s c 14 | 0 0 1 15 | 0.261799387799149 0.258819045102521 0.965925826289068 16 | 0.523598775598299 0.5 0.866025403784439 17 | 0.785398163397448 0.707106781186547 0.707106781186548 18 | 1.0471975511966 0.866025403784439 0.5 19 | 1.30899693899575 0.965925826289068 0.258819045102521 20 | 1.5707963267949 1 2.83276944882399E-16 21 | 1.83259571459405 0.965925826289068 -0.25881904510252 22 | 2.0943951023932 0.866025403784439 -0.5 23 | 2.35619449019234 0.707106781186548 -0.707106781186547 24 | 2.61799387799149 0.5 -0.866025403784439 25 | 2.87979326579064 0.258819045102521 -0.965925826289068 26 | 3.14159265358979 -3.21624529935327E-16 -1 27 | 3.40339204138894 -0.258819045102521 -0.965925826289068 28 | 3.66519142918809 -0.500000000000001 -0.866025403784438 29 | 3.92699081698724 -0.707106781186548 -0.707106781186547 30 | 4.18879020478639 -0.866025403784439 -0.5 31 | 4.45058959258554 -0.965925826289068 -0.258819045102521 32 | 4.71238898038469 -1 -1.83697019872103E-16 33 | 4.97418836818384 -0.965925826289068 0.25881904510252 34 | 5.23598775598299 -0.866025403784439 0.499999999999999 35 | 5.49778714378214 -0.707106781186548 0.707106781186547 36 | 5.75958653158129 -0.500000000000001 0.866025403784438 37 | 6.02138591938044 -0.258819045102522 0.965925826289068 38 | 6.28318530717958 -2.02128619922972E-15 1 39 | ]] 40 | 41 | local dx = 3.0 42 | local data3 = gdt.create(|i| {x = i / 256 * dx, xs = (i / 256 * dx)^2, xc = (i / 256 * dx)^3}, 0, 256) 43 | 44 | print(data3) 45 | 46 | print(gdt.integrate(data1, "y ~ x")) 47 | print(gdt.integrate(data2, "s, c, s^2, c^2 ~ x")) 48 | 49 | 50 | print(gdt.integrate(data3, "x, xs, xc ~ x")) 51 | print(dx^2/2, dx^3/3, dx^4/4) 52 | 53 | print(gdt.integrate(data3, "x", "xs"), dx^3/3) 54 | 55 | -------------------------------------------------------------------------------- /tests/test-gdt-subsample.lua: -------------------------------------------------------------------------------- 1 | local dx, N = 3.0, 8196 * 4 2 | local data = gdt.create(|i| {x = i / N * dx, y = (i / N * dx)^2}, 0, N) 3 | 4 | print("BEFORE", #data) 5 | 6 | local data_opt = gdt.sampling_optimize(data, "y ~ x", 1e-4) 7 | print("AFTER", #data_opt) 8 | 9 | gdt.plot(data_opt, "y ~ x") 10 | 11 | local data2 = gdt.create(|i| {x = i / N * dx, y = (i / N * dx)^2, s = math.sin(2 * math.pi * 12 * i / N)}, 0, N) 12 | 13 | print("BEFORE", #data) 14 | 15 | local data2_opt = gdt.sampling_optimize(data2, "y, s ~ x", {1e-4, 1e-2}) 16 | print("AFTER", #data2_opt) 17 | 18 | gdt.plot(data2_opt, "y, s ~ x") 19 | 20 | local data2_optb = gdt.sampling_optimize(data2, "x", {"y", "s"}, {1e-4, 1e-2}) 21 | print("AFTER", #data2_optb) 22 | 23 | 24 | local data3_opt = gdt.sampling_optimize(data2, "y, s*x ~ x", {1e-4, 1e-2}) 25 | print("AFTER", #data3_opt) 26 | gdt.plot(data3_opt, "y, s , s*x ~ x") 27 | 28 | -------------------------------------------------------------------------------- /todo.txt: -------------------------------------------------------------------------------- 1 | - provide help for matrix.svd function 2 | - modify get/set methods for gdt table to accept column's names 3 | - rename gdt.new to gdt.alloc and define gdt.new to initialize the table 4 | like matrix.new 5 | - in gdt.lineplot remove the parameter name from legend if only one parameter 6 | is plotted. It can be put in the title instead. 7 | - sanitize variable names in gdt-lm macro generation => exclude Lua keywords and 8 | headers that cannot be considered as Lua identifiers 9 | - add more colors and markers for generated plots 10 | - add a "correlation" function for gdt table like GNU R 11 | - carry out a complete example for PCA analysis in GNU R book (heptatlon) 12 | - bug with PREDICTED [[th_sigeb.ell] (PREDICTED)] 13 | - introduire a WHERE clause to filter data 14 | - ajouter le Degree of freedom dans le summary du gdt.lm 15 | - DONE/ dans PREDICTED il devrait verifier si la colonne n'existe pas déjà 16 | - dans gdt.plot il faut skipper les lignes undefinis au niveau de champs 17 | de aggregation 18 | - implement col_insert/append using expressions 19 | 20 | A REFLECHIR 21 | - trois mechanisms sont disponible pour travailler sur les tables (gdt) 22 | - functional approach: t:col_append("boo", |r| r.a + r.b) 23 | - simple string header like: gdt.plot(t, {"wafer", "site"}, "thickness") 24 | - GNU R like LM model specifications: "thickness ~ 1, exec_time, tool" 25 | --------------------------------------------------------------------------------