Re: Premature Optimization

From: [email protected] [mailto:[email protected]]

first = [1,0,0,0,0]
second = [1,1,0,0,0]
third = [0,0,0,1,0]

I would end up with
count = [2,1,0,1,0]

Built into Ruby:
irb(main):001:0> require ‘matrix’
=> true
irb(main):002:0> first = Vector[1,0,0,0,0]
=> Vector[1, 0, 0, 0, 0]
irb(main):003:0> second = Vector[1,1,0,0,0]
=> Vector[1, 1, 0, 0, 0]
irb(main):004:0> third = Vector[0,0,0,1,0]
=> Vector[0, 0, 0, 1, 0]
irb(main):005:0> count = first + second + third
=> Vector[2, 1, 0, 1, 0]

However, I believe that’s a pure-ruby implementation of matrices and
vectors. A quick bit of Googling looks ike RNum[1] might be crazy fast
and do what you need. I’ve never used it. I’ve also never used
NArray[2], but it might do what you need.

[1] http://rnum.rubyforge.org/
[2] http://narray.rubyforge.org/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs