kmat 0.1.0 → 0.1.2

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: 63f68444113fd2472e9d7464d88a7055c0b667fc16f6fe48a6efc6e57588cfb5
4
- data.tar.gz: bb7da016d0f3dfcc526cfff275a90bcc42280a9fabc3e52541f3a6909c549949
3
+ metadata.gz: 81be32fe807061f97a8fa19a95daf8bd61583b794648621e2a377f50882a3a87
4
+ data.tar.gz: 223a8091e25b86c4080ba7d6ed311cf23f17f7e5f3adb602633985a5ef71a9ab
5
5
  SHA512:
6
- metadata.gz: 1b01f793d1dde83a9ab7e079c0b9695eea75a41dd66a50df832ae8e6ee931cb27f650331d97096ace84efb57962f99730b4e8becf0e643a436fba5f9f76ab1a6
7
- data.tar.gz: fccd83529c2af864a5dab072e483c5e25a4d9c9efe7b8a4e078337de1e2a5e1b975810bd4cfd300669a98013fd289dccda4a317382ba6ba7fce8025e319a9d47
6
+ metadata.gz: 146af53cd0b3b5f2d19508e4aad64fa7fa7a04ae668a8f86fd1886fbc06e37117502a9341f4ea998cb79e263cedbd0e7b71beae043eaaba8a5ef6b8e62d1d0ef
7
+ data.tar.gz: 764a5f1817fada5ea36c1d91dc3aeefc2c966e663963821b03a70da118cf44d4e91f98958722c7bb77f60043e651b4540bfcfa1f5c63fc4becf2f1652e1ba120
data/CHANGELOG.md CHANGED
@@ -5,21 +5,29 @@
5
5
 
6
6
  ## 0.0.2 2019/12/03
7
7
  ### Bug fix
8
- - Fixed an error in km_copy_from_work() for transposed matricies.
8
+ - Fixed an error in `km_copy_from_work()` for transposed matricies.
9
9
  Linear algebra methods used with transposed output matricies were affected.
10
10
  ### New feature
11
- - Added Mat#geo_mean which returns the geometric mean of self's elements.
12
- - Added some normalizing methods: Mat#normalize/!, Mat#geo_normalize/! and Mat#svd_symmetrize/!
11
+ - Added` Mat#geo_mean` which returns the geometric mean of self's elements.
12
+ - Added some normalizing methods: `Mat#normalize/!`, `Mat#geo_normalize/!` and `Mat#svd_symmetrize/!`.
13
13
 
14
14
  ## 0.0.3 2019/12/03
15
- - Fix a bug in Mat#geo_normalize
15
+ - Fix a bug in `Mat#geo_normalize`.
16
16
 
17
17
  ## 0.1.0 2022/03/20
18
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.
19
+ - Quit using `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
25
  - Fixed some minor bugs.
26
+
27
+ ## 0.1.1 2026/01/07
28
+ - Deprecate the global variable `$MatRandom`.
29
+ - It is replaced by a class variable `@@random` under the `Mat` class.
30
+ - The class variable can be obtained by `Mat.random` and can be substituted by `Mat.random=(new_random_instance)`.
31
+
32
+ ## 0.1.2 2026/01/08
33
+ - Fixed a bug that `Numeric#*(Mat)` raised TypeError on Ruby 3.4 or later.
data/README.md CHANGED
@@ -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
+ Mat.random = Random.new # Or substitute the class variable
203
203
  Random.new.randn # Random#randn returns a random value following N(0, 1)
204
- randn() # Kernel#randn is equivalent to $MatRandom.randn
204
+ randn() # Kernel#randn is equivalent to Mat.random.randn
205
205
  ```
206
206
 
207
207
 
data/ext/kmat/extconf.rb CHANGED
@@ -15,7 +15,6 @@ end
15
15
  $CFLAGS = "$(cflags) -std=c11"
16
16
  $CFLAGS += " -m64" if mkl
17
17
 
18
- #$warnflags = "-Wall -Wextra -Wdeprecated-declarations -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wmissing-noreturn -Wno-unused-parameter -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wno-maybe-uninitialized -Winit-self -Wshadow"
19
18
  $warnflags = "-Wall -Wextra -Wdeprecated-declarations -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wmissing-noreturn -Wno-unused-parameter -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Winit-self -Wshadow -Wlogical-op -Wconversion"
20
19
 
21
20
  $DLDFLAGS += " -Wl,-Bsymbolic -fPIC"
data/ext/kmat/id.txt CHANGED
@@ -41,6 +41,7 @@ op_pow **
41
41
  op_uminus -@
42
42
  quo
43
43
  rand
44
+ random
44
45
  real
45
46
  to_c
46
47
  to_s
@@ -351,4 +351,3 @@ void ztrsm_(char *side, char *uplo, char *trans, char *diag, int *m, int *n,
351
351
  #endif
352
352
 
353
353
  #endif
354
-
@@ -63,10 +63,20 @@ km_random_randn(int argc, VALUE *argv, VALUE random)
63
63
  }
64
64
  }
65
65
 
66
+ VALUE
67
+ kmm_Mat__set_random(VALUE self, VALUE other)
68
+ {
69
+ if ( rb_obj_is_kind_of(other, rb_cRandom) ) {
70
+ kmgv_mat_random = other;
71
+ return kmgv_mat_random;
72
+ } else {
73
+ rb_raise(rb_eTypeError, "the argument must be an Random, not %s", rb_obj_classname(other));
74
+ }
75
+ }
76
+
66
77
  void
67
78
  km_Mat_rand_init(void)
68
79
  {
69
- kmgv_mat_random = rb_funcall(rb_cRandom, id_new, 0);
70
- rb_define_variable("$MatRandom", &kmgv_mat_random);
80
+ kmgv_mat_random = rb_funcall(km_cMat, id_random, 0);
71
81
  rb_define_method(rb_cRandom, "randn", km_random_randn, -1);
72
82
  }
data/lib/kmat/arith.rb CHANGED
@@ -2,7 +2,7 @@ class Mat
2
2
  # to define Numeric * Mat as Mat#scalar(Numeric) remaining Mat * Mat is undefined,
3
3
  # this returns non‐standard value
4
4
  def coerce(other)
5
- if caller.first[/`([^']*)'/, 1] == '*'
5
+ if caller.first[/[`#]([^']*)'/, 1] == '*'
6
6
  [self, other]
7
7
  else
8
8
  raise TypeError, "Mat can't be coerced into #{other.class}"
data/lib/kmat/linalg.rb CHANGED
@@ -63,10 +63,10 @@ class Mat
63
63
  Mat.new(self.col_size, 1, :f).wls!(self, b, w)
64
64
  end
65
65
 
66
- def rand_orth(random: $MatRandom)
66
+ def rand_orth(random: @@andom)
67
67
  _rand_orth(random)
68
68
  end
69
- def self.rand_orth(n, random: $MatRandom)
69
+ def self.rand_orth(n, random: @@andom)
70
70
  Mat.new(n, n, :float).rand_orth(random: random)
71
71
  end
72
72
 
@@ -275,4 +275,3 @@ class Mat
275
275
  end
276
276
  end
277
277
  end
278
-
data/lib/kmat/random.rb CHANGED
@@ -78,7 +78,7 @@ class << Random
78
78
  kmat_srand_org(*args)
79
79
  end
80
80
  def randn(*args)
81
- $MatRandom.randn(*args)
81
+ Mat.random.randn(*args)
82
82
  end
83
83
  end
84
84
 
@@ -89,18 +89,18 @@ module Kernel
89
89
  end
90
90
 
91
91
  class Mat
92
- def rand(arg=nil, random: $MatRandom)
92
+ def rand(arg=nil, random: @@random)
93
93
  _rand0(random, arg)
94
94
  end
95
- def randn(random: $MatRandom)
95
+ def randn(random: @@random)
96
96
  _randn0(random)
97
97
  end
98
98
  end
99
99
  class << Mat
100
- def rand(m=1, n=1, random: $MatRandom)
100
+ def rand(m=1, n=1, random: self.random)
101
101
  _rand0(m, n, random)
102
102
  end
103
- def randn(m=1, n=1, random: $MatRandom)
103
+ def randn(m=1, n=1, random: self.random)
104
104
  _randn0(m, n, random)
105
105
  end
106
106
  end
data/lib/kmat/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Mat
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/kmat.rb CHANGED
@@ -2,6 +2,13 @@ require_relative "./kmat/version"
2
2
 
3
3
  class Mat
4
4
  include Enumerable
5
+ @@random = Random.new
6
+ def self.random
7
+ @@random
8
+ end
9
+ def self.random=(other)
10
+ @@random = _set_random(other)
11
+ end
5
12
  end
6
13
 
7
14
  class << Mat
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kmat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - KAZOON
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-03-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -80,7 +79,6 @@ dependencies:
80
79
  - - ">="
81
80
  - !ruby/object:Gem::Version
82
81
  version: 3.12.0
83
- description:
84
82
  email:
85
83
  - cycloawaodorin+gem@gmail.com
86
84
  executables: []
@@ -149,7 +147,6 @@ metadata:
149
147
  homepage_uri: https://github.com/cycloawaodorin/
150
148
  source_code_uri: https://github.com/cycloawaodorin/kmat
151
149
  changelog_uri: https://github.com/cycloawaodorin/kmat/blob/master/CHANGELOG.md
152
- post_install_message:
153
150
  rdoc_options: []
154
151
  require_paths:
155
152
  - lib
@@ -164,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
161
  - !ruby/object:Gem::Version
165
162
  version: '0'
166
163
  requirements: []
167
- rubygems_version: 3.4.8
168
- signing_key:
164
+ rubygems_version: 4.0.3
169
165
  specification_version: 4
170
166
  summary: Kmat is a Ruby gem for matrix operations. Kmat uses BLAS/LAPACK as back-end.
171
167
  test_files: []