Comments (7)
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.
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.
I don't think to_s
should produce multi-line output. I haven't seen any others that do.
from nmatrix.
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.
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.
Can we try something like awesome_print?
from nmatrix.
No. I think we don't want to complicate NMatrix with additional dependencies, if possible.
from nmatrix.
Related Issues (20)
- Fix travis-ci rdoc problem on mac osx builds
- MRI segmentation fault at unknown location in code HOT 15
- Calculate rank of matrix based on SVD HOT 1
- More user-friendly SVD interface HOT 8
- Update Travis CI for current Ruby options [critical]
- Concatenate matrices by specifying them in an Array HOT 3
- Boolean indexing
- Check equality with tolerance HOT 1
- More descriptive TypeError from #dot HOT 1
- Can we stop using ALLOCA_N in C++? HOT 3
- MKL support out-of-the-box? HOT 5
- Add Ruby 2.5 and 2.6 to travis configuration HOT 7
- Installation error for MaxOSX and Ubuntu HOT 4
- There is a method in nmatrix for matrix exponential? HOT 9
- puts or p on simple matrix crashes HOT 2
- lib/nmatrix/nmatrix.rb:47:in `require_relative': superclass mismatch for class NMatrix (TypeError) HOT 1
- Is there a 'argmax' method for NMatrix? HOT 1
- '10.2.1' < '4.3.0' is true
- Last argument as keyword parameters is deprecated in Ruby 2.7
- Dir.exists? removed in Ruby 3.2 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nmatrix.