binneroc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/binneroc.rb +21 -5
- data/lib/binneroc/version.rb +1 -1
- data/spec/binneroc_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9fe2157dc493e9885a14535c3ee6fe7bee9a7db
|
4
|
+
data.tar.gz: 2fc6387c6b1eef1f8d6bb488ac0a73ab68b02b75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57564f23f0fb39f27276cdc1cc3f8a5d9b63bb74ede8fab75eba0504a696239f75c7de14ce2051f26bfe1ea2cfcca6fe9dbd813e388c7fef16e60af8ddf69560
|
7
|
+
data.tar.gz: a9b521af7b742b4a7333dba09323b301a12ceb32b71a392d1c61372417f61e427a9f4714bf081f4d5e0c047574499ff1db529543283ef2d740429f221d5f1ca4
|
data/lib/binneroc.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require "binneroc/version"
|
2
2
|
require 'bigdecimal'
|
3
3
|
|
4
|
+
if RUBY_VERSION == '2.1.0'
|
5
|
+
STDERR.puts "You are using a version of ruby with a known bug in BigDecimal division."
|
6
|
+
STDERR.puts "This is fixed in newer versions of ruby. Please upgrade"
|
7
|
+
raise
|
8
|
+
end
|
9
|
+
|
4
10
|
module Binneroc
|
5
11
|
|
6
12
|
class << self
|
@@ -54,11 +60,11 @@ module Binneroc
|
|
54
60
|
#
|
55
61
|
# outputclass needs to be able to create a new vector like object with the
|
56
62
|
# arguments outputclass.new(size, value) or outputclass.new(size).
|
57
|
-
def bin(xvals, yvals, start: nil, stop: nil, increment: 1.0, default: 0.0, behavior: :sum, outputclass: Array, return_xvals: true, exclude_end: false, consider_default: false)
|
63
|
+
def bin(xvals, yvals, start: nil, stop: nil, increment: 1.0, default: 0.0, behavior: :sum, outputclass: Array, return_xvals: true, exclude_end: false, consider_default: false, only_xvals: false)
|
58
64
|
raise ArgumentError, "xvals and yvals need to be parallel (same size)!" unless xvals.size == yvals.size
|
59
65
|
|
60
66
|
if xvals.size == 0
|
61
|
-
if return_xvals
|
67
|
+
if return_xvals && !only_xvals
|
62
68
|
return [[],[]]
|
63
69
|
else
|
64
70
|
return []
|
@@ -90,6 +96,13 @@ module Binneroc
|
|
90
96
|
newsize = array_size(startbd, stopbd, incrementbd, exclude_end)
|
91
97
|
range = Range.new(startbd, startbd + (incrementbd * newsize), exclude_end)
|
92
98
|
|
99
|
+
if return_xvals
|
100
|
+
basic_xvals = range.step(incrementbd).to_a
|
101
|
+
basic_xvals.pop if basic_xvals.size > newsize
|
102
|
+
new_xvals = outputclass.new(basic_xvals)
|
103
|
+
end
|
104
|
+
return new_xvals if only_xvals
|
105
|
+
|
93
106
|
yvec_new = outputclass.new(newsize, default)
|
94
107
|
index_bounds = (0...newsize)
|
95
108
|
|
@@ -115,9 +128,7 @@ module Binneroc
|
|
115
128
|
end
|
116
129
|
|
117
130
|
if return_xvals
|
118
|
-
new_xvals
|
119
|
-
new_xvals.pop if new_xvals.size > newsize
|
120
|
-
[outputclass.new(new_xvals), yvec_new]
|
131
|
+
[new_xvals, yvec_new]
|
121
132
|
else
|
122
133
|
yvec_new
|
123
134
|
end
|
@@ -131,6 +142,11 @@ module Binneroc
|
|
131
142
|
array_size_floor.to_i
|
132
143
|
end
|
133
144
|
|
145
|
+
# takes the x array and the arguments and produces the xvals that would be
|
146
|
+
# produced with bin
|
147
|
+
def xvals(xvals, **args)
|
148
|
+
end
|
149
|
+
|
134
150
|
end
|
135
151
|
end
|
136
152
|
|
data/lib/binneroc/version.rb
CHANGED
data/spec/binneroc_spec.rb
CHANGED
@@ -95,4 +95,8 @@ describe 'iconic case' do
|
|
95
95
|
expect(reply).to eq [30.0, 30.0, 40.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 50.0]
|
96
96
|
end
|
97
97
|
|
98
|
+
specify 'can return only the x values' do
|
99
|
+
reply = Binneroc.bin(*vals, start: "4.0", stop: "5.0", increment: "0.1", only_xvals: true)
|
100
|
+
expect(reply).to eq (4..5).step(0.1).to_a
|
101
|
+
end
|
98
102
|
end
|