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 +4 -4
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +10 -0
- data/README.md +11 -11
- data/ext/kmat/arith/binary.c +161 -139
- data/ext/kmat/arith/math.c +1 -1
- data/ext/kmat/arith/statistics.c +11 -11
- data/ext/kmat/arith/unary.c +6 -6
- data/ext/kmat/extconf.rb +3 -0
- data/ext/kmat/km_util.h +34 -13
- data/ext/kmat/kmat.h +3 -3
- data/ext/kmat/linalg/dla.c +185 -133
- data/ext/kmat/linalg/linalg.c +33 -17
- data/ext/kmat/linalg/norm.c +83 -69
- data/ext/kmat/linalg/vla.c +23 -23
- data/ext/kmat/linalg/working.c +42 -38
- data/ext/kmat/main.c +4 -4
- data/ext/kmat/smat/accessor.c +104 -104
- data/ext/kmat/smat/array.c +3 -3
- data/ext/kmat/smat/boxmuller.c +5 -5
- data/ext/kmat/smat/constructer.c +52 -52
- data/ext/kmat/smat/convert.c +21 -21
- data/ext/kmat/smat/elem.c +7 -7
- data/ext/kmat/smat/fund.c +37 -37
- data/ext/kmat/smat/share.c +28 -27
- data/ext/kmat/smat/smat.c +58 -42
- data/ext/kmat/smat/sort.c +148 -146
- data/kmat.gemspec +5 -4
- data/lib/kmat/accessor.rb +5 -5
- data/lib/kmat/linalg.rb +1 -2
- data/lib/kmat/random.rb +2 -2
- data/lib/kmat/version.rb +1 -1
- data/lib/kmat.rb +9 -9
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63f68444113fd2472e9d7464d88a7055c0b667fc16f6fe48a6efc6e57588cfb5
|
4
|
+
data.tar.gz: bb7da016d0f3dfcc526cfff275a90bcc42280a9fabc3e52541f3a6909c549949
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b01f793d1dde83a9ab7e079c0b9695eea75a41dd66a50df832ae8e6ee931cb27f650331d97096ace84efb57962f99730b4e8becf0e643a436fba5f9f76ab1a6
|
7
|
+
data.tar.gz: fccd83529c2af864a5dab072e483c5e25a4d9c9efe7b8a4e078337de1e2a5e1b975810bd4cfd300669a98013fd289dccda4a317382ba6ba7fce8025e319a9d47
|
data/.gitignore
CHANGED
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!(
|
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,
|
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;
|
115
|
-
a[] #=> [0,
|
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
|
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.
|
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
|
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
|
204
|
+
randn() # Kernel#randn is equivalent to $MatRandom.randn
|
205
205
|
```
|
206
206
|
|
207
207
|
|