chris_lib 2.0.5 → 2.0.8

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: a8e589ae062b5ed85189108754fbaa7d9cbb19b45edced9a8d2fbdf5bca295a2
4
- data.tar.gz: 321eec2a967da2a904da7909109182087c3317d14ace9c546a5b3ea8156fb773
3
+ metadata.gz: 84a94c6a793526f1cae853abfbb82818c7e788533754384ee11275ccacd53510
4
+ data.tar.gz: e27b5366151b6d00967c4fc4bcdee8069f8d446130c5e51a07e2ab0a49511780
5
5
  SHA512:
6
- metadata.gz: ddae70fc4078288c6dc7b5db4f0027eeac0247001d490c85ba5300a58a14cd7aa34b4dfb81b4f8a822a26c5f1dd5ee6e2284c5511c68f5186460bd6e9c64c55a
7
- data.tar.gz: 81fc5296ba1bd6a8cec244f378fb35312ae7e1deeff4d52da6c822b5a23bb20a450ef7f49ed9aa63270f390f8ae6093c90f0d881580ed63c2548b75be99ebfcb
6
+ metadata.gz: 6c9ca73ab3dec5f3f309d0fadcd8c021f0d238dd719e15b1de9c00e13d7fc40a8bc2a9669bf30f3044a768aea705e54921b9b27ddd6999272a3122a494a49f0e
7
+ data.tar.gz: 98dbeb7007703ac035dcc5761a6c21db5d81a12082583771304c4968b83538446f7e28334bc147a78669b539c0e1fd6e4ddec5810aea1460a6c43ab2152d9a94
@@ -1,4 +1,29 @@
1
1
  require 'matrix'
2
+ require 'quaternion'
3
+ Quaternion.class_eval do
4
+ # rounds each element of quaternion to n decimal places
5
+ def round(n)
6
+ q = self
7
+ Quaternion.new(q[0].round(n), q[1].round(n), q[2].round(n), q[3].round(n))
8
+ end
9
+
10
+ # Creates identity quaternion
11
+ def self.identity
12
+ Quaternion.new(1.0, 0.0, 0.0, 0.0)
13
+ end
14
+
15
+ # Creates zero quaternion
16
+ def self.zero
17
+ Quaternion.new(0.0, 0.0, 0.0, 0.0)
18
+ end
19
+
20
+ # Creates quaternion using square brackets (for compatability with Matrix and Vector)
21
+ # see https://stackoverflow.com/questions/69155796/how-to-define-a-class-method-when-using-class-eval
22
+ def self.[](q0, q1, q2, q3)
23
+ Quaternion.new(q0, q1, q2, q3)
24
+ end
25
+ end
26
+
2
27
  Integer.class_eval do
3
28
  def factorial
4
29
  n = self
@@ -32,6 +57,18 @@ Matrix.class_eval do
32
57
  end
33
58
 
34
59
  Array.class_eval do
60
+ # converts radians to degrees
61
+ # Also rounds to n_decimal places unless n_decimimals is nil
62
+ def to_deg(n_decimals = nil)
63
+ map { |e| e.to_deg(n_decimals) }
64
+ end
65
+
66
+ # converts degrees to radians
67
+ # Also rounds to n_decimal places unless n_decimimals is nil
68
+ def to_rad(n_decimals = nil)
69
+ map { |e| e.to_rad(n_decimals) }
70
+ end
71
+
35
72
  # round each element
36
73
  def round(decimal_points = 0)
37
74
  map { |e| e.round(decimal_points) }
@@ -43,8 +80,10 @@ Array.class_eval do
43
80
 
44
81
  # mean of array
45
82
  def mean
46
- raise 'Length must be greater than 0.' if length < 1
47
- sum.to_f / length
83
+ raise 'chris_lib - f - Length must be greater than 0.' if length < 1
84
+ return sum.to_f / length unless all? { |e| e.class == Vector }
85
+ ary = map { |v| v.to_a }.transpose.map { |a| a.mean }
86
+ Vector.elements ary
48
87
  end
49
88
 
50
89
  # unbiased sample variance of array
@@ -84,6 +123,24 @@ Array.class_eval do
84
123
  end
85
124
 
86
125
  Float.class_eval do
126
+ # converts radians to degrees
127
+ # Also rounds to n_decimal places unless n_decimimals is nil
128
+ def to_deg(n_decimals = nil)
129
+ include Math unless defined?(Math)
130
+ degrees = self * 180.0 / PI
131
+ return degrees if n_decimals.nil?
132
+ degrees.round(n_decimals)
133
+ end
134
+
135
+ # converts degrees to radians
136
+ # Also rounds to n_decimal places unless n_decimimals is nil
137
+ def to_rad(n_decimals = nil)
138
+ include Math unless defined?(Math)
139
+ radians = self * PI / 180.0
140
+ return radians if n_decimals.nil?
141
+ radians.round(n_decimals)
142
+ end
143
+
87
144
  # rounds exponential notation to n decimal places
88
145
  def eround(decimal_points = 0)
89
146
  ("%.#{decimal_points}e" % self).to_f
@@ -5,6 +5,14 @@ module ShellMethods
5
5
  require 'optparse'
6
6
  Dotenv.load
7
7
 
8
+ # runs an R script from ruby
9
+ # script_path is absolute path of R script
10
+ # arg1 is an argument passed to script, can access in R by
11
+ # arg1 <- commandArgs(trailingOnly=TRUE)[1]
12
+ def r_runner(script_path, arg1)
13
+ `Rscript --vanilla #{script_path} #{arg1}`
14
+ end
15
+
8
16
  def file_size(file_path)
9
17
  `stat -f%z #{file_path}`.to_i
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module ChrisLib
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.8"
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: 2.0.5
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-04 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -47,7 +47,7 @@ dependencies:
47
47
  version: 6.1.4
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 6.1.4.2
50
+ version: 6.1.4.6
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +57,21 @@ dependencies:
57
57
  version: 6.1.4
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 6.1.4.2
60
+ version: 6.1.4.6
61
+ - !ruby/object:Gem::Dependency
62
+ name: quaternion
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: rspec
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +114,20 @@ dependencies:
100
114
  - - ">="
101
115
  - !ruby/object:Gem::Version
102
116
  version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: colorize
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
103
131
  description: It includes maths, datetime, and rspec access test libraries.
104
132
  email:
105
133
  - obromios@gmail.com