gsl-shell - Luajit GNU Scientific Library Shell

Intro gsl-shell์€ GSL(GNU Scientific Library์— luajit์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์–ด์กŒ๋‹ค. ๋งคํŠธ๋ฆญ์Šค, ๋ฒกํ„ฐ ๋ฐ ์—ฌ๋Ÿฌ ํ•จ์ˆ˜ ๋“ฑ์„ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๋Ÿฌ ํ•จ์ˆ˜์— ๋Œ€ํ•œ ๊ทธ๋ž˜ํ”„๋ฅผ ์ถœ๋ ฅ์„ ์ง€์›ํ•œ๋‹ค. luajit + ์ถ”๊ฐ€ ํ•จ์ˆ˜ ๋ฐ ๋ช…๋ น์–ด๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. ๋น„์Šทํ•œ ๋‹ค๋ฅธ ๋„๊ตฌ ์ค‘์— ๋งค์šฐ ์šฐ์ˆ˜ํ•œ ์—ฐ์‚ฐ ๋Šฅ๋ ฅ๊ณผ ์†๋„๋ฅผ ์ž๋ž‘ํ•œ๋‹ค. Install ์„ฑ๋Šฅ ์ตœ์ ํ™”๋ฅผ ์œ„ํ•ด ์ง์ ‘ ๋นŒ๋“œํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜ ๊นƒํ—ˆ๋ธŒ ๋งํฌ๋ฅผ ์ฐธ์กฐํ•œ๋‹ค. ๋ฐ๋น„์•ˆ, ์šฐ๋ถ„ํˆฌ์—์„œ๋Š” GSL์™ธ์— gsl-shell์€ ํŒจํ‚ค์ง€๊ฐ€ ์—†๋‹ค. ์ฒ˜์Œ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋นŒ๋“œ๋œ ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. ๋‹ค์šด๋กœ๋“œ ๋ฆด๋ฆฌ์ฆˆ๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ์œผ๋‹ˆ ์„ค๋ช…์„ ์ฐธ๊ณ ํ•ด์„œ ์ ํ•ฉํ•œ ๊ฒƒ์œผ๋กœ ๋‚ด๋ ค๋ฐ›๋Š”๋‹ค. $ sudo apt install libgsl27 libgslcblas0 $ wget https://github.com/franko/gsl-shell/releases/download/v2.3.4/gsl-shell-dynamic-linux-x86-64.tar.gz $ tar xvfz gsl-shell-dynamic-linux-x86-64.tar.gz $ ls gsl-shell $ export PATH=$PATH:$HOME/gsl-shell/bin # ~/.bashrc์— ์ถ”๊ฐ€ ๋“ฑ๋ก $ gsl-shell # ์‹คํ–‰ GSL Shell 2.3.4 -- Copyright (C) 2009-2022 Francesco Abbate GNU Scientific Library -- Copyright (C) The GSL Team LuaJIT 2.0.5 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/ JIT: ON CMOV SSE2 SSE3 SSE4.1 AMD fold cse dce fwd dse narrow loop abc sink fuse > # ๋‚˜๊ฐ€๊ธฐ(Ctrl+d) $ ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ• ๋Œ€ํ™”์‹์ด ์•„๋‹Œ ์†Œ์Šค๋ฅผ ์ž‘์„ฑํ•ด์„œ ์‹คํ–‰ํ•  ๊ฒฝ์šฐ ์•„๋ž˜ ๋ฐฉ๋ฒ•์™ธ์— #!/usr/bin/env gsl-shell์„ ์ฒซ ์ค„์— ๋„ฃ๊ณ  chmod๋กœ ์‹คํ–‰๊ถŒํ•œ์„ ์ฃผ์–ด ์ง์ ‘ ์‹คํ–‰ํ•ด๋„ ๋œ๋‹ค. ์Šคํฌ๋ฆฝํŠธ ํ™•์žฅ์ž๋ฅผ lua๋กœ ํ•˜๋Š” ๊ฒƒ์€ ํŽธ์ง‘๊ธฐ ๋“ฑ์—์„œ ๋ฌธ๋ฒ• ๊ฐ•์กฐ๋“ฑ์˜ ์ง€์›์„ ๋ฐ›๊ธฐ ์œ„ํ•จ๋„ ์žˆ๊ณ  lua์˜ ๋ฌธ๋ฒ•์„ ๋”ฐ๋ฅด๊ธฐ ๋•Œ๋ฌธ์ด๊ธฐ๋„ ํ•˜๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ lua๋‚˜ luajit์—์„œ๋Š” ์ •์ƒ ๋™์ž‘ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์‹๋ณ„์ด ๊ฐ€๋Šฅํ•œ ํด๋”๋ฅผ ๋งŒ๋“ค๊ณ  ์ •๋ฆฌํ•ด ๋‘๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. $ gsl-shell --help $ gsl-shell # ๋Œ€ํ™”์‹ ์‚ฌ์šฉ $ gsl-shell my-program.lua # ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰ ์ด๋ ‡๊ฒŒ ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋‹ค๋ฉด ์•„๋ž˜ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉด ๋œ๋‹ค. ์ด๊ฒƒ์„ ์–ด๋–ป๊ฒŒ ์“ฐ๋Š”๊ฐ€๋Š” ์ž์‹ ์—๊ฒŒ ๋‹ฌ๋ ธ๋‹ค. GSL์— ์–ด๋А์ •๋„ ์•„๋Š” ์‚ฌ์šฉ์ž๋ผ๋ฉด ๋”์šฑ ์ˆ˜์›”ํ•  ๊ฒƒ์ด๋‹ค. ์ฐธ๊ณ ๋กœ ์„ค์น˜๋œ GSL ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€๋„ ๋‚˜์™€ ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ ํ•œ๋‹ค. ๊ธฐํƒ€ ๋„์›€๋ง ๋ฌธ์„œ๋Œ€๋กœ use "math" ๋“ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค. gsl-shell/share/gsl-shell/import.lua ์„ ์ˆ˜์ •ํ•œ๋‹ค. ... -- ์•„๋ž˜ ๋ฌธ์žฅ์„ ์ฃผ์„์ฒ˜๋ฆฌํ•˜๊ณ  ๊ทธ ์•„๋ž˜ ๋ฌธ์žฅ์œผ๋กœ ๊ณ ์นœ๋‹ค. -- local level = getinfo(2, "") and 2 or 0 local level = 2 ๋Œ€ํ™”ํ˜• ๋ชจ๋“œ ์‚ฌ์šฉ์‹œ์— rlwrap์„ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ํŽธ๋ฆฌํ•˜๋‹ค. ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“ˆ๊ณผ ํ•จ์ˆ˜๋ฅผ ํŽธ์ง‘๊ธฐ์—์„œ ์ž๋™์™„์„ฑ, ๊ฒ€์ƒ‰ ๋“ฑ์„ ์ง€์›ํ•˜๋Š” ๊ฒƒ์€ ์•„์ง ๋ชจ๋ฅธ๋‹ค. ์ตœ์†Œํ•œ ํ•จ์ˆ˜ ์ด๋ฆ„์„ ์ถ”์ถœํ•ด์„œ vim ๋“ฑ๊ณผ ์—ฐ๋™ํ•˜๊ฑฐ๋‚˜ grep์„ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์‹œ์ž‘ํ•˜๊ธฐ๋กœ ํ•œ๋‹ค. ๋ฌธ์„œ์ž‘์„ฑ์‹œ ์ˆ˜ํ•™์‹ ํ‘œํ˜„ ๊ด€๋ จ ํ”„๋กœ๊ทธ๋žจ(์Šคํฌ๋ฆฝํŠธ)๋ฅผ ์ž‘์„ฑํ•œ ํ›„ ๋„์›€๋ง์ด๋‚˜ ๋ฌธ์„œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์€ ๋งˆํฌ๋‹ค์šด(markdown) ๋ฌธ์„œ์— latex ๋ฌธ๋ฒ•์œผ๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์‚ฌ์šฉ๋ฐฉ๋ฒ•์„ ์ฐธ์กฐํ•œ๋‹ค. ์ฆ‰, ๋ฌธ์žฅ ์ค‘์—๋Š” $์ˆ˜์‹$ ์œผ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ๋…๋ฆฝ์ ์ธ ์ˆ˜์‹์€ $$์ˆ˜์‹$$์œผ๋กœ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๊นƒํ—ˆ๋ธŒ๋‚˜ ๊ธฐํƒ€ ์›นํŽ˜์ด์ง€์—์„œ ์ด๋ฅผ ์ž˜ ์ง€์›ํ•œ๋‹ค. vscode์—์„œ๋Š” markdown all in one ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•˜๋ฉด ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋กœ ์‹ค์‹œ๊ฐ„์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ฌผ๋ก  ์ˆ˜ํ•™ํ‘œํ˜„์‹๋„ ์ง€์›ํ•œ๋‹ค. vim์—์„œ๋Š” hugo๋กœ ๋กœ์ปฌ์—์„œ ์„œ๋ฒ„๋ฅผ ๋„์–ด ์‹ค์‹œ๊ฐ„ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ firefox์˜ markdown์ง€์› ๋ชจ๋“ˆ์ธ markdown viewer webtext๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‹ค์‹œ๊ฐ„ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ์ด์™€ ๊ด€๋ จ๋œ ์‚ฌํ•ญ์€ ๋‹ค๋ฅธ ๋ฌธ์„œ๋กœ ์ •๋ฆฌํ•ด ๋ณผ ์ƒ๊ฐ์ด๋‹ค. Links GSL Shell project page https://github.com/franko/gsl-shell/ GSL Documentation https://franko.github.io/gsl-shell/ Download Release https://github.com/franko/gsl-shell/releases/tag/v2.3.4

2023-02-01 ยท 405 words

LuaFun - LuaJit Functional

Intro LuaFun ์ •์˜ - LuaJit Hight Performance Functional Programming Library luajit์˜ ๋‚ด์žฅํ•จ์ˆ˜๋ฅผ ํ™•์žฅํ•˜์—ฌ ๋‹ค์–‘ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๋•๋Š”๋‹ค. ํ•˜๋‚˜์”ฉ ๊ณต๋ถ€ํ•ด์„œ ํ™œ์šฉํ•˜๋ฉด ๋งค์šฐ ๊ฐ•๋ ฅํ•œ ํˆด์ด ๋  ๊ฒƒ์ด๋‹ค. Usage ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ• $ git clone https://github.com/luafun/luafun.git $ cd luafun $ luajit -i > -- Functional style > require "fun" () > -- calculate sum(x for x^2 in 1..n) > n = 100 > print(reduce(operator.add, 0, map(function(x) return x^2 end, range(n)))) 328350 > -- Object-oriented style > local fun = require "fun" > -- calculate sum(x for x^2 in 1..n) > print(fun.range(n):map(function(x) return x^2 end):reduce(operator.add, 0)) 328350 Using the Library Links github https://github.com/luafun/luafun Document https://luafun.github.io/

2022-10-12 ยท 99 words

Lfs-ffi - LuaJit FFI Lua File System

Intro luaJit์šฉ Lua File System ๋ชจ๋“ˆ ffi๋ฅผ ์ด์šฉํ•œ lfs์ด๋ฉฐ lua์˜ lfs ๋ชจ๋“ˆ๊ณผ ๋˜‘๊ฐ™๋‹ค. ํŒŒ์ผ์‹œ์Šคํ…œ์„ ๋‹ค๋ฃจ๋Š” ํ™•์žฅ ๋ชจ๋“ˆ์ด๋‹ค. ๋ฆฌ๋ˆ…์Šค ์ „์šฉ์ด๋‹ค. ์œˆ๋„์šฐ์ฆˆ์šฉ์€ ์•„๋ž˜ ๊นƒํ—ˆ๋ธŒ์— ๊ฐ€๋ฉด ์•ˆ๋‚ด๊ฐ€ ์žˆ๋‹ค. ์„ค์น˜ luarocks๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์ง์ ‘ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ์‚ฌ์šฉ Links Github https://github.com/spacewander/luafilesystem

2022-10-12 ยท 34 words

Lua - Interactive Mode

2023-08-11: rlwarp + readline์„ ํ™œ์šฉํ•œ ํ‚ค์›Œ๋“œ ์™„์„ฑ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ Intro ์ฝ”๋”ฉ์„ ํ•˜๊ธฐ ์ „ ๋˜๋Š” ๋น ๋ฅธ ํ™•์ธ์„ ์œ„ํ•ด ์ธํ„ฐ์—‘ํ‹ฐ๋ธŒ ๋ชจ๋“œ๋ฅผ ์‚ฌ์šฉ ๊ฐ„๋‹จํ•œ ํ…Œ์ŠคํŠธ๋‚˜ ๋ช‡๊ฐ€์ง€ ์‹คํ—˜์„ ํ•ด๋ณด๋Š” ์šฉ๋„๋กœ์„œ ์ข‹๋‹ค. ilua๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด jupyter console, notebook ๋“ฑ์œผ๋กœ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. Execute String $ lua -e 'print("hello world")' hello world Interactive Mode lua -i ๋˜๋Š” luajit -i ๋กœ interactive mode๋กœ ์ง„์ž… -i ์˜ต์…˜์ด ์—†์–ด๋„ ์ง„์ž… ๊ฐ€๋Šฅ local ๋ณ€์ˆ˜๊ฐ€ ๋‹ค์Œ ๋ผ์ธ์—์„œ ์ธ์‹๋˜์ง€ ์•Š๋Š”๋‹ค. ์‚ฌ์šฉํ•  ๋•Œ ์ฃผ์˜ $ lua -i -- ๋˜๋Š” luajit -i > local a = 'hello world' -- local ๋ณ€์ˆ˜ ์„ค์ • > print(a) -- print nil -- ๊ฒฐ๊ณผ: nil > a = 'hello world' -- Global ๋ณ€์ˆ˜ ์„ค์ • > print(a) -- print hello world -- ๊ฒฐ๊ณผ: hello world > os.exit() -- ์ข…๋ฃŒ: ๋˜๋Š” Ctrl+d, Ctrl+c Opening Lua File > f = assert(loadfile('foo.lua') -- luaํŒŒ์ผ ๋กœ๋“œ > f() -- ์‹คํ–‰ > dofile('foo.lua') -- ๋กœ๋“œ ๋ฐ ์‹คํ–‰ > m = require('mymodule') -- mymodule.lua ๋ชจ๋“ˆ ๋กœ๋“œ > m.parse() -- ๋ชจ๋“ˆ๋‚ด ํ•จ์ˆ˜ ์‹คํ–‰ Load Libary Example -- file 'lib1.lua' function norm(x,y) local n2 = x^2 + y^2 return math.sqrt(n2) end function twice(x) return 2*x end > dofile('lib1.lua') -- load your library > n = norm(3.4, 1.0) -- using lib1.lua functions > print(twice(n)) -- using twice functions Command Line Arguments (-- /dev/null ์˜ต์…˜ ์ฃผ๋ชฉ) $ lua -i -- /dev/null one two three > print(arg[1]) -- one > print(arg[2]) -- two > print(arg[3]) -- three > print(arg[0]) -- /dev/null Lua, LuaJit line completion like in bash bash์—์„œ line completion๊ณผ ์œ ์‚ฌํ•œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ rlwrap ํ™œ์šฉ - -a:always-readline,-c:complete-filenames,-e:extra-char-after-completion $ sudo apt install rlwrap $ alias luajit='rlwrap -ac -e "" -pRed luajit' # add this line to ~/.bashrc $ luajit > = 2 + 2 4 > = 2 + 2 --> ํ™”์‚ดํ‚ค๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒ์œ„ ๋ช…๋ น๋ผ์ธ์„ ๋ถˆ๋Ÿฌ ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. rlwarp์˜ readline์„ ํ™œ์šฉํ•œ ๋ช…๋ น์–ด ์™„์„ฑ: Dictionary ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ์‚ฌ์šฉ. $ echo "print local assert string ..." > ~/.luadict $ alias luajit='rlwrap -b "" -f $HOME/.luadic -pRed -ca -e "" luajit' $ luajit > ass(-> Press Tab Key anc Check) iLua : with Jupyter Jupyter์˜ ๋ง‰๊ฐ•ํ•œ ์ง€์›์•„๋ž˜ ์ฝ˜์†”ํ˜• ์ธํ„ฐ์—‘ํ‹ฐ๋ธŒ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฝ”๋“œ์™„์„ฑ ๋ฐ vi edit mode ๊ทธ๋ฆฌ๊ณ  ๋ณ€์ˆ˜๋ฅผ ์ง์ ‘ ์ถœ๋ ฅ๊ฐ€๋Šฅํ•˜๋‹ค. ๋ฌผ๋ก  ํŠน์„ฑ์ƒ local ๋ณ€์ˆ˜๋Š” ์—ญ์‹œ ์ง€์›๋˜์ง€ ์•Š๋Š”๋‹ค. ํ˜„์žฌ๋กœ์„œ๋Š” ๊ทธ๋ ‡๋‹ค. ~/.local ์ดํ•˜์— jupyter ๋ฐ ilua๊ฐ€ ์„ค์น˜๋œ๋‹ค. ์•„๋ž˜์ฒ˜๋Ÿผ vi edit mode๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋”์šฑ ํŽธ๋ฆฌํ•˜๋‹ค. $ pip install ilua $ echo "c.ZMQTerminalInteractiveShell.editing_mode='vi'" > ~/.jupyter/jupyter_console_config.py $ jupyter console -h # help $ jupyter kernelspec list # ๋‚ด์žฅ ์ปค๋„ ์ŠคํŽ™ ํ™•์ธ $ ~/.local/bin/ilua -i lua[jit] # ์‹คํ–‰ $ echo "alias ilua='ilua -i luajit'" >> ~/.bashrc # luajit ์ „์šฉ alias $ source ~/.bashrc $ ilua Links https://www.lua.org/pil/1.1.html https://www.tutorialspoint.com/command-line-arguments-in-lua https://lua-users.org/wiki/InteractiveLua https://github.com/guysv/ilua https://jupyter-console.readthedocs.io/en/latest/config_options.html

2022-09-22 ยท (updated 2023-08-11) ยท 422 words