Module: StairCar::UMatrixTypes

Included in:
UMatrix
Defined in:
lib/stair_car/umatrix/types.rb

Instance Method Summary collapse

Instance Method Details

#sparse?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/stair_car/umatrix/types.rb', line 9

def sparse?
  @data.sparse?
end

#typeObject



5
6
7
# File 'lib/stair_car/umatrix/types.rb', line 5

def type
  return :double
end

#type_class(type, sparse, initialize_values) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/stair_car/umatrix/types.rb', line 14

def type_class(type, sparse, initialize_values)
  if sparse
    base = Java::org.ujmp.parallelcolt::ParallelColtSparseDoubleMatrix2D
  else
    base = Java::org.ujmp.core.Matrix.factory
  end

  # if sparse
  #   base = Java::org.ujmp.core.matrix.SparseMatrix.factory
  # else
  #   base = Java::org.ujmp.core.Matrix.factory
  # end

  if [:zeros, :ones, :rand, :desc, :asc].include?(initialize_values)
    if [:asc, :desc].include?(initialize_values)
      initialize_values = :zeros
    end

    if sparse && initialize_values == :zeros
      initialize_values = :new
    end

    return Proc.new { |rows, cols| base.send(initialize_values, rows, cols) }
  else
    raise "Type is not valid"
  end
end