Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/kmat/misc.rb
Instance Method Summary collapse
Instance Method Details
#argsort ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/kmat/misc.rb', line 71 def argsort ret = Array.new(self.size, &:itself) if block_given? ret.sort! do |a, b| yield(self[a], self[b]) end else ret.sort_by! do |elm| self[elm] end end end |
#argsort!(ary) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kmat/misc.rb', line 83 def argsort!(ary) if block_given? sort! do |a, b| yield(ary[a], ary[b]) end else sort_by! do |elm| self[elm] end end end |
#argsort_by ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/kmat/misc.rb', line 94 def argsort_by if block_given? Array.new(self.size, &:itself).sort_by! do |elm| yield(self[elm]) end else self.to_enum(:argsort_by) end end |