kmat 0.0.3 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7829ae70db9d621efcc3021500b520e7248969baf7cef3752ba945e012575f82
4
- data.tar.gz: 2e06e8b2bffc46952ea2e72c01d50756ec91c72db8a3a1399c46af0e05e95e0c
3
+ metadata.gz: 63f68444113fd2472e9d7464d88a7055c0b667fc16f6fe48a6efc6e57588cfb5
4
+ data.tar.gz: bb7da016d0f3dfcc526cfff275a90bcc42280a9fabc3e52541f3a6909c549949
5
5
  SHA512:
6
- metadata.gz: 56f3ef7e5dbd8cae2a4f897958531fd028ca638373760a17f580b9ff692b073727bea25c5c7532e3045a4875e08c51b0a614539010f01c83819a68b2aea4aa8a
7
- data.tar.gz: 9032a9843c1c7641e28121b44123104a3fd54e2e2bb085961e207c9e225e3d80aaef10f4cc8d7540e6605f04a5d35b65db12f095361c21b40f9831f99430066c
6
+ metadata.gz: 1b01f793d1dde83a9ab7e079c0b9695eea75a41dd66a50df832ae8e6ee931cb27f650331d97096ace84efb57962f99730b4e8becf0e643a436fba5f9f76ab1a6
7
+ data.tar.gz: fccd83529c2af864a5dab072e483c5e25a4d9c9efe7b8a4e078337de1e2a5e1b975810bd4cfd300669a98013fd289dccda4a317382ba6ba7fce8025e319a9d47
data/.gitignore CHANGED
@@ -6,10 +6,12 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /.vscode/
9
10
  *.bundle
10
11
  *.so
11
12
  *.o
12
13
  *.a
13
14
  mkmf.log
14
15
  Gemfile.lock
16
+ /spec/examples.txt
15
17
  test.rb
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/CHANGELOG.md CHANGED
@@ -13,3 +13,13 @@ Linear algebra methods used with transposed output matricies were affected.
13
13
 
14
14
  ## 0.0.3 2019/12/03
15
15
  - Fix a bug in Mat#geo_normalize
16
+
17
+ ## 0.1.0 2022/03/20
18
+ - Conformed newer Ruby regulations.
19
+ - Not use Random::DEFAULT.
20
+ - Set rb_data_type_t::dcompact.
21
+ - Use rb_block_call instead of rb_iterate.
22
+ - Use RB_BLOCK_CALL_FUNC_ARGLIST.
23
+ - Fixed int/size_t confusion.
24
+ - Fixed a bug that Mat#ge_evd did not return correct right eigen vectors.
25
+ - Fixed some minor bugs.
data/README.md CHANGED
@@ -44,7 +44,7 @@ Mat.new(2, 3){|i, j| i+j} #=> [0, 1, 2; 1, 2, 3]
44
44
  ```ruby
45
45
  require 'kmat'
46
46
 
47
- a = Mat.ones; b = Mat[[2, 0], [0, 1]]
47
+ a = Mat.ones(2, 2); b = Mat[[2, 0], [0, 1]]
48
48
  a+b #=> [3, 1; 1, 2]
49
49
  a-b #=> [-1, 1; 1, 0]
50
50
  a.mprod(b) #=> [2, 1; 2, 1] (matrix product)
@@ -61,14 +61,14 @@ a.sin # Most of mathematical functions defined in math.h are available as e
61
61
  ```ruby
62
62
  require 'kmat'
63
63
 
64
- a = Mat.ones; b = Mat[[2, 0], [0, 1]]
64
+ a = Mat.ones(2, 2); b = Mat[[2, 0], [0, 1]]
65
65
  a+b; a #=> [1, 1; 1, 1]
66
66
  a.add!(b)
67
67
  a #=> [3, 1; 1, 2]
68
68
  c = Mat.new(2, 2)
69
69
  c.mprod!(a, b)
70
70
  c #=> [6, 1; 2, 2]
71
- a.sub!(b); a.e_mul!(b); b.e_div!(a); c.under!(a, b)
71
+ a.sub!(b); a.e_mul!(b); b.e_div!(a); c.under!(b, a)
72
72
  ```
73
73
 
74
74
  ### Numpy-like broadcasting
@@ -76,7 +76,7 @@ a.sub!(b); a.e_mul!(b); b.e_div!(a); c.under!(a, b)
76
76
  require 'kmat'
77
77
 
78
78
  a = Mat.eye(2, 2); b = Mat.range(2)
79
- a+b #=> [1, 1; 2, 2]
79
+ a+b #=> [1, 0; 1, 2]
80
80
  a.add!(a.broadcast(b)) # For destructive operation, you need to fit shape using Mat#broadcast
81
81
  a.s_add!(1.5) # Or use Mat#s_xxx! for element-wise opertion with broadcasted scalar value
82
82
  0.5 * a # Numeric#* can be used as scalar multiplication (others like Numeric+Mat are not available)
@@ -111,8 +111,8 @@ a[nil, 0] = Mat.range(2) # multi-entry substitution is also available
111
111
  a #=> [0, 2; 1, 4]
112
112
  a.map(&:-@) #=> [0, -2; -1, -4]
113
113
  a.map_with_index!{|e, i, j| e+j}
114
- a.diag #=> [0; 4] (returns diagonal elements as a vector)
115
- a[] #=> [0, 2; 1, 4] (with no argument is equivalent to a[nil, nil])
114
+ a.diag #=> [0; 5] (returns diagonal elements as a vector)
115
+ a[] #=> [0, 3; 1, 5] (with no argument is equivalent to a[nil, nil])
116
116
  Mat.range(3)[2] #=> 2.0 (with single integer or single integer array is available for vectors)
117
117
  ```
118
118
 
@@ -128,7 +128,7 @@ The default value type is `:float`. Values are `double` in C language and it is
128
128
  `:int` can be used as row or column index array. Values are `int` in C language, so it is not useful for matrix operations with large integer elements. We recomend to use `:object` with `Integer` for such usage.
129
129
 
130
130
  #### Bool
131
- `:bool` can be used as boolean indexing. Logical operations are available. In some operations, elements in boolean matricies behaves as a finite filed with order 2 (`+` is exclusive disjunction and `*` is logical conjunction).
131
+ `:bool` can be used as boolean indexing. Logical operations are available. In some operations, elements in boolean matricies behave as a finite filed with order 2 (`+` is exclusive disjunction and `*` is logical conjunction).
132
132
 
133
133
  #### Object
134
134
  `:object` matricies can contain arbitrary Ruby objects. Operation behaviors are dependent on methods defined for the objects. For example, `Mat#solve` works if `K#==`, `K#quo`, `K#*` and `K#-` are defined appropriately, where `K` is a class of the elements.
@@ -141,7 +141,7 @@ Mat.new(2, 2, :float){|i, j| i+j}
141
141
  Mat.new(2, 2, :complex){|i, j| Complex.rect(i, j)}
142
142
  Mat.new(2, 2, :int){|i, j| i-j}
143
143
  Mat.new(2, 2, :bool){|i, j| i==j}
144
- Mat.new(2, 2, :object){|i, j| Rational(i, j) }
144
+ Mat.new(2, 2, :object){|i, j| Rational(i, j+1) }
145
145
  Mat.new(1, 1).vtype #=> :float (Mat#vtype returns its value type as a Symbol above)
146
146
  ```
147
147
 
@@ -158,7 +158,7 @@ b = Mat.range(2)
158
158
  Mat.blocks([[a, b], [b, a]]) #=> [3, 2, 1, 0; 5, -3, 7, 1; 0, 3, 2, 1; 1, 5, -3, 7]
159
159
  Mat.vstack(a, a); Mat.hstack(a, b)
160
160
  a.gt(b) #=> [true, true, true; true, false, true] (numpy-like broadcasting)
161
- a.eq(b); a.ne(b); a.ge(b); a.lt(b); a.le(b)
161
+ a.eq(b); a.ge(b); a.lt(b); a.le(b)
162
162
  a.max #=> 7
163
163
  a.maximum(b) #=> [3, 2, 1; 5, 1, 7]
164
164
  Mat.maximum(a, b.repmat(1, 3), Mat.randn(2, 3))
@@ -199,9 +199,9 @@ Marshal.load(Marshal.dump(a))
199
199
  require 'kmat'
200
200
 
201
201
  Mat.randn(2, 2, random: Random.new) # In kmat, methods using random value, the generator can be specified by keyword `random'
202
- $MatRandom = Random.new # Or substitute into $MatRandom (default value of $MatRandom is Random::DEFAULT)
202
+ $MatRandom = Random.new # Or substitute into $MatRandom
203
203
  Random.new.randn # Random#randn returns a random value following N(0, 1)
204
- randn() # Kernel#randn is equivalent to Random::DEFAULT.randn
204
+ randn() # Kernel#randn is equivalent to $MatRandom.randn
205
205
  ```
206
206
 
207
207