GithubHelp home page GithubHelp logo

google-deepmind / lua-pprint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rosejn/lua-pprint

16.0 17.0 16.0 24 KB

A pretty print library for torch and lua.

License: MIT License

Lua 100.00%

lua-pprint's Introduction

pprint

Pretty Printing for Torch and Lua.

pprint will print a human readable printout of Lua tables and torch tensors.

Features

The visual improvements offered by pprint are the following:

  • Keys are printed alphabetically
  • Nested tables are indented
  • Loops are detected
  • Metatable info is printed
  • Torch tensors are printed if they contain less than 20 elements, otherwise just the dimensions are printed

Differences with Penlight.pretty

All the mentioned features, except for loop detection, are not included in Penlight.pretty. In addition Penlight.pretty substitutes loops by a <cycle> tag, making it impossible to see the table causing the loop.

Apart from this, Penlight.pretty introduces new lines per table element, whereas pprint only creates them based on non-numerical indices of the table.

Usage

There are different ways in which pprint can be used:

General (torch and lua) usages

  • Using pprint(data) directly, as seen in the example below:
require 'pprint'
a = {1, 2}
a[3] = a
a[4] = torch.zeros(21)
pprint(a)

Outputs:

{ 1, 2, { 1, 2, { 1, 2, { 1, 2, {...}, [torch.DoubleTensor of dimension 21] },
[torch.DoubleTensor of dimension 21] }, [torch.DoubleTensor of dimension 21] },
[torch.DoubleTensor of dimension 21] }
  • Calling pprint.pretty_string(data), which differs from pprint(data) in that the method returns the generated string instead of printing it.

  • Calling pprint.string(data), which is the inline result version of pprint.pretty_string(data).

  • Using pprint.printer() to create a printer that returns a the concatenated pretty_string version of an arbitrary amount of parameters.

  • When printing a table, the default depth is 4. This depth can be modified:

require 'pprint'
a = {1, {2, {3, {4, {5}}}}}
pprint(a, 2)
print(pprint.pretty_string(a, 3))
pprint(a)

Outputs:

{ 1, { 2, {...} } }	
{ 1, { 2, { 3, {...} } } }	
{ 1, { 2, { 3, { 4, {...} } } } }

Tensor specific usage

  • pprint.dims(tensor) returns a string containing the dimensions of the tensor passed as an argument.

  • pprint.info(data) returns a string containing information of the tensors (dimensions, minimum value, mean value, maximum value, type) found in data.

lua-pprint's People

Contributors

adria-p avatar akfidjeland avatar alschua avatar d11 avatar fidlej avatar georgostrovski avatar jucor avatar rosejn avatar sergomezcol avatar sermanet avatar sracaniere avatar timharley avatar zoso95 avatar

Stargazers

 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  avatar  avatar

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.