lib/nmatrix/shortcuts.rb in nmatrix-0.0.9 vs lib/nmatrix/shortcuts.rb in nmatrix-0.1.0.rc1

- old
+ new

@@ -7,12 +7,12 @@ # NMatrix was originally inspired by and derived from NArray, by # Masahiro Tanaka: http://narray.rubyforge.org # # == Copyright Information # -# SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation -# NMatrix is Copyright (c) 2013, Ruby Science Foundation +# SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation +# NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation # # Please see LICENSE.txt for additional copyright notices. # # == Contributing # @@ -293,10 +293,18 @@ # # call-seq: # seq(shape) -> NMatrix # seq(shape, options) -> NMatrix + # bindgen(shape) -> NMatrix of :byte + # indgen(shape) -> NMatrix of :int64 + # findgen(shape) -> NMatrix of :float32 + # dindgen(shape) -> NMatrix of :float64 + # cindgen(shape) -> NMatrix of :complex64 + # zindgen(shape) -> NMatrix of :complex128 + # rindgen(shape) -> NMatrix of :rational128 + # rbindgen(shape) -> NMatrix of :object # # Creates a matrix filled with a sequence of integers starting at zero. # # * *Arguments* : # - +shape+ -> Array (or integer for square matrix) specifying the dimensions. @@ -320,69 +328,14 @@ # It'll produce :int32, except if a dtype is provided. NMatrix.new(shape, values, {:stype => :dense}.merge(options)) end - # - # call-seq: - # indgen(size) -> NMatrix - # - # Returns an integer NMatrix. Equivalent to <tt>seq(n, dtype: :int32)</tt>. - # - # * *Arguments* : - # - +shape+ -> Shape of the sequence. - # * *Returns* : - # - NMatrix with dtype +:int32+. - # - def indgen(shape) - NMatrix.seq(shape, dtype: :int32) + {:bindgen => :byte, :indgen => :int64, :findgen => :float32, :dindgen => :float64, + :cindgen => :complex64, :zindgen => :complex128, + :rindgen => :rational128, :rbindgen => :object}.each_pair do |meth, dtype| + define_method(meth) { |shape| NMatrix.seq(shape, :dtype => dtype) } end - - # - # call-seq: - # findgen(shape) -> NMatrix - # - # Returns a float NMatrix. Equivalent to <tt>seq(n, dtype: :float32)</tt>. - # - # * *Arguments* : - # - +shape+ -> Shape of the sequence. - # * *Returns* : - # - NMatrix with dtype +:float32+. - # - def findgen(shape) - NMatrix.seq(shape, dtype: :float32) - end - - # - # call-seq: - # bindgen(size) -> NMatrix - # - # Returns a byte NMatrix. Equivalent to <tt>seq(n, dtype: :byte)</tt>. - # - # * *Arguments* : - # - +size+ -> Shape of the sequence. - # * *Returns* : - # - NMatrix with dtype +:byte+. - # - def bindgen(shape) - NMatrix.seq(shape, dtype: :byte) - end - - # - # call-seq: - # cindgen(shape) -> NMatrix - # - # Returns a complex NMatrix. Equivalent to <tt>seq(n, dtype: :complex64)</tt>. - # - # * *Arguments* : - # - +shape+ -> Shape of the sequence. - # * *Returns* : - # - NMatrix with dtype +:complex64+. - # - def cindgen(shape) - NMatrix.seq(shape, dtype: :complex64) - end - end end module NVector