Module: NMatrix::YaleFunctions

Defined in:
lib/nmatrix/yale_functions.rb

Overview

NMatrix

A linear algebra library for scientific computation in Ruby. NMatrix is part of SciRuby.

NMatrix was originally inspired by and derived from NArray, by Masahiro Tanaka: narray.rubyforge.org

Copyright Information

SciRuby is Copyright © 2010 - 2014, Ruby Science Foundation NMatrix is Copyright © 2012 - 2014, John Woods and the Ruby Science Foundation

Please see LICENSE.txt for additional copyright notices.

Contributing

By contributing source code to SciRuby, you agree to be bound by our Contributor Agreement:

yale_functions.rb

This file contains some shortcut functions for the specialty Yale matrix extensions (mostly for debugging and experimental purposes, but sometimes applicable when you need to speed up your code a lot). ++

Instance Method Summary collapse

Instance Method Details

#yale_ja_at(i) ⇒ Object Also known as: yale_nd_row_as_array

call-seq:

yale_ja_at(i) -> Array

Returns the non-diagonal column indices which are stored in a given row.



45
46
47
# File 'lib/nmatrix/yale_functions.rb', line 45

def yale_ja_at i
  yale_nd_row(i, :keys)
end

#yale_ja_d_keys_at(i) ⇒ Object Also known as: yale_row_as_array

call-seq:

yale_ja_d_keys_at(i) -> Array

Returns the diagonal and non-digonal column indices stored in a given row.



82
83
84
85
86
# File 'lib/nmatrix/yale_functions.rb', line 82

def yale_ja_d_keys_at i
  ary = yale_nd_row(i, :keys)
  return ary if i >= self.shape[1] || self[i,i] == self.default_value
  ary << i
end

#yale_ja_d_keys_set_at(i) ⇒ Object Also known as: yale_row_as_set

call-seq:

yale_ja_d_keys_set_at(i) -> Set

Returns the diagonal and non-diagonal column indices stored in a given row.



93
94
95
96
# File 'lib/nmatrix/yale_functions.rb', line 93

def yale_ja_d_keys_set_at i
  require 'set'
  yale_ja_d_keys_at(i).to_set
end

#yale_ja_d_keys_sorted_set_at(i) ⇒ Object Also known as: yale_row_as_sorted_set

call-seq:

yale_ja_d_keys_sorted_set_at(i) -> SortedSet

Returns the diagonal and non-diagonal column indices stored in a given row.



103
104
105
106
# File 'lib/nmatrix/yale_functions.rb', line 103

def yale_ja_d_keys_sorted_set_at i
  require 'set'
  SortedSet.new(yale_row_as_array(i))
end

#yale_ja_set_at(i) ⇒ Object Also known as: yale_nd_row_as_set

call-seq:

yale_ja_set_at(i) -> Set

Returns the non-diagonal column indices which are stored in a given row, as a Set.



54
55
56
57
# File 'lib/nmatrix/yale_functions.rb', line 54

def yale_ja_set_at i
  require 'set'
  yale_nd_row(i, :keys).to_set
end

#yale_ja_sorted_set_at(i) ⇒ Object Also known as: yale_nd_row_as_sorted_set

call-seq:

yale_ja_sorted_set_at -> SortedSet

Returns the non-diagonal column indices which are stored in a given row, as a Set.



64
65
66
67
# File 'lib/nmatrix/yale_functions.rb', line 64

def yale_ja_sorted_set_at i
  require 'set'
  SortedSet.new(yale_nd_row(i, :keys))
end

#yale_nd_row_as_hash(i) ⇒ Object

call-seq:

yale_nd_row_as_hash(i) -> Hash

Returns the non-diagonal column indices and entries stored in a given row.



74
75
76
# File 'lib/nmatrix/yale_functions.rb', line 74

def yale_nd_row_as_hash i
  yale_nd_row(i, :hash)
end

#yale_nd_row_size(i) ⇒ Object

call-seq:

yale_nd_row_size(i) -> Fixnum

Returns the size of a given non-diagonal row.



37
38
39
# File 'lib/nmatrix/yale_functions.rb', line 37

def yale_nd_row_size i
  yale_ija(i+1) - yale_ija(i)
end

#yale_row_as_hash(i) ⇒ Object

call-seq:

yale_row_as_hash(i) -> Hash

Returns the diagonal and non-diagonal column indices and entries stored in a given row.



113
114
115
116
117
# File 'lib/nmatrix/yale_functions.rb', line 113

def yale_row_as_hash i
  h = yale_nd_row(i, :hash)
  return h if i >= self.shape[1] || self[i,i] == self.default_value
  h[i] = self[i,i]
end