Method: CsrMatrix::Helpers#depth

Defined in:
lib/csrmatrix/helpers.rb

#depth(array) ⇒ Object

count_nonzero



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/csrmatrix/helpers.rb', line 58

def depth(array)
  # Code from http://stackoverflow.com/questions/9545613/getting-dimension-of-multidimensional-array-in-ruby
  # Identifies the depth of an array.
  # pre  array
  # post   int depth of array
   return 0 if array.class != Array
  result = 1
  array.each do |sub_a|
    if sub_a.class == Array
      dim = depth(sub_a)
      result = dim + 1 if dim + 1 > result
    end
  end
  return result
end