tdigest 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be74af8cae96393fca31017d57cd99a125c06af6
4
- data.tar.gz: 7f17839d5f50ee56071d213c55891f189c99de37
3
+ metadata.gz: fb2b554c557253ae6826b504943a315bf4f660a0
4
+ data.tar.gz: 4f86fdef222ec8f3ddd7746ccfb7767cfbd1bd26
5
5
  SHA512:
6
- metadata.gz: 9aa1a1379afab686402272ae6cd04a147c522d443924436cc599745abe3cf3bdf3bac86e04ef0d47428c1f8329c1a12c9789838a2b1cfae844b4b0cc089489c9
7
- data.tar.gz: a7ceaf5fe58f37f18cd4ff5c72a026296637d73e6f7071ac9b8ed98c4c944ecbd36f7fc36d6b927e0b53102fe653688eac4c4baa013208c9e887b0e8bbf09242
6
+ metadata.gz: c5b5567069b6958c551721f8c6c6d707e9a08f6f20c23473b39e732c853a92e4ef1e20406dba46d67ddf2b496ce94224501f6605def6f36be0b65b7f586aaa01
7
+ data.tar.gz: c00dfc8c3bb483793c5f5b2c8a4ea8ad9b324c4ce506a7930db362d31f42e2f1759215552d25140ab5667be969e62ee79fcc4e72cf7dcb0ca976d0fbae8b95d3
@@ -72,12 +72,16 @@ module TDigest
72
72
  def p_rank(x)
73
73
  is_array = x.is_a? Array
74
74
  x = [x] unless is_array
75
+
76
+ min = @centroids.first
77
+ max = @centroids.last
78
+
75
79
  x.map! do |item|
76
80
  if size == 0
77
81
  nil
78
- elsif item < @centroids.min[1].mean
82
+ elsif item < min[1].mean
79
83
  0.0
80
- elsif item > @centroids.max[1].mean
84
+ elsif item > max[1].mean
81
85
  1.0
82
86
  else
83
87
  _cumulate(true)
@@ -97,6 +101,9 @@ module TDigest
97
101
  is_array = p.is_a? Array
98
102
  p = [p] unless is_array
99
103
  p.map! do |item|
104
+ unless (0..1).include? item
105
+ fail ArgumentError, "p should be in [0,1], got #{item}"
106
+ end
100
107
  if size == 0
101
108
  nil
102
109
  else
@@ -135,7 +142,7 @@ module TDigest
135
142
  end
136
143
 
137
144
  def size
138
- @centroids.count
145
+ @centroids.size
139
146
  end
140
147
 
141
148
  def to_a
@@ -161,7 +168,8 @@ module TDigest
161
168
 
162
169
  def _cumulate(exact = false)
163
170
  factor = @last_cumulate == 0 ? Float::INFINITY : (@n / @last_cumulate)
164
- if @n == @last_cumulate
171
+ if @n == @last_cumulate ||
172
+ !exact && @cx && @cx > (factor)
165
173
  return
166
174
  end
167
175
 
@@ -175,8 +183,11 @@ module TDigest
175
183
  end
176
184
 
177
185
  def _digest(x, n)
178
- min = @centroids.min
179
- max = @centroids.max
186
+ # Use 'first' and 'last' instead of min/max because of performance reasons
187
+ # This works because RBTree is sorted
188
+ min = @centroids.first
189
+ max = @centroids.last
190
+
180
191
  min = min.nil? ? nil : min[1]
181
192
  max = max.nil? ? nil : max[1]
182
193
  nearest = find_nearest(x)
@@ -1,3 +1,3 @@
1
1
  module TDigest
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdigest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wallin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-22 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbtree