Method: Daru::Vector#type

Defined in:
lib/daru/vector.rb

#typeObject

The type of data contained in the vector. Can be :object or :numeric. If the underlying dtype is an NMatrix, this method will return the data type of the NMatrix object.

Running through the data to figure out the kind of data is delayed to the last possible moment.



577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/daru/vector.rb', line 577

def type
  return @data.nm_dtype if dtype == :nmatrix

  if @type.nil? || @possibly_changed_type
    @type = :numeric
    each do |e|
      next if e.nil? || e.is_a?(Numeric)
      @type = :object
      break
    end
    @possibly_changed_type = false
  end

  @type
end