vector_number 0.6.1 → 0.7.0
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 +4 -4
- data/README.md +254 -85
- data/lib/vector_number/comparing.rb +16 -8
- data/lib/vector_number/converting.rb +37 -19
- data/lib/vector_number/enumerating.rb +237 -22
- data/lib/vector_number/mathing.rb +62 -22
- data/lib/vector_number/querying.rb +3 -1
- data/lib/vector_number/{math_converting.rb → rounding.rb} +12 -35
- data/lib/vector_number/similarity.rb +97 -0
- data/lib/vector_number/special_unit.rb +20 -8
- data/lib/vector_number/stringifying.rb +52 -18
- data/lib/vector_number/vectoring.rb +504 -0
- data/lib/vector_number/version.rb +1 -1
- data/lib/vector_number.rb +105 -106
- data/sig/manifest.yaml +4 -0
- data/sig/vector_number.rbs +143 -56
- metadata +14 -16
- data/lib/vector_number/numeric_refinements.rb +0 -97
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vector_number
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Bulancov
|
|
@@ -9,16 +9,12 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
description:
|
|
13
|
-
|
|
12
|
+
description: 'A Numeric-like vector space implementation for Ruby. Perform arithmetic
|
|
13
|
+
on heterogeneous objects, calculate norms and dot products, get hash-like access
|
|
14
|
+
to components, and seamlessly interoperate with core numbers. Zero dependencies,
|
|
15
|
+
pure Ruby.
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
* Add and subtract (almost) any object, with no setup or declaration.
|
|
17
|
-
* Multiply and divide vectors by any real number to create 1.35 of an array and -2 of a string. What does that mean? Only you know!
|
|
18
|
-
* Use vectors instead of inbuilt numbers in most situtations with no difference in behavior. Or, use familiar methods from numerics with sane semantics!
|
|
19
|
-
* Enumerate vectors in a hash-like fashion, or transform to an array or hash as needed.
|
|
20
|
-
* Enjoy a mix of vector-, complex- and polynomial-like behavior at appropriate times.
|
|
21
|
-
* No dependencies, no extensions. It just works!
|
|
17
|
+
'
|
|
22
18
|
executables: []
|
|
23
19
|
extensions: []
|
|
24
20
|
extra_rdoc_files:
|
|
@@ -29,13 +25,15 @@ files:
|
|
|
29
25
|
- lib/vector_number/comparing.rb
|
|
30
26
|
- lib/vector_number/converting.rb
|
|
31
27
|
- lib/vector_number/enumerating.rb
|
|
32
|
-
- lib/vector_number/math_converting.rb
|
|
33
28
|
- lib/vector_number/mathing.rb
|
|
34
|
-
- lib/vector_number/numeric_refinements.rb
|
|
35
29
|
- lib/vector_number/querying.rb
|
|
30
|
+
- lib/vector_number/rounding.rb
|
|
31
|
+
- lib/vector_number/similarity.rb
|
|
36
32
|
- lib/vector_number/special_unit.rb
|
|
37
33
|
- lib/vector_number/stringifying.rb
|
|
34
|
+
- lib/vector_number/vectoring.rb
|
|
38
35
|
- lib/vector_number/version.rb
|
|
36
|
+
- sig/manifest.yaml
|
|
39
37
|
- sig/vector_number.rbs
|
|
40
38
|
homepage: https://github.com/trinistr/vector_number
|
|
41
39
|
licenses:
|
|
@@ -43,9 +41,9 @@ licenses:
|
|
|
43
41
|
metadata:
|
|
44
42
|
homepage_uri: https://github.com/trinistr/vector_number
|
|
45
43
|
bug_tracker_uri: https://github.com/trinistr/vector_number/issues
|
|
46
|
-
documentation_uri: https://rubydoc.info/gems/vector_number/0.
|
|
47
|
-
source_code_uri: https://github.com/trinistr/vector_number/tree/v0.
|
|
48
|
-
changelog_uri: https://github.com/trinistr/vector_number/blob/v0.
|
|
44
|
+
documentation_uri: https://rubydoc.info/gems/vector_number/0.7.0
|
|
45
|
+
source_code_uri: https://github.com/trinistr/vector_number/tree/v0.7.0
|
|
46
|
+
changelog_uri: https://github.com/trinistr/vector_number/blob/v0.7.0/CHANGELOG.md
|
|
49
47
|
rubygems_mfa_required: 'true'
|
|
50
48
|
rdoc_options:
|
|
51
49
|
- "--main"
|
|
@@ -65,5 +63,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
65
63
|
requirements: []
|
|
66
64
|
rubygems_version: 3.6.9
|
|
67
65
|
specification_version: 4
|
|
68
|
-
summary:
|
|
66
|
+
summary: Do full linear algebra on any Ruby objects
|
|
69
67
|
test_files: []
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class VectorNumber
|
|
4
|
-
# Refinements of Numeric classes and Kernel to better work with VectorNumber and similar classes.
|
|
5
|
-
#
|
|
6
|
-
# These do not depend on +VectorNumber+ and can technically be used separately.
|
|
7
|
-
# Currently includes:
|
|
8
|
-
# - refinement for +Complex#<=>+ to work with classes implementing +<=>+;
|
|
9
|
-
# - refinement for +Kernel#BigDecimal+ to work with classes implementing +to_d+.
|
|
10
|
-
#
|
|
11
|
-
# @note Refinements won't work on Ruby 3.0.
|
|
12
|
-
#
|
|
13
|
-
# @example activating refinements
|
|
14
|
-
# require "vector_number/numeric_refinements"
|
|
15
|
-
# using VectorNumber::NumericRefinements
|
|
16
|
-
#
|
|
17
|
-
# @since 0.2.0
|
|
18
|
-
module NumericRefinements
|
|
19
|
-
# CommutativeShuttle refinement works only on 3.1, so it almost never actually runs.
|
|
20
|
-
# There are tests for the correct behavior, however, so it's fine.
|
|
21
|
-
# :nocov:
|
|
22
|
-
|
|
23
|
-
# Refinement module to provide a +#<=>+ method that can work backwards.
|
|
24
|
-
#
|
|
25
|
-
# @note Currently only applies to Complex on *3.1*,
|
|
26
|
-
# as other numeric classes rely on +#coerce+.
|
|
27
|
-
# @example without refinements
|
|
28
|
-
# VectorNumber[2] <=> Complex(1, 0) #=> 1
|
|
29
|
-
# Complex(1, 0) <=> VectorNumber[2] #=> nil
|
|
30
|
-
# @example with refinements
|
|
31
|
-
# require "vector_number/numeric_refinements"
|
|
32
|
-
# using VectorNumber::NumericRefinements
|
|
33
|
-
# VectorNumber[2] <=> Complex(1, 0) #=> 1
|
|
34
|
-
# Complex(1, 0) <=> VectorNumber[2] #=> -1
|
|
35
|
-
#
|
|
36
|
-
# @since 0.2.1
|
|
37
|
-
module CommutativeShuttle
|
|
38
|
-
# Commutative +#<=>+.
|
|
39
|
-
# Tries to call +other <=> self+ if +self <=> other+ returns +nil+.
|
|
40
|
-
def <=>(other)
|
|
41
|
-
comparison = super
|
|
42
|
-
return comparison if comparison || !other.respond_to?(:<=>)
|
|
43
|
-
|
|
44
|
-
comparison = other <=> self
|
|
45
|
-
-comparison if comparison
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
if (Complex(1, 0) <=> VectorNumber[1]).nil?
|
|
50
|
-
refine(Complex) do
|
|
51
|
-
import_methods CommutativeShuttle
|
|
52
|
-
rescue
|
|
53
|
-
warn "Numeric refinements are not available on Ruby < 3.1"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
# :nocov:
|
|
57
|
-
|
|
58
|
-
# Refinement module to change Kernel#BigDecimal so it works with +#to_d+.
|
|
59
|
-
#
|
|
60
|
-
# @note `BigDecimal` needs to be defined for this refinement to activate.
|
|
61
|
-
# @example without refinements
|
|
62
|
-
# BigDecimal(VectorNumber[2]) # can't convert VectorNumber into BigDecimal (TypeError)
|
|
63
|
-
# @example with refinements
|
|
64
|
-
# require "vector_number/numeric_refinements"
|
|
65
|
-
# using VectorNumber::NumericRefinements
|
|
66
|
-
# BigDecimal(VectorNumber[2]) #=> 0.2e1
|
|
67
|
-
#
|
|
68
|
-
# @since 0.2.1
|
|
69
|
-
module BigDecimalToD
|
|
70
|
-
# BigDecimal() that first tries to use #to_d.
|
|
71
|
-
# @param value [Object]
|
|
72
|
-
# @param exception [Boolean]
|
|
73
|
-
# @overload BigDecimal(value, exception: true)
|
|
74
|
-
# @overload BigDecimal(value, ndigits, exception: true)
|
|
75
|
-
# @param ndigits [Integer]
|
|
76
|
-
# @return [BigDecimal, nil]
|
|
77
|
-
# @raise [TypeError]
|
|
78
|
-
def BigDecimal(value, ndigits = nil, exception: true) # rubocop:disable Naming/MethodName
|
|
79
|
-
if value.respond_to?(:to_d)
|
|
80
|
-
ndigits.nil? ? value.to_d : value.to_d(ndigits)
|
|
81
|
-
else
|
|
82
|
-
ndigits.nil? ? super(value, exception: exception) : super
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# :nocov:
|
|
88
|
-
if defined?(BigDecimal)
|
|
89
|
-
refine(Kernel) do
|
|
90
|
-
import_methods BigDecimalToD
|
|
91
|
-
rescue
|
|
92
|
-
warn "Numeric refinements are not available on Ruby < 3.1"
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
# :nocov:
|
|
96
|
-
end
|
|
97
|
-
end
|