chris_lib 1.1.11 → 2.0.3

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: 79c4ea547446df8d0379c747cdfc49c2d75a6dbca69c030fbb184addc55a35f8
4
- data.tar.gz: 964c3612a94592578ca8c5620e235f32990616fac42d26f6e5c030983b6dbd98
3
+ metadata.gz: 8ea3447c69d66f98ca586f54400ff878b50722e96769865c9a09bc8533e94eec
4
+ data.tar.gz: 28e1df6aa9b135b88a428b5e8e0b1cd856455c7f224bfee90705c32f742590cf
5
5
  SHA512:
6
- metadata.gz: f7fa67040270e0404053b52235d126e308429ab264a7d87cae17e594f80953419e971cb30443384f88ebee3d8193fd39d83ec47dca36aa883d6c86fe46162b07
7
- data.tar.gz: c2efb641ba2af31d692f3ebdef4ae6cc19c308f99ac7abc0d870d3e25365225ce4b7c7934d4a45ec550bf955beb84a8ec5a16b15a7c9d82677a54ccf3d7bed15
6
+ metadata.gz: 119b1971ba49a8c67486603910279c3e9488b384b80e63e474ec275089a0391febb68cd5ebe4a1f42b74ee968096455d982011bcc4a996c78f5b51642d8357a1
7
+ data.tar.gz: d04f7889df086aa1f3403383d767bc41877e80220d930f57d8c489deaf6ffab156905b359fd0236b861248cf551fcd8f37c5ab2b12594b5de75666b8828f5e86
@@ -3,7 +3,7 @@ Integer.class_eval do
3
3
  def factorial
4
4
  n = self
5
5
  if n > 20
6
- fail 'Number too large'
6
+ raise 'Number too large'
7
7
  else
8
8
  (1..n).inject {|prod, i| prod * i}
9
9
  end
@@ -32,17 +32,20 @@ Matrix.class_eval do
32
32
  end
33
33
 
34
34
  Array.class_eval do
35
+ # round each element
36
+ def round(n)
37
+ map { |e| e.round(n) }
38
+ end
39
+
35
40
  # mean of array
36
41
  def mean
37
- # s=c(7.08195525827783, 10.831582068121444, 9.288611270369554, 9.054684238411918, 12.268532229606647)
38
- # returns 9.705073
39
- fail 'Length must be greater than 0.' if length < 1
42
+ raise 'Length must be greater than 0.' if length < 1
40
43
  sum.to_f / length
41
44
  end
42
45
 
43
46
  # unbiased sample variance of array
44
47
  def var
45
- fail 'Length must be greater than 1' if length < 2
48
+ raise 'Length must be greater than 1' if length < 2
46
49
  mu = mean
47
50
  map { |v| (v**2 - mu**2) }.sum.to_f / (length - 1)
48
51
  end
@@ -69,12 +72,6 @@ Array.class_eval do
69
72
  end
70
73
  end
71
74
 
72
- def histogram
73
- k = Hash.new(0)
74
- self.each { |x| k[x] += 1 }
75
- k
76
- end
77
-
78
75
  # deep dup, takes about 20 microseconds for scores arrays
79
76
  # https://www.thoughtco.com/making-deep-copies-in-ruby-2907749
80
77
  def deep_dup
@@ -136,7 +133,7 @@ module ChrisMath
136
133
 
137
134
  def std(values)
138
135
  n = values.length
139
- fail 'n = #{n} but must be greater than 1' if n < 2
136
+ raise 'n = #{n} but must be greater than 1' if n < 2
140
137
  m = mean(values)
141
138
  sum = values.inject { |s,v| s + (v**2 - m**2)}
142
139
  sqrt(sum.to_f/(n - 1))
@@ -153,7 +150,7 @@ module ChrisMath
153
150
  end
154
151
  sum
155
152
  else
156
- fail 'Error, #{r} must be >= 0 and <= #{n}'
153
+ raise 'Error, #{r} must be >= 0 and <= #{n}'
157
154
  end
158
155
  end
159
156
 
@@ -1,3 +1,3 @@
1
1
  module ChrisLib
2
- VERSION = "1.1.11"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chris_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-31 00:00:00.000000000 Z
11
+ date: 2021-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv