From: Logan Capaldo Date: 2006-02-17T08:20:11+09:00 Subject: Re: dot-product operators and strides for linear algebra --Apple-Mail-3-763520958 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Feb 16, 2006, at 5:59 PM, wrote: > My assumption is that is might be possible to extend ruby with > reasonable effort to add the additional ".*" "./" and ".^2" binary > operators and the transpose / conjugate transpose operators. For > the standard ruby this function would just do the same as their > scalar conterparts, however, when implementing a matrix class > these additional operators can become alive and be used to > implement the elementwise dot operations. That's an especially poor choice of operator name ;) a * b == a.*(b) You could add a method called .*, but you couldn't call it in the normal manner, you'd have to say: a.send(".*", b) which I don't think is what you were looking for. As for "strides", have you seen ranges? 0..9 # 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 1...10 # 1, 2, 3, 4, 5, 6, 7, 8, 9 As for having an alternative step, you can use #step, 1.step(10, 2) { |x| p x } 1 3 5 7 9 To turn a step into a range-like object (instead of a method) use an enumerator: require 'enumerator' zero_to_twentyfive_by_five = 0.to_enum(:step, 25, 5) zero_to_twentyfive_by_five.each { |x| p x } 0 5 10 15 20 25 In 1.9 you don't even need to use the to_enum, ie you could simply write zero_to_twentyfive_by_five = 0.step(25,5) --Apple-Mail-3-763520958--