Class: Rserve::REXP::Double
Constant Summary
collapse
- NA_ARRAY =
[162, 7, 0, 0, 0, 0, 240, 127]
Constants inherited
from Rserve::REXP
MaxDebugItems, MismatchError
Instance Attribute Summary collapse
Attributes inherited from Rserve::REXP
#attr
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Vector
#==, #to_a, #vector?
#as_bytes, #as_double, #as_double_matrix, #as_factor, #as_float, #as_floats, #as_integer, #as_list, #as_matrix, #as_nested_array, #as_string, #complex?, create_data_frame, #dim, #environment?, #expression?, #factor?, #get_attribute, #has_attribute?, #inherits?, #language?, #list?, #logical?, #null?, #pair_list?, #raw?, #recursive?, #reference?, #split_array, #string?, #symbol?, #to_f, #to_i, #to_ruby, #vector?
Constructor Details
#initialize(data, attrs = nil) ⇒ Double
Returns a new instance of Double.
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rserve/rexp/double.rb', line 16
def initialize(data, attrs=nil)
@payload=case data
when Numeric
[data.to_f]
when Array
data
else
raise ArgumentError, "Should be Numeric or Array"
end
super(attrs)
end
|
Instance Attribute Details
#payload ⇒ Object
Returns the value of attribute payload.
5
6
7
|
# File 'lib/rserve/rexp/double.rb', line 5
def payload
@payload
end
|
Class Method Details
.infinite?(value) ⇒ Boolean
60
61
62
|
# File 'lib/rserve/rexp/double.rb', line 60
def self.infinite?(value)
value.respond_to?(:infinite?) and value.infinite?
end
|
Instance Method Details
#as_doubles ⇒ Object
41
42
43
44
45
|
# File 'lib/rserve/rexp/double.rb', line 41
def as_doubles
@payload.map do |v|
na?(v) ? nil : v.to_f
end
end
|
#as_integers ⇒ Object
36
37
38
39
40
|
# File 'lib/rserve/rexp/double.rb', line 36
def as_integers
@payload.map do |v|
(na?(v) or Double.infinite?(v)) ? nil : v.to_i
end
end
|
#as_strings ⇒ Object
46
47
48
|
# File 'lib/rserve/rexp/double.rb', line 46
def as_strings
@payload.map {|v| v.to_f.to_s}
end
|
#integer? ⇒ Boolean
30
31
32
|
# File 'lib/rserve/rexp/double.rb', line 30
def integer?
true
end
|
#length ⇒ Object
27
28
29
|
# File 'lib/rserve/rexp/double.rb', line 27
def length
payload.length
end
|
#na?(value = nil) ⇒ Boolean
50
51
52
53
54
55
56
57
58
|
# File 'lib/rserve/rexp/double.rb', line 50
def na?(value=nil)
return _na?(value) unless value.nil?
@payload.map {|v| _na?(v) }
end
|
#numeric? ⇒ Boolean
33
34
35
|
# File 'lib/rserve/rexp/double.rb', line 33
def numeric?
true
end
|
#to_debug_string ⇒ Object
65
66
67
68
|
# File 'lib/rserve/rexp/double.rb', line 65
def to_debug_string
t=super
t << "{" << @payload.map(&:to_s).join(",") << "}"
end
|
#to_ruby_internal ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rserve/rexp/double.rb', line 69
def to_ruby_internal
if dim
if dim.size==2
as_matrix
else
as_nested_array
end
else
super
end
end
|