rserve-client 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +3 -0
- data/lib/rserve.rb +1 -1
- data/lib/rserve/protocol.rb +1 -1
- data/lib/rserve/protocol/rexpfactory.rb +13 -9
- data/lib/rserve/rexp/double.rb +49 -47
- data/lib/rserve/rexp/factor.rb +1 -0
- data/lib/rserve/rexp/integer.rb +45 -46
- data/lib/rserve/rlist.rb +34 -35
- data/lib/rserve/withnames.rb +7 -7
- metadata +3 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/lib/rserve.rb
CHANGED
data/lib/rserve/protocol.rb
CHANGED
@@ -14,7 +14,7 @@ module Rserve
|
|
14
14
|
LONG_NA=9221120237041092514 # :nodoc:
|
15
15
|
else
|
16
16
|
LONG_NA=9218868437227407266 # :nodoc:
|
17
|
-
|
17
|
+
end
|
18
18
|
# Defines from Rsrv.h
|
19
19
|
CMD_RESP=0x010000 # all responses have this flag set
|
20
20
|
RESP_OK=(CMD_RESP|0x0001) # command succeeded; returned parameters depend on the command issued
|
@@ -136,7 +136,7 @@ module Rserve
|
|
136
136
|
@cont=nil
|
137
137
|
if has_at
|
138
138
|
puts "Processing attribs:" if $DEBUG
|
139
|
-
o = attr.parse_REXP(buf,o)
|
139
|
+
o = attr.parse_REXP(buf, o)
|
140
140
|
puts "FINAL ATTRIB:" if $DEBUG
|
141
141
|
pp get_attr.as_list if $DEBUG
|
142
142
|
end
|
@@ -190,7 +190,7 @@ module Rserve
|
|
190
190
|
as=(eox-o)
|
191
191
|
i=0
|
192
192
|
d=Array.new(as)
|
193
|
-
(eox-i).times {|
|
193
|
+
(eox-i).times {|ii| d[ii]=buf[o+ii]}
|
194
194
|
o=eox
|
195
195
|
|
196
196
|
d.length.each {|j|
|
@@ -205,7 +205,7 @@ module Rserve
|
|
205
205
|
as=get_int(buf, o)
|
206
206
|
o+=4
|
207
207
|
d=Array.new(as)
|
208
|
-
as.times {|
|
208
|
+
as.times {|ai| d[ai]=buf[o+ai]}
|
209
209
|
d.collect! {|v|
|
210
210
|
if v!=0 and v!=1
|
211
211
|
REXP::Logical::NA
|
@@ -359,7 +359,7 @@ module Rserve
|
|
359
359
|
if nam.string?
|
360
360
|
names=nam.as_strings
|
361
361
|
elsif nam.vector?
|
362
|
-
names=nam.as_list.map {|
|
362
|
+
names=nam.as_list.map {|vv| vv.as_string}
|
363
363
|
end
|
364
364
|
l=Rlist.new(v,names)
|
365
365
|
@cont=(xt==XT_VECTOR_EXP) ? REXP::ExpressionVector.new(l,get_attr) : REXP::GenericVector.new(l,get_attr)
|
@@ -535,6 +535,9 @@ module Rserve
|
|
535
535
|
l+=4 if (l>0xfffff0)
|
536
536
|
l+4
|
537
537
|
end
|
538
|
+
|
539
|
+
|
540
|
+
|
538
541
|
def get_binary_representation(buf,off)
|
539
542
|
myl=get_binary_length;
|
540
543
|
is_large=(myl>0xfffff0);
|
@@ -593,7 +596,8 @@ module Rserve
|
|
593
596
|
# HACK
|
594
597
|
# On i686, NA returns [162, 7, 0, 0, 0, 0, 240, 127]
|
595
598
|
# So if we got a Double::NA, we should set mannualy this array
|
596
|
-
if v
|
599
|
+
if cont.na? v
|
600
|
+
#if v==REXP::Double::NA
|
597
601
|
buf[io,8]=REXP::Double::NA_ARRAY
|
598
602
|
else
|
599
603
|
set_long(doubleToRawLongBits(v), buf, io)
|
@@ -611,7 +615,7 @@ module Rserve
|
|
611
615
|
sa.each do |v|
|
612
616
|
if !v.nil?
|
613
617
|
b=v.unpack("C*")
|
614
|
-
b.each_with_index{|
|
618
|
+
b.each_with_index{|vv,index| buf[io+index]=vv}
|
615
619
|
io+=b.length
|
616
620
|
end
|
617
621
|
buf[io]=0
|
@@ -630,8 +634,8 @@ module Rserve
|
|
630
634
|
lst=cont.as_list
|
631
635
|
#p lst
|
632
636
|
if !lst.nil?
|
633
|
-
lst.size.times do |
|
634
|
-
x=lst.at(
|
637
|
+
lst.size.times do |ii|
|
638
|
+
x=lst.at(ii)
|
635
639
|
#puts "#{x}"
|
636
640
|
x==REXP::Null if x.nil?
|
637
641
|
#p buf
|
@@ -640,7 +644,7 @@ module Rserve
|
|
640
644
|
#p io
|
641
645
|
if(rxt==XT_LIST_TAG or rxt==XT_LANG_TAG)
|
642
646
|
|
643
|
-
io=REXPFactory.new(REXP::Symbol.new(lst.key_at(
|
647
|
+
io=REXPFactory.new(REXP::Symbol.new(lst.key_at(ii))).get_binary_representation(buf, io)
|
644
648
|
|
645
649
|
end
|
646
650
|
end #times
|
data/lib/rserve/rexp/double.rb
CHANGED
@@ -15,58 +15,60 @@ module Rserve
|
|
15
15
|
|
16
16
|
def initialize(data, attrs=nil)
|
17
17
|
@payload=case data
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
when Numeric
|
19
|
+
[data.to_f]
|
20
|
+
when Array
|
21
|
+
data
|
22
|
+
else
|
23
|
+
raise ArgumentError, "Should be Numeric or Array"
|
24
|
+
end
|
25
|
+
super(attrs)
|
26
|
+
end
|
27
|
+
def length
|
28
|
+
payload.length
|
29
|
+
end
|
30
|
+
def integer?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
def numeric?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
def as_integers
|
37
|
+
@payload.map(&:to_i)
|
38
|
+
end
|
39
|
+
def as_doubles
|
40
|
+
@payload.map do |v|
|
41
|
+
na?(v) ? NA : v.to_f
|
42
|
+
end
|
43
|
+
end
|
44
|
+
def as_strings
|
45
|
+
@payload.map {|v| v.to_f.to_s}
|
24
46
|
end
|
25
|
-
super(attrs)
|
26
|
-
end
|
27
|
-
def length
|
28
|
-
payload.length
|
29
|
-
end
|
30
|
-
def integer?
|
31
|
-
true
|
32
|
-
end
|
33
|
-
def numeric?
|
34
|
-
true
|
35
|
-
end
|
36
|
-
def as_integers
|
37
|
-
@payload.map(&:to_i)
|
38
|
-
end
|
39
|
-
def as_doubles
|
40
|
-
@payload.map(&:to_f)
|
41
|
-
end
|
42
|
-
def as_strings
|
43
|
-
@payload.map {|v| v.to_f.to_s}
|
44
|
-
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
48
|
+
def na?(value=nil)
|
49
|
+
#if value.nil?
|
50
|
+
# @payload.map {|v| v.respond_to? :nan and v.nan?}
|
51
|
+
#else
|
52
|
+
# value.respond_to? :nan? and value.nan?
|
53
|
+
#end
|
54
|
+
return ((value.is_a? Float and value.nan?) or value.to_i==NA) unless value.nil?
|
55
|
+
@payload.map {|v| ((v.is_a? Float and v.nan?) or v.to_i==NA)}
|
56
|
+
end
|
57
|
+
def to_debug_string
|
58
|
+
t=super
|
59
|
+
t << "{" << @payload.map(&:to_s).join(",") << "}"
|
60
|
+
end
|
61
|
+
def to_ruby_internal
|
62
|
+
if dim
|
63
|
+
if dim.size==2
|
64
|
+
as_matrix
|
65
|
+
else
|
66
|
+
as_nested_array
|
67
|
+
end
|
63
68
|
else
|
64
|
-
|
69
|
+
super
|
65
70
|
end
|
66
|
-
else
|
67
|
-
super
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
71
74
|
end
|
72
|
-
end
|
data/lib/rserve/rexp/factor.rb
CHANGED
data/lib/rserve/rexp/integer.rb
CHANGED
@@ -6,56 +6,55 @@ module Rserve
|
|
6
6
|
NA = -2147483648;
|
7
7
|
def initialize(data, attrs=nil)
|
8
8
|
@payload=case data
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
9
|
+
when Integer
|
10
|
+
[data]
|
11
|
+
when Numeric
|
12
|
+
[data.to_i]
|
13
|
+
when Array
|
14
|
+
data
|
15
|
+
else
|
16
|
+
raise ArgumentError, "Should be Numeric or Array"
|
17
|
+
end
|
18
|
+
super(attrs)
|
19
|
+
end
|
20
|
+
def length
|
21
|
+
payload.length
|
22
|
+
end
|
23
|
+
def integer?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
def numeric?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
def as_integers
|
30
|
+
@payload
|
31
|
+
end
|
32
|
+
def as_doubles
|
33
|
+
@payload.map(&:to_f)
|
34
|
+
end
|
35
|
+
def as_strings
|
36
|
+
@payload.map(&:to_s)
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
def na?(value=nil)
|
40
|
+
return value == NA unless value.nil?
|
41
|
+
@payload.map {|v| v==NA}
|
42
|
+
end
|
43
|
+
def to_debug_string
|
44
|
+
t=super
|
45
|
+
t << "{" << @payload.map(&:to_s).join(",") << "}"
|
46
|
+
end
|
47
|
+
def to_ruby_internal
|
48
|
+
if dim
|
49
|
+
if dim.size==2
|
50
|
+
as_matrix
|
51
|
+
else
|
52
|
+
as_nested_array
|
53
|
+
end
|
51
54
|
else
|
52
|
-
|
55
|
+
super
|
53
56
|
end
|
54
|
-
else
|
55
|
-
super
|
56
57
|
end
|
57
58
|
end
|
58
|
-
|
59
59
|
end
|
60
60
|
end
|
61
|
-
end
|
data/lib/rserve/rlist.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Rserve
|
2
2
|
class Rlist < Array
|
3
3
|
include WithNames
|
4
|
-
attr_reader :data
|
5
4
|
def initialize(data=nil, n=nil)
|
6
5
|
@names=nil
|
7
6
|
if data.nil?
|
@@ -17,41 +16,41 @@ module Rserve
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
if n
|
20
|
+
@names=Array.new(size)
|
21
|
+
n.each_index {|i| @names[i]=n[i]} if n.respond_to? :each_index
|
22
|
+
end
|
23
23
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#
|
24
|
+
def keys
|
25
|
+
@names
|
26
|
+
end
|
27
|
+
# Returns the data without names, as Ruby objects
|
28
|
+
def to_a
|
29
|
+
self.map {|d| d.to_ruby}
|
30
|
+
end
|
31
|
+
# Returns the data, as REXP
|
32
|
+
def data
|
33
|
+
self.map {|d| d}
|
34
|
+
end
|
35
|
+
def ==(o)
|
36
|
+
#p "Comparing #{self.inspect} with #{o.inspect} gives #{o.is_a? Rlist and self.data==o.data and self.names==o.names}"
|
37
|
+
o.is_a? Rlist and self.data==o.data and self.names==o.names
|
38
|
+
end
|
39
|
+
def to_s
|
40
|
+
super+"[#{size}]"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns an Array with module WithNames included
|
44
|
+
# * Unnamed list: returns an Array
|
45
|
+
# * Named List: returns a Hash. Every element without explicit name receive
|
46
|
+
# as key the number of element, 1-based
|
47
|
+
#
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
def to_ruby
|
50
|
+
data=to_a
|
51
|
+
data.extend WithNames
|
52
|
+
data.names=@names
|
53
|
+
data
|
54
|
+
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
end
|
data/lib/rserve/withnames.rb
CHANGED
@@ -16,7 +16,7 @@ module Rserve
|
|
16
16
|
def pretty_print(q)
|
17
17
|
q.group(1,'[|WN|',']') {
|
18
18
|
q.seplist(self,nil,:each_with_index) {|v,i|
|
19
|
-
|
19
|
+
if (@names.nil? or @names[i].nil?)
|
20
20
|
q.pp v
|
21
21
|
else
|
22
22
|
q.group {
|
@@ -31,11 +31,11 @@ module Rserve
|
|
31
31
|
def to_s
|
32
32
|
out=[]
|
33
33
|
self.each_with_index { |v,i|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
if !@names.nil? and !@names[i].nil?
|
35
|
+
out.push("#{@names[i]}=#{v}")
|
36
|
+
else
|
37
|
+
out.push("#{v}")
|
38
|
+
end
|
39
39
|
}
|
40
40
|
"[#{out.join(", ")}]"
|
41
41
|
end
|
@@ -141,7 +141,7 @@ module Rserve
|
|
141
141
|
i.nil? ? nil : at(i)
|
142
142
|
else
|
143
143
|
nil
|
144
|
-
|
144
|
+
end
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 5
|
9
|
+
version: 0.2.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Claudio Bustos
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
rpP0jjs0
|
36
36
|
-----END CERTIFICATE-----
|
37
37
|
|
38
|
-
date: 2010-07-
|
38
|
+
date: 2010-07-12 00:00:00 -04:00
|
39
39
|
default_executable:
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
metadata.gz.sig
CHANGED
Binary file
|