class CTioga2::Data::Backends::SMathBackend

Public Class Methods

new() click to toggle source
Calls superclass method CTioga2::Data::Backends::Backend::new
# File lib/ctioga2/data/backends/backends/smath.rb, line 53
def initialize
  super()
  @samples = 30
  @u_range = -10.0..10.0
  @v_range = -10.0..10.0
end

Public Instance Methods

query_dataset(set) click to toggle source

This is called by the architecture to get the data. It first splits the set name into func@range.

# File lib/ctioga2/data/backends/backends/smath.rb, line 62
def query_dataset(set)
  name = "#{set}"

  u_values = make_dvector(@u_range, @u_samples || @samples)
  v_values = make_dvector(@v_range, @v_samples || @samples)

  if ! (set.split_at_toplevel(/:/).size > 1)
    set = "u:v:#{set}"
  end

  val_u = Dvector.new
  val_v = Dvector.new
  for u in u_values
    for v in v_values
      val_u << u
      val_v << v
    end
  end

  

  return Dataset.dataset_from_spec(name, set) do |b|
    get_data_column(b, [val_u, val_v])
  end
end

Protected Instance Methods

get_data_column(column, values) click to toggle source

Uses compute_formula to get data from

# File lib/ctioga2/data/backends/backends/smath.rb, line 113
def get_data_column(column, values)
  column.gsub!(/\b(u|v)\b/) do
    cl = if $1 == 'u'
           0
         else
           1
         end
    "(column[#{cl}])"
  end
  return Ruby.compute_formula(column, values)
end
make_dvector(range, nb_points, log = @log) click to toggle source

Turns a Range and a number of points into a Dvector

# File lib/ctioga2/data/backends/backends/smath.rb, line 92
def make_dvector(range, nb_points, log = @log)
  n = nb_points -1
  a = Dvector.new(nb_points) { |i| 
    i.to_f/(n.to_f)
  }
  # a is in [0:1] inclusive...
  if log
    delta = range.last/range.first
    # delta is positive necessarily
    a *= delta.log
    a.exp!
    a *= range.first
  else
    delta = range.last - range.first
    a *= delta
    a += range.first
  end
  return a
end