Giter Site home page Giter Site logo

trepl's Introduction

TREPL: A REPL for Torch

  ______             __   |  Torch7
 /_  __/__  ________/ /   |  Scientific computing for LuaJIT.
  / / / _ \/ __/ __/ _ \  |
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch
                          |  http://torch.ch

th>

A pure Lua REPL for LuaJIT, with heavy support for Torch types.

Uses Readline for tab completion.

This package installs a new binary named th, which comes packed with all these features:

Features:

  • Tab-completion on nested namespaces
  • Tab-completion on disk files (when opening a string)
  • History
  • Pretty print (table introspection and coloring)
  • Auto-print after eval (can be stopped with ;)
  • Each command is profiled, timing is reported
  • No need for '=' to print
  • Easy help with: ? funcname
  • Self help: ?
  • Shell commands with: $ cmd (example: $ ls)
  • Print all user globals with who()
  • Import a package's symbols globally with import(package)
  • Require is overloaded to provide relative search paths: require('./mylocallib/')
  • Optional strict global namespace monitoring
  • Optional async repl (based on async)

Install

Via luarocks:

luarocks install trepl

Launch

We install a binary, simple to remember:

th
> -- amazing repl!

Alternatively, you can always bring up the repl by loading it as a lib, from anywhere:

luajit
> repl = require 'trepl'
> repl()

Use

Completion:

> cor+TAB   ...  completes to: coroutine

History:

> ARROW_UP | ARROW_DOWN

Help (shortcut to Torch's help method):

> ? torch.FloatTensor
prints help...

Shell commands:

> $ ls
README.md
init.lua
trepl-scm-1.rockspec

[Lua # 2] > $ ll
...

> $ ls
...

History / last results. Two variables are used:

_RESULTS: contains the history of results:

> a = 1
> a
1
> 'test'
test
> _RESULTS
{
   1 : 1
   2 : test
}

_LAST: contains the last result
> _LAST
test

Convenient to get output from shell commands:
> $ ls -l
> _LAST
contains the results from ls -l, in a string.

Hide output. By default, TREPL always tries to dump the content of what's evaluated. Use ; to stop it.

> a = torch.Tensor(3)
> a:zero()
0
0
0
[torch.DoubleTensor of dimension 3]

> a:zero();
> 

Helpers

Colors libraries can be loaded independently:

> c = require 'trepl.colorize'
> print(c.red('a red string') .. c.Blue('a bold blue string'))

Globals

Global variables are a well known issue with Lua. th can be run with a flag -g that will monitor global variables creation and access.

Creation of a variable will generate a warning message, while access will generate an error.

th -g
> require 'sys';
created global variable: sys @ [c-module]
> a = 1
created global variable: a @ a = 1
> b
error: attempt to read undeclared variable b

Async repl [BETA]

An asynchronous repl can be started with -a. Based on async, this repl is non-blocking, and can be used to spawn/schedule asyncrhonous jobs. It is still beta, and does not yet have readline support:

th -a
> idx = 1
> async.setInterval(1000, function() print('will be printed every second - step #' .. idx) idx = idx + 1 end)
will be printed every second - step #1
will be printed every second - step #2
will be printed every second - step #3
> idx = 20
will be printed every second - step #20
will be printed every second - step #21

trepl's People

Contributors

adamlerer avatar alexisbrenon avatar archenroot avatar atcold avatar btnc avatar cdluminate avatar clementfarabet avatar colesbury avatar dmitryulyanov avatar howard0su avatar koraykv avatar lucasb-eyer avatar nhynes avatar nicholas-leonard avatar samehkhamis avatar soumith avatar szagoruyko avatar szym avatar vsergeev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trepl's Issues

Readline conflict

Hi all !

We recently installed the readline package through luarocks (https://luarocks.org/modules/peterbillam/readline). We were not able to launch torch (th) anymore.

It appears there is a conflict line 536 of init.lua of TREPL. Can someone explain me what is the readline of TREPL ? Does it have the same functionalities than the readline package ?

Thank

[feature proposal] better completion for tables

it is cool that

torch.co+[tab] completes to torch.conv2

However, it'd be cool to also have a key to show all possible completions, for example

torch.co+[shift+tab]
torch.conv2 torch.conv3 torch.cos torch.cosh

Problem when using "Who()" function

Hi

I am using torch 7 for a while now.

After reinstalling the package , I encountered a problem with the "Who()" function.
For example, when I have a model and defined a criterion ( like nn.msecriterion) the who() function gives an error that there is no size for this function. Or also, I get this error:

/usr/local/share/lua/5.1/trepl/init.lua:106: torch.CmdLine has no length operator

What can be the problem?

Thanks,
Regards,
Siavash

Command history problem

launching the REPL with th the i cannot move the curser and the command history is not working

Pressing the arrows results in : ^[[A^[[D^[[C^[[B^[[D^[[C^[[B

the luajit REPL works fine.

I installed the torch7 following the instructions on https://github.com/torch/torch7/wiki/Cheatsheet

I'm on OSx 10.7.5 with danish keyboard.
(i tried swithing to U.S International PC keyboard, but that did not solve the problem)

option to ignore local?

when debugging a script, often I want to copy blocks of code and run interactively in the trepl. However, I can't run in the repl via copy+paste, because things declared local in a script cannot see each other when run in the repl. Is there, or is there any interest, in adding a flag to ignore local so script blocks can be tested in the repl?

THArgCheck doesn't print error message from interpreter

To reproduce bug:

$> th
a = torch.randn(3,4,1)
b = torch.randn(2,4,1)
i = torch.randperm(1):long()
a:indexCopy(1, i, b)

Run the same thing in a lua scritp to get a nice error message.

Makes it impossible to debug using the th shell.

metatable tab-completions don't seem to work as expected

I like most trepl's features but the tab-completion of methods doesn't seem to work properly

require 'optim'
l = optim.Logger('out.log')
l:<TAB>

luajit alone gives:

l:add(       l:epsfile    l:idx.       l:names.     l:plot(      l:style(     l:symbols.
l:empty      l:file:      l:name       l:new(       l:setNames(  l:styles.

th (luajit with trepl) gives:

_G              break           false           io              module          pairs           repeat          sys             utils
_LAST           collectgarbage  for             ipairs          monitor_G       paths           repl_linenoise  table           while
_RESULTS        coroutine       function        jit             newproxy        pcall           repl_readline   then            who
_VERSION        debug           gcinfo          l               next            print           require         tonumber        xerror
...

Tab-completions of l.<TAB> are likewise wrong.

module 'trepl' not found

Hello
I'm trying to run a torch model and I get the following error:

usr/bin/luajit: /usr/lib/luarocks/rocks/trepl/scm-1/bin/th:104: module 'trepl' not found:
no field package.preload['trepl']
no file '/tmp/buildd/.luarocks/share/lua/5.1/trepl.lua'
no file '/tmp/buildd/.luarocks/share/lua/5.1/trepl/init.lua'
no file '/usr/share/lua/5.1/trepl.lua'
no file '/usr/share/lua/5.1/trepl/init.lua'
no file './trepl.lua'
no file '/usr/share/luajit-2.1.0-beta1/trepl.lua'
no file '/usr/local/share/lua/5.1/trepl.lua'
no file '/usr/local/share/lua/5.1/trepl/init.lua'
no file '/usr/share/lua/5.1/trepl.lua'
no file '/usr/share/lua/5.1/trepl/init.lua'
no file '/tmp/buildd/.luarocks/lib/lua/5.1/trepl.so'
no file '/usr/lib/lua/5.1/trepl.so'
no file './trepl.so'
no file '/usr/local/lib/lua/5.1/trepl.so'
no file '/usr/lib/lua/5.1/trepl.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
/usr/lib/luarocks/rocks/trepl/scm-1/bin/th:104: in main chunk
[C]: at 0x00406670

I looked up in luarocks list and it is in fact installed.

command-line options with -l are gobbled up

Original issue:
torch/torch7#76
Test case:
th test.lua -lhello

It should happen that -lhello should be passed as an argument to the lua file, but th gobbles up the -l prefixed flags irrespective of where they are. We should limit this to only processing -l flags that appear before the ".lua" file

module 'treplutils' not found

When installing Torch with ezinstall (https://github.com/torch/ezinstall), I get the following error:

$ th
/usr/local/bin/luajit: /usr/local/share/lua/5.1/trepl/init.lua:40: module 'treplutils' not found:No LuaRocks module found for treplutils
        no field package.preload['treplutils']
        no file '/root/.luarocks/share/lua/5.1/treplutils.lua'
        no file '/root/.luarocks/share/lua/5.1/treplutils/init.lua'
        no file '/usr/local/share/lua/5.1/treplutils.lua'
        no file '/usr/local/share/lua/5.1/treplutils/init.lua'
        no file './treplutils.lua'
        no file '/usr/local/share/luajit-2.0.4/treplutils.lua'
        no file '/root/.luarocks/lib/lua/5.1/treplutils.so'
        no file '/usr/local/lib/lua/5.1/treplutils.so'
        no file './treplutils.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        /usr/local/share/lua/5.1/trepl/init.lua:40: in main chunk
        [C]: in function 'require'
        /usr/local/lib/luarocks/rocks/trepl/scm-1/bin/th:104: in main chunk
        [C]: at 0x00405850

If I remove lines 40 and 50 the error doesn't show up.

40. local cutils = require 'treplutils'
50. or (not cutils.isatty())

Cannot launch with th

Hi all,
I have problem using th to launch trepl. After the program was launched, I cannot require any package. The error is:

/home/yangky/torch/install/share/lua/5.1/trepl/init.lua:363: loop or previous error loading module 'xlua'
stack traceback:
    [C]: in function 'error'
    /home/yangky/torch/install/share/lua/5.1/trepl/init.lua:363: in function 'require'
    [string "_RESULT={require 'xlua'}"]:1: in main chunk
    [C]: in function 'xpcall'
    /home/yangky/torch/install/share/lua/5.1/trepl/init.lua:630: in function 'repl'
    ...ngky/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
    [C]: at 0x00405800  

However, it's fine if I use trepl as a package in luajit

help function doesn't work

reported by @Grisson

I installed torch7 and other modules in mac by following the Cheatsheet. Somehow, the help function doesn't work. (help is nil)
Do you have any solution for this issue?

has license changed

Hi,
Thanks for sharing Trepl. I used (modified a bit) it in an online Lua REPL with torch support, tide (https://github.com/bitRadio/tide). The last time I checked license notification was "Copyright: MIT / BSD / Do whatever you want with it. Clement Farabet, 2013", so I kept it in sources. Should I change it acoording to current one ?

Regards,
Ali Sabri

No results matching query found

When I issue luarocks install trepl, I get the this error : Error: No results matching query were found.
luarocks list is :

Installed rocks:

cwrap
scm-1 (installed) - /home/radar/anaconda/lib/luarocks/rocks

luarocks
2.2.1-1 (installed) - /home/radar/anaconda/lib/luarocks/rocks

paths
scm-1 (installed) - /home/radar/anaconda/lib/luarocks/rocks

torch
scm-1 (installed) - /home/radar/anaconda/lib/luarocks/rocks

Bad colours management

setprintlevel(0) removes colours output.
noColors() adds a tab after each line. So setprintlevel(0) has noColors() correct behaviour.

Both functions are bugged.

loop or previous error loading module 'torch'

Hi,I ever saw other similar issues, but it's a little bit different…I don't know how to solve it.
Can you give me some suggestions?

when I run "th …… .lua"
/home/liming/torch/install/bin/luajit: /home/liming/torch/install/share/lua/5.1/trepl/init.lua:389: /home/liming/torch/install/share/lua/5.1/trepl/init.lua:389: loop or previous error loading module 'torch' stack traceback: [C]: in function 'error' /home/liming/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require' main_test_bound_realsense.lua:1: in main chunk [C]: in function 'dofile' ...ming/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x55cb16a8e0e0

"th" is okay. But "th> require 'nn'
/home/liming/torch/install/share/lua/5.1/trepl/init.lua:389: /home/liming/torch/install/share/lua/5.1/trepl/init.lua:389: loop or previous error loading module 'torch' stack traceback: [C]: in function 'error' /home/liming/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require' [string "_RESULT={require 'nn'}"]:1: in main chunk [C]: in function 'xpcall' /home/liming/torch/install/share/lua/5.1/trepl/init.lua:661: in function 'repl' ...ming/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:204: in main chunk [C]: at 0x55e28d56d0e0

and "luajit -ltorch" "luajit -llibtorch"
luajit: /home/liming/torch/install/share/lua/5.1/torch/init.lua:13: cannot load '/home/liming/torch/install/lib/lua/5.1/libtorch.so' stack traceback: [C]: in function 'require' /home/liming/torch/install/share/lua/5.1/torch/init.lua:13: in main chunk [C]: at 0x55abc7ff99e0 [C]: at 0x55abc7f950e0
luajit: error loading module 'libtorch' from file '/home/liming/torch/install/lib/lua/5.1/libtorch.so': libgfortran.so.4: cannot open shared object file: No such file or directory stack traceback: [C]: at 0x55c30ab91640 [C]: at 0x55c30ab819e0 [C]: at 0x55c30ab1d0e0

I also check the path "~/torch/install/lib"
libluaT.so.0 exits

io.write does not behave as expected

When the trepl environment is on, io.write stops to behave as one would expect. On luajit, I get the following behaviour:

th> io.write('tst\n')
tst
th> require 'trepl'
th> io.write('tst\n')
tst
th> repl()
th> io.write('tst\n')
tst
file (0x7f08fd7ec400)

It indeed prints the given string, but after calling repl() it also prints file (0x7f08fd7ec400). Any thoughts about what might be causing this issue ?

loading a library at command-line fails to print the error + stack-trace

The library loading at command-line with the -l flag is wrapped in pcalls, so if a library fails to load, all we see is: could not load xxxx, skipping

This is not great, as, when you want to debug something, you have to fallback to luajit to see "why" the library isn't loading.

It would be nice to not only see "could not load xxxx, skipping" but also see the stack-trace on why it did not load.

Loop or previous error loading module 'torch'

Two of the other issues seemed similar, but could someone explain the issue (and a fix) to me in simple words? I'm not sure why this is happening. I run "th file.lua -input_h5 -input_json", and the following comes up:

/home/adityac/torch/install/bin/luajit: /home/adityac/torch/install/share/lua/5.1/trepl/init.lua:384: loop or previous error loading module 'torch'
stack traceback:
[C]: in function 'error'
/home/adityac/torch/install/share/lua/5.1/trepl/init.lua:384: in function 'require'
train.lua:2: in main chunk
[C]: in function 'dofile'
...tyac/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x004064d0

Does not support colors

Hi,

The current repo does not seem to support colors in some cases.
It seems that init.lua calls noColors() if tput colors gives non-zero values (my machine gives 256).
If I comment out noColors() manually, it shows colors correctly.
Do you have any idea?

History file configuration

Hi all,

It would be great to have a way to configure the history file used.
I have different projects using Torch, and it's a mess to get non relevant history from other projects when debugging one.

Kind regards,
Alexis.

Re-Run after hitting an error

I experienced the same problem as Siavash Sakhavi in https://groups.google.com/forum/embed/?place=forum%2Ftorch7#!topic/torch7/vUp2dTkic54 while using th.
I haven't explored it further in detail, but when there is a bug in a .lua code, th runs it twice before outputting the error.

Here is a code snippet that reproduces this behaviour

require 'torch'

a = torch.Tensor({1,2,3})
print('here')
b = torch.FloatTensor({2,3,4})

c = a+b

The output after executing this file with dofile in th is

th> dofile 'tst.lua'
here    
here    
bad argument #2 to '?' (number expected, got userdata)
stack traceback:
    [C]: at 0x7f1c1963f900
    [C]: in function '__add'
    tst.lua:7: in main chunk
    [C]: in function 'dofile'
    [string "dofile 'tst.lua'"]:1: in main chunk
    [C]: in function 'xpcall'
    /home/francisco/torch/install/share/lua/5.1/trepl/init.lua:588: in function 'repl'
    ...isco/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
    [C]: at 0x00406170  

Note that the here is displayed twice.

th cannot import packages

Same problem as in Issue #33

th> require 'nn'
/Users/___/torch/install/share/lua/5.1/trepl/init.lua:363: /Users/___/torch/install/share/lua/5.1/trepl/init.lua:363: loop or previous error loading module 'torch'
stack traceback:
    [C]: in function 'error'
    /Users/___/torch/install/share/lua/5.1/trepl/init.lua:363: in function 'require'
    [string "_RESULT={require 'nn'}"]:1: in main chunk
    [C]: in function 'xpcall'
    /Users/___/torch/install/share/lua/5.1/trepl/init.lua:630: in function 'repl'
    .../___/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:187: in main chunk
    [C]: at 0x01020a11b0    

luajit -l xlua gives:

luajit: error loading module 'libsys' from file '/Users/___/torch/install/lib/lua/5.1/libsys.so':
    dlopen(/Users/___/torch/install/lib/lua/5.1/libsys.so, 6): Library not loaded: libmkl_intel_lp64.dylib
  Referenced from: /Users/___/torch/install/lib/lua/5.1/libsys.so
  Reason: image not found
stack traceback:
    [C]: at 0x010a86f960
    [C]: in function 'require'
    /Users/___/torch/install/share/lua/5.1/sys/init.lua:14: in main chunk
    [C]: in function 'require'
    /Users/___/torch/install/share/lua/5.1/xlua/init.lua:37: in main chunk
    [C]: at 0x010a8702c0
    [C]: at 0x010a7f71b0

Running on MAC OSX 10.11

ld: library not found for -lgcc_ext.10.5

Does anyone know why it does not work for me?
ld: library not found for -lgcc_ext.10.5

more:
Missing dependencies for penlight:
luafilesystem

Using http://www.luarocks.org/repositories/rocks/luafilesystem-1.6.2-1.src.rock... switching to 'build' mode
Archive: /tmp/luarocks_luarocks-rock-luafilesystem-1.6.2-1-2325/luafilesystem-1.6.2-1.src.rock
inflating: luafilesystem-1.6.2-1.rockspec
inflating: luafilesystem-1.6.2.tar.gz
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -O2 -fPIC -I/usr/local/include -c src/lfs.c -o src/lfs.o
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -bundle -undefined dynamic_lookup -all_load -o lfs.so -L/usr/local/lib src/lfs.o
ld: library not found for -lgcc_ext.10.5
collect2: error: ld returned 1 exit status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.