Class: Malge::MultiVariableFunction
- Inherits:
-
Object
- Object
- Malge::MultiVariableFunction
- Defined in:
- lib/malge/multivariablefunction.rb
Constant Summary collapse
- TOLERANCE =
1E-10
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #abstract(conditions) ⇒ Object
-
#abstract!(conditions) ⇒ Object
Return array of data which matches the hash.
-
#data_pairs(key0, key1) ⇒ Object
return 2-dimensional array.
- #delete_axis(axis) ⇒ Object
- #delete_axis!(axis) ⇒ Object
-
#initialize(data) ⇒ MultiVariableFunction
constructor
data example: [ => 0.0, y => 0.1, z => 0.0, => 1.0, y => 1.1, z => 1.0, => 2.0, y => 2.1, z => 3.0, ].
- #unite_axes(keys, new_key = nil) ⇒ Object
-
#unite_axes!(keys, new_key = nil) ⇒ Object
unite axes with the same value.
Constructor Details
#initialize(data) ⇒ MultiVariableFunction
data example:
[
{x => 0.0, y => 0.1, z => 0.0},
{x => 1.0, y => 1.1, z => 1.0},
{x => 2.0, y => 2.1, z => 3.0},
]
19 20 21 |
# File 'lib/malge/multivariablefunction.rb', line 19 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/malge/multivariablefunction.rb', line 8 def data @data end |
Instance Method Details
#abstract(conditions) ⇒ Object
31 32 33 34 35 |
# File 'lib/malge/multivariablefunction.rb', line 31 def abstract(conditions) result = Marshal.load(Marshal.dump(self)) result.abstract!(conditions) result end |
#abstract!(conditions) ⇒ Object
Return array of data which matches the hash.
24 25 26 27 28 29 |
# File 'lib/malge/multivariablefunction.rb', line 24 def abstract!(conditions) results = @data.select do |coords| match_condition?(coords, conditions) end @data = results end |
#data_pairs(key0, key1) ⇒ Object
return 2-dimensional array. [
[x0, y0],
[x1, y1],
:
]
79 80 81 82 83 84 85 |
# File 'lib/malge/multivariablefunction.rb', line 79 def data_pairs(key0, key1) results = [] @data.each do |datum| results << [datum[key0], datum[key1]] end results end |
#delete_axis(axis) ⇒ Object
67 68 69 70 71 |
# File 'lib/malge/multivariablefunction.rb', line 67 def delete_axis(axis) result = Marshal.load(Marshal.dump(self)) result.delete_axis!(axis) result end |
#delete_axis!(axis) ⇒ Object
61 62 63 64 65 |
# File 'lib/malge/multivariablefunction.rb', line 61 def delete_axis!(axis) @data.each do |datum| datum.delete axis end end |
#unite_axes(keys, new_key = nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/malge/multivariablefunction.rb', line 55 def unite_axes(keys, new_key = nil) result = Marshal.load(Marshal.dump(self)) result.unite_axes!(keys, new_key) result end |
#unite_axes!(keys, new_key = nil) ⇒ Object
unite axes with the same value. keys : [:a, :b] new_key : default is keys
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/malge/multivariablefunction.rb', line 40 def unite_axes!(keys, new_key = nil) new_key ||= keys[0] results = [] @data.each do |datum| new_datum = Marshal.load(Marshal.dump(datum)) if same?(new_datum, keys) val = new_datum[keys[0]] keys.each {|key| new_datum.delete(key) } new_datum[new_key] = val results << new_datum end end @data = results end |