Giter Club home page Giter Club logo

Comments (7)

translunar avatar translunar commented on August 24, 2024

I cleaned up the code in a recent commit. Have you tried it with pry (which uses coderay)? It looks a little better.

from nmatrix.

agarie avatar agarie commented on August 24, 2024

Some experiments in IRB:

> n = NMatrix.random(4)
> n.pp
[[0.6299860224178115, 0.2626926192712231, 0.9008651790526774, 0.7025077672785742]
[0.6629325603072921, 0.657471929860773, 0.9601643345978037, 0.7900181731280271]
[0.22735456931808107, 0.5035327724154458, 0.6728627567703459, 0.9629883418502257]
[0.36004767980910257, 0.6542623614657115, 0.9829866207607914, 0.6299860224178115]]
 => nil 

> u = NVector.random(3)
> u.pretty_print
[0.6652767626356697
0.1188537203789306
0.8368488043457466]
 => nil
> u.pp
 => "#<NVector:0x007fad838f6668 orientation:column shape:[3,1] dtype:float64 stype:dense>" 

The result from pretty_print is correct and acceptable, but obviously pp is wrong. This is probably due to it being an alias to NMatrix#pretty_print; as NVectors have dimension 1, it calls inspect directly. Just aliasing it again in NVector solves the problem:

> class NVector
>   alias :pp :pretty_print
> end
 => nil 
> u.pp
[0.6652767626356697
0.1188537203789306
0.8368488043457466]
 => nil 

I can send a PR with this. But there's one more question: why isn't there a to_s method defined? We could simply use puts in this case. Also, what about displaying it such that the indices appear next to the values? Like:

> n = NMatrix.seq(3)
> u = NVector.random(3)
> puts n
     0   1   2
0   0   1   2
1   3   4   5
2   6   7   8
> puts u
0   0.6652767626356697
1   0.1188537203789306
2   0.8368488043457466

I think this can be useful. If you agree with me, I can implement it during the weekend.

from nmatrix.

translunar avatar translunar commented on August 24, 2024

I don't think to_s should produce multi-line output. I haven't seen any others that do.

from nmatrix.

agarie avatar agarie commented on August 24, 2024

Why not? I agree that I've never seen others do that, but in this case it's much better (and useful) than #<NMatrix:0x007fff418a3b38>. Besides, if someone unfamiliar with Ruby (e.g. a scientist trying to use SciRuby tools for his work) wants to see how the operations work in IRB, he might not know the pp library or that NMatrix has the pp method.

In any case, I'll ask other Rubyists' opinions on this :)

from nmatrix.

translunar avatar translunar commented on August 24, 2024

Why not? Again, mainly because I haven't seen any other objects that do multiline to_s output (unless with assistance from pry).

from nmatrix.

v0dro avatar v0dro commented on August 24, 2024

Can we try something like awesome_print?

from nmatrix.

translunar avatar translunar commented on August 24, 2024

No. I think we don't want to complicate NMatrix with additional dependencies, if possible.

from nmatrix.

Related Issues (20)

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.