rserve-client 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,6 @@
1
+ === 0.2.3 / 2010-07-02
2
+ * Bug fix: assignation of double vector with NA doesn't work right
3
+
1
4
  === 0.2.2 / 2010-06-24
2
5
  * ¿Bug? fix: a R matrix with a 0 dims raise an error [clbustos]
3
6
  * Bug fix on rexpfactory: typo on creation of S4
@@ -1,7 +1,7 @@
1
1
  require 'socket'
2
2
  require 'rbconfig'
3
3
  module Rserve
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  ON_WINDOWS=RbConfig::CONFIG['arch']=~/mswin|mingw/
6
6
  end
7
7
 
@@ -5,6 +5,7 @@ module Rserve
5
5
 
6
6
  ERROR_DESCRIPTIONS={
7
7
  2=>'Invalid expression',
8
+ 3=>'Parse error',
8
9
  127=>'Unknown variable/method'}
9
10
 
10
11
  def initialize(cmd, cont)
@@ -209,6 +209,7 @@ module Rserve
209
209
  def longBitsToDouble(bits)
210
210
  (bits==LONG_NA) ? Rserve::REXP::Double::NA : [bits].pack("Q").unpack("d")[0]
211
211
  end
212
+
212
213
  # Complete version of longBitsToDouble, as Java documentation established
213
214
  def longBitsToDouble_old(bits) # :nodoc:
214
215
  s = ((bits >> 63) == 0) ? 1 : -1;
@@ -80,6 +80,7 @@ module Rserve
80
80
  STDERR.puts("Warning: #{type} SEXP size mismatch")
81
81
  end
82
82
  def initialize(*args)
83
+ @attr=nil
83
84
  if args.size==0
84
85
 
85
86
  elsif
@@ -563,6 +564,7 @@ module Rserve
563
564
  elsif(rxt==XT_INT)
564
565
  set_int(cont.as_integer, buf, off)
565
566
  elsif(rxt==XT_DOUBLE)
567
+
566
568
  set_long(doubleToRawLongBits(cont.as_double), buf, off)
567
569
  elsif(rxt==XT_ARRAY_INT)
568
570
  ia=cont.as_integers
@@ -585,10 +587,17 @@ module Rserve
585
587
  end
586
588
 
587
589
  elsif(rxt==XT_ARRAY_DOUBLE)
588
- da=cont.as_doubles
590
+ da=cont.payload
589
591
  io=off
590
592
  da.each do |v|
591
- set_long(doubleToRawLongBits(v),buf,io)
593
+ # HACK
594
+ # On i686, NA returns [162, 7, 0, 0, 0, 0, 240, 127]
595
+ # So if we got a Double::NA, we should set mannualy this array
596
+ if v==REXP::Double::NA
597
+ buf[io,8]=REXP::Double::NA_ARRAY
598
+ else
599
+ set_long(doubleToRawLongBits(v), buf, io)
600
+ end
592
601
  io+=8
593
602
  end
594
603
  elsif(rxt==XT_RAW)
@@ -10,7 +10,9 @@ module Rserve
10
10
  else
11
11
  NA = 0x100000000007a2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
12
12
  end
13
-
13
+
14
+ NA_ARRAY=[162, 7, 0, 0, 0, 0, 240, 127]
15
+
14
16
  def initialize(data, attrs=nil)
15
17
  @payload=case data
16
18
  when Numeric
@@ -50,6 +50,11 @@ describe Rserve::Connection do
50
50
  @r.assign("x","a string")
51
51
  @r.eval("x").to_ruby.should=="a string"
52
52
  end
53
+ it "should assign an array with nils values" do
54
+
55
+ @r.assign('x',[1.0,2.5,nil])
56
+ @r.eval('x').to_ruby.should==[1.0,2.5,nil]
57
+ end
53
58
 
54
59
  end
55
60
  describe "assign using REXPs" do
@@ -64,7 +69,30 @@ describe Rserve::Connection do
64
69
  @r.assign("x", rexp)
65
70
  @r.eval("x").should==rexp
66
71
  end
72
+ it "should assign a double with nils and set correctly the nils" do
73
+ rexp=Rserve::REXP::Double.new([1.5, Rserve::REXP::Double::NA, -1.5])
74
+ @r.assign("x", rexp)
75
+ @r.eval('is.na(x)').to_ruby.should==[false,true,false]
76
+ end
77
+ it "should assign a integer with nils and set correctly the nils" do
78
+ rexp=Rserve::REXP::Integer.new([1, Rserve::REXP::Integer::NA, 2])
79
+ @r.assign("x", rexp)
80
+ @r.eval('is.na(x)').to_ruby.should==[false,true,false]
81
+ end
67
82
 
83
+
84
+ it "should assign a double with nils and return correct values" do
85
+ rexp=Rserve::REXP::Double.new([1.5,Rserve::REXP::Double::NA, -1.5])
86
+ @r.assign("x", rexp)
87
+ rexp_out=@r.eval("x")
88
+ rexp_out.payload.should==rexp.payload
89
+ end
90
+ it "should assign a integer with nils and return correct values" do
91
+ rexp=Rserve::REXP::Integer.new([1,Rserve::REXP::Integer::NA, 2])
92
+ @r.assign("x", rexp)
93
+ rexp_out=@r.eval("x")
94
+ rexp_out.payload.should==rexp.payload
95
+ end
68
96
  it "should assign a null" do
69
97
  rexp=Rserve::REXP::Null.new
70
98
  @r.assign("x", rexp)
@@ -12,9 +12,6 @@ describe Rserve::REXP::Double do
12
12
  a=Rserve::REXP::Double.new(payload)
13
13
  a.payload.should==[1.1]
14
14
  end
15
-
16
-
17
-
18
15
  end
19
16
  describe "NA management" do
20
17
  before do
@@ -46,5 +46,4 @@ describe Rserve::REXP::Wrapper do
46
46
  Rserve::REXP::Wrapper.wrap([true,nil]).should==Rserve::REXP::Logical.new([1,Rserve::REXP::Logical::NA])
47
47
  Rserve::REXP::Wrapper.wrap(["a",nil]).should==Rserve::REXP::String.new(["a", Rserve::REXP::String::NA])
48
48
  end
49
-
50
49
  end
@@ -55,9 +55,9 @@ describe Rserve::Protocol::REXPFactory do
55
55
  la.as_integers.should==(-10..10).to_a
56
56
  end
57
57
  it "should process double vector with NA" do
58
- la=@r.eval("c(1,NA)")
58
+ la=@r.eval("c(1.0,2.0, NA)")
59
59
  la.should be_instance_of(Rserve::REXP::Double)
60
- la.na?.should==[false,true]
60
+ la.na?.should==[false,false,true]
61
61
 
62
62
  end
63
63
  it "should process string vector" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
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-06-24 00:00:00 -04:00
38
+ date: 2010-07-02 00:00:00 -04:00
39
39
  default_executable:
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file