chris_lib 2.0.4 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chris_lib/chris_math.rb +68 -2
- data/lib/chris_lib/shell_methods.rb +8 -0
- data/lib/chris_lib/version.rb +1 -1
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6d799d0f8000a13766abc5e042a0533e989112b6d3a87abd3f193d18157fb75
|
4
|
+
data.tar.gz: 0dcc9ec5aeaa4a2179b8c79bbaa4e5ccaa7f93d235c7e907f5f8941a7dde6fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce73e2ca6a4ed4096ac3ffe1c940ea984fbae0aebafcc1a122c26a49dc8d1cff98ad48188ecd9485ec9c5f10a6644672b8b81513abc6741d2dc9628a7f62f0fd
|
7
|
+
data.tar.gz: 2804b6cd5d494ffbfcb0bf366efa0700d5c5772b620857dc8c3df2556ceaab806cbf60d7b4a7870d998a8684af397451c700f32f52b6bd6a03bdcf2163a68b6a
|
data/lib/chris_lib/chris_math.rb
CHANGED
@@ -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,15 +57,33 @@ 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) }
|
38
75
|
end
|
76
|
+
|
77
|
+
def eround(decimal_points = 0)
|
78
|
+
map { |e| e.eround(decimal_points) }
|
79
|
+
end
|
39
80
|
|
40
81
|
# mean of array
|
41
82
|
def mean
|
42
|
-
raise 'Length must be greater than 0.' if length < 1
|
43
|
-
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
|
44
87
|
end
|
45
88
|
|
46
89
|
# unbiased sample variance of array
|
@@ -80,6 +123,29 @@ Array.class_eval do
|
|
80
123
|
end
|
81
124
|
|
82
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
|
+
|
144
|
+
# rounds exponential notation to n decimal places
|
145
|
+
def eround(decimal_points = 0)
|
146
|
+
("%.#{decimal_points}e" % self).to_f
|
147
|
+
end
|
148
|
+
|
83
149
|
def round_down(n=0)
|
84
150
|
# n is decimal place to round down at
|
85
151
|
int,dec=self.to_s.split('.')
|
@@ -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
|
data/lib/chris_lib/version.rb
CHANGED
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.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -38,6 +38,40 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionpack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.1.4
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 6.1.4.6
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 6.1.4
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
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'
|
41
75
|
- !ruby/object:Gem::Dependency
|
42
76
|
name: rspec
|
43
77
|
requirement: !ruby/object:Gem::Requirement
|