rover-df 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a1b47800b1d7e9b84e7a1976f2cfbc551e9dee6a9a0ec39b3759b6564e4e278
4
- data.tar.gz: a41f8ed9bdeabc01a0fc83bdb98487a375bfa6f6d1d2fd4041db7cc38f803482
3
+ metadata.gz: c77203874c704a18978e6a2483a1718c65fc96c47ef4dbe178a23bcd8ea6ce32
4
+ data.tar.gz: 24f04572c8197898387037c6800f487066ad4e56a35ef31df1877b6aef442fcd
5
5
  SHA512:
6
- metadata.gz: 7b2e10547e204ff592757373bc93c7d8dfd004802a87e10ca886c47771c29aa717fe19ef11e20c9b830765c64c6ef65db5d0bfead0d1b064c680938a1cca8184
7
- data.tar.gz: ce25fac82709a912e78c871f356e681ad8f85a599db1eeea58d5654ddf3928554d70a7434e92beb4352c81b69307dce77062baedd8669f2584bda54f1e40ee42
6
+ metadata.gz: 383e162cd6f62d1d409b869081f4ba97025dd297567a01d300672451a0883f90464f1396b348b6991d1b99a383d4d328f33f8c7cd560e810c96e0ed2f231b688
7
+ data.tar.gz: 45bb86dfc58172021e7fdef8677f74bbb32075bfe15022e6c0cfe2ddbae0be9b0d1909f5ff42a7792a7863d54bb53afeb309610d22ae0fc02f93f9026c2ab782
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.4 (2022-07-12)
2
+
3
+ - Added `cbrt`, `erf`, `erfc`, and `hypot` methods to vectors
4
+ - Added `frexp` and `ldexp` methods to vectors
5
+ - Added `base` argument to `log` method
6
+
1
7
  ## 0.3.3 (2022-07-11)
2
8
 
3
9
  - Added `ln`, `log`, `log10`, and `log2` methods to vectors
data/README.md CHANGED
@@ -192,6 +192,7 @@ df[:a] / 5
192
192
  df[:a] % 5
193
193
  df[:a] ** 2
194
194
  df[:a].sqrt
195
+ df[:a].cbrt
195
196
  df[:a].abs
196
197
  ```
197
198
 
@@ -207,6 +208,7 @@ Logarithm
207
208
 
208
209
  ```ruby
209
210
  df[:a].ln # or log
211
+ df[:a].log(5)
210
212
  df[:a].log10
211
213
  df[:a].log2
212
214
  ```
@@ -240,6 +242,13 @@ df[:a].acosh
240
242
  df[:a].atanh
241
243
  ```
242
244
 
245
+ Error function
246
+
247
+ ```ruby
248
+ df[:a].erf
249
+ df[:a].erfc
250
+ ```
251
+
243
252
  Summary statistics
244
253
 
245
254
  ```ruby
data/lib/rover/vector.rb CHANGED
@@ -21,6 +21,8 @@ module Rover
21
21
  uint: Numo::UInt64
22
22
  }
23
23
 
24
+ NOT_SET = Object.new
25
+
24
26
  def initialize(data, type: nil)
25
27
  @data = cast_data(data, type: type)
26
28
  raise ArgumentError, "Bad size: #{@data.shape}" unless @data.ndim == 1
@@ -87,6 +89,7 @@ module Rover
87
89
  if v.is_a?(Vector)
88
90
  Vector.new(v.to_numo.mask(@data))
89
91
  else
92
+ # TODO return vector unless v is an integer in 0.4.0
90
93
  @data[v]
91
94
  end
92
95
  end
@@ -201,7 +204,8 @@ module Rover
201
204
  if ndigits == 0
202
205
  Vector.new(@data.round)
203
206
  else
204
- map { |v| v.round(ndigits) }
207
+ # TODO pass type
208
+ Vector.new(@data.to_a.map { |v| v.round(ndigits) })
205
209
  end
206
210
  end
207
211
 
@@ -209,7 +213,8 @@ module Rover
209
213
  if ndigits == 0
210
214
  Vector.new(@data.ceil)
211
215
  else
212
- map { |v| v.ceil(ndigits) }
216
+ # TODO pass type
217
+ Vector.new(@data.to_a.map { |v| v.ceil(ndigits) })
213
218
  end
214
219
  end
215
220
 
@@ -217,22 +222,44 @@ module Rover
217
222
  if ndigits == 0
218
223
  Vector.new(@data.floor)
219
224
  else
220
- map { |v| v.floor(ndigits) }
225
+ # TODO pass type
226
+ Vector.new(@data.to_a.map { |v| v.floor(ndigits) })
221
227
  end
222
228
  end
223
229
 
224
- [:sqrt, :sin, :cos, :tan, :asin, :acos, :atan, :sinh, :cosh, :tanh, :asinh, :acosh, :atanh, :log, :log2, :log10, :exp, :exp2].each do |m|
230
+ [:sqrt, :cbrt, :sin, :cos, :tan, :asin, :acos, :atan, :sinh, :cosh, :tanh, :asinh, :acosh, :atanh, :log2, :log10, :exp, :exp2, :erf, :erfc].each do |m|
225
231
  define_method(m) do
226
- data =
227
- if @data.is_a?(Numo::SFloat)
228
- Numo::SFloat::Math.send(m, @data)
229
- else
230
- Numo::DFloat::Math.send(m, @data)
231
- end
232
- Vector.new(data)
232
+ Vector.new(Numo::NMath.send(m, @data))
233
+ end
234
+ end
235
+
236
+ def log(base = NOT_SET)
237
+ if base == NOT_SET
238
+ Vector.new(Numo::NMath.log(@data))
239
+ else
240
+ type = self.type == :float32 ? :float32 : :float64
241
+ Vector.new(@data.to_a.map { |v| Math.log(v, base) }, type: type)
233
242
  end
234
243
  end
235
- alias_method :ln, :log
244
+
245
+ def ln
246
+ log
247
+ end
248
+
249
+ def hypot(y)
250
+ y = y.to_numo if y.is_a?(Rover::Vector)
251
+ Vector.new(Numo::NMath.hypot(@data, y))
252
+ end
253
+
254
+ def frexp
255
+ fraction, exponent = Numo::NMath.frexp(@data)
256
+ [Vector.new(fraction), Vector.new(exponent)]
257
+ end
258
+
259
+ def ldexp(exponent)
260
+ exponent = exponent.to_numo if exponent.is_a?(Rover::Vector)
261
+ Vector.new(Numo::NMath.ldexp(@data, exponent))
262
+ end
236
263
 
237
264
  def each(&block)
238
265
  @data.each(&block)
data/lib/rover/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rover
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rover-df
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray