In Torch / Lua, is there a command to parse an object (e.g. str () in R)?

I need to analyze some objects and their structure in my Torch / Lua script. I would like to use a command that behaves like str()in the R .

Do you have any suggestions?

+4
source share
2 answers

You can use a serializer to represent complex data structures in a readable way. There is a function torch.serialize , but it does not output a readable result. I wrote a Serpent serializer and a pretty-printer , which supports some parameters, which str()have, for example, the maximum nesting level for tables or the maximum number of elements in a table. It also supports custom formats, which allows some modification of the output.

+2
source

I like this module: https://github.com/kikito/inspect.lua

luarocks install inspect

then import it as follows

local inspect = require 'inspect'

the output could be something like this:

assert(inspect(setmetatable({a=1}, {b=2}) == [[{
  a = 1
  <metatable> = {
    b = 2
  }
}]]))

general use:

print(inspect(myobj))
0
source

Source: https://habr.com/ru/post/1583845/


All Articles