pnmatrix 1.2.4 → 2.0.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/ext/nmatrix/extconf.rb +6 -6
- data/ext/nmatrix/math/math.h +2 -2
- data/ext/nmatrix/nmatrix.h +2 -1
- data/ext/nmatrix/ruby_nmatrix.c +36 -7
- data/ext/nmatrix/storage/list/list.cpp +3 -2
- data/lib/nmatrix/homogeneous.rb +3 -3
- data/lib/nmatrix/mkmf.rb +5 -2
- data/lib/nmatrix/nmatrix.rb +2 -2
- data/lib/nmatrix/shortcuts.rb +12 -15
- data/lib/nmatrix/version.rb +3 -3
- data/spec/stress_test_spec.rb +18 -0
- metadata +14 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c61ebac7b89f8d0fd43e09fdbe74aa0ef1564232c1f56224837cf8e1dd3ea7cc
|
|
4
|
+
data.tar.gz: 19c1789f16a5c87a91b2b0de44dbfa39bc024a117f166a43bd466528b7fe24c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a53e78fa91ce0d8dbc30a5a0d9ad035d768238f3c9fba3de3f7eb1e181e4f1756c815db600bfc40e608c26aa6810083b69b4442a4a338904c7581209db9d0092
|
|
7
|
+
data.tar.gz: 2ef44f7c3f1079411c29c189d7c988c6432521f08d3291bcfbf9e555b400ac685a09673db8d07175a281a7973b774ebac4141cb176f004c38e2557b791486373
|
data/ext/nmatrix/extconf.rb
CHANGED
|
@@ -54,13 +54,13 @@ $srcs = basenames.map { |b| "#{b}.cpp" }
|
|
|
54
54
|
create_conf_h("nmatrix_config.h")
|
|
55
55
|
create_makefile("nmatrix")
|
|
56
56
|
|
|
57
|
-
Dir.mkdir("data") unless Dir.
|
|
58
|
-
Dir.mkdir("util") unless Dir.
|
|
59
|
-
Dir.mkdir("storage") unless Dir.
|
|
57
|
+
Dir.mkdir("data") unless Dir.exist?("data")
|
|
58
|
+
Dir.mkdir("util") unless Dir.exist?("util")
|
|
59
|
+
Dir.mkdir("storage") unless Dir.exist?("storage")
|
|
60
60
|
Dir.chdir("storage") do
|
|
61
|
-
Dir.mkdir("yale") unless Dir.
|
|
62
|
-
Dir.mkdir("list") unless Dir.
|
|
63
|
-
Dir.mkdir("dense") unless Dir.
|
|
61
|
+
Dir.mkdir("yale") unless Dir.exist?("yale")
|
|
62
|
+
Dir.mkdir("list") unless Dir.exist?("list")
|
|
63
|
+
Dir.mkdir("dense") unless Dir.exist?("dense")
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# to clean up object files in subdirectories:
|
data/ext/nmatrix/math/math.h
CHANGED
|
@@ -339,12 +339,12 @@ namespace smmp_sort {
|
|
|
339
339
|
if (a < b) {
|
|
340
340
|
if (b < c) return b; // a b c
|
|
341
341
|
if (a < c) return c; // a c b
|
|
342
|
-
|
|
342
|
+
return a; // c a b
|
|
343
343
|
|
|
344
344
|
} else { // a > b
|
|
345
345
|
if (a < c) return a; // b a c
|
|
346
346
|
if (b < c) return c; // b c a
|
|
347
|
-
|
|
347
|
+
return b; // c b a
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
|
data/ext/nmatrix/nmatrix.h
CHANGED
|
@@ -338,6 +338,7 @@ NM_DEF_STRUCT_POST(NMATRIX); // };
|
|
|
338
338
|
/* Structs for dealing with VALUEs in use so that they don't get GC'd */
|
|
339
339
|
|
|
340
340
|
NM_DEF_STRUCT_PRE(NM_GC_LL_NODE); // struct NM_GC_LL_NODE {
|
|
341
|
+
VALUE* key; // VALUE* key;
|
|
341
342
|
VALUE* val; // VALUE* val;
|
|
342
343
|
size_t n; // size_t n;
|
|
343
344
|
NM_DECL_STRUCT(NM_GC_LL_NODE*, next); // NM_GC_LL_NODE* next;
|
|
@@ -401,7 +402,7 @@ NM_DEF_STRUCT_POST(NM_GC_HOLDER); // };
|
|
|
401
402
|
|
|
402
403
|
#define NM_CHECK_ALLOC(x) if (!x) rb_raise(rb_eNoMemError, "insufficient memory");
|
|
403
404
|
|
|
404
|
-
#define RB_FILE_EXISTS(fn) (rb_funcall(rb_const_get(rb_cObject, rb_intern("File")), rb_intern("
|
|
405
|
+
#define RB_FILE_EXISTS(fn) (rb_funcall(rb_const_get(rb_cObject, rb_intern("File")), rb_intern("exist?"), 1, (fn)) == Qtrue)
|
|
405
406
|
|
|
406
407
|
#define IsNMatrixType(v) (RB_TYPE_P(v, T_DATA) && (RDATA(v)->dfree == (RUBY_DATA_FUNC)nm_delete || RDATA(v)->dfree == (RUBY_DATA_FUNC)nm_delete_ref))
|
|
407
408
|
#define CheckNMatrixType(v) if (!IsNMatrixType(v)) rb_raise(rb_eTypeError, "expected NMatrix on left-hand side of operation");
|
data/ext/nmatrix/ruby_nmatrix.c
CHANGED
|
@@ -409,6 +409,7 @@ void Init_nmatrix() {
|
|
|
409
409
|
*/
|
|
410
410
|
static VALUE nm_alloc(VALUE klass) {
|
|
411
411
|
NMATRIX* mat = NM_ALLOC(NMATRIX);
|
|
412
|
+
mat->stype = nm::DENSE_STORE;
|
|
412
413
|
mat->storage = NULL;
|
|
413
414
|
|
|
414
415
|
// DO NOT MARK This STRUCT. It has no storage allocated, and no stype, so mark will do an invalid something.
|
|
@@ -454,6 +455,8 @@ static VALUE nm_capacity(VALUE self) {
|
|
|
454
455
|
* Mark function.
|
|
455
456
|
*/
|
|
456
457
|
void nm_mark(NMATRIX* mat) {
|
|
458
|
+
if (!mat || !mat->storage) return;
|
|
459
|
+
|
|
457
460
|
STYPE_MARK_TABLE(mark)
|
|
458
461
|
mark[mat->stype](mat->storage);
|
|
459
462
|
}
|
|
@@ -463,12 +466,17 @@ void nm_mark(NMATRIX* mat) {
|
|
|
463
466
|
* Destructor.
|
|
464
467
|
*/
|
|
465
468
|
void nm_delete(NMATRIX* mat) {
|
|
469
|
+
if (!mat) return;
|
|
470
|
+
|
|
466
471
|
static void (*ttable[nm::NUM_STYPES])(STORAGE*) = {
|
|
467
472
|
nm_dense_storage_delete,
|
|
468
473
|
nm_list_storage_delete,
|
|
469
474
|
nm_yale_storage_delete
|
|
470
475
|
};
|
|
471
|
-
|
|
476
|
+
|
|
477
|
+
if (mat->storage && mat->stype < nm::NUM_STYPES) {
|
|
478
|
+
ttable[mat->stype](mat->storage);
|
|
479
|
+
}
|
|
472
480
|
|
|
473
481
|
NM_FREE(mat);
|
|
474
482
|
}
|
|
@@ -477,12 +485,17 @@ void nm_delete(NMATRIX* mat) {
|
|
|
477
485
|
* Slicing destructor.
|
|
478
486
|
*/
|
|
479
487
|
void nm_delete_ref(NMATRIX* mat) {
|
|
488
|
+
if (!mat) return;
|
|
489
|
+
|
|
480
490
|
static void (*ttable[nm::NUM_STYPES])(STORAGE*) = {
|
|
481
491
|
nm_dense_storage_delete_ref,
|
|
482
492
|
nm_list_storage_delete_ref,
|
|
483
493
|
nm_yale_storage_delete_ref
|
|
484
494
|
};
|
|
485
|
-
|
|
495
|
+
|
|
496
|
+
if (mat->storage && mat->stype < nm::NUM_STYPES) {
|
|
497
|
+
ttable[mat->stype](mat->storage);
|
|
498
|
+
}
|
|
486
499
|
|
|
487
500
|
NM_FREE(mat);
|
|
488
501
|
}
|
|
@@ -503,7 +516,9 @@ static void __nm_mark_value_container(NM_GC_HOLDER* gc_value_holder_struct) {
|
|
|
503
516
|
if (gc_value_holder_struct && gc_value_holder_struct->start) {
|
|
504
517
|
NM_GC_LL_NODE* curr = gc_value_holder_struct->start;
|
|
505
518
|
while (curr) {
|
|
506
|
-
|
|
519
|
+
if (curr->val && curr->n) {
|
|
520
|
+
rb_gc_mark_locations(curr->val, curr->val + curr->n);
|
|
521
|
+
}
|
|
507
522
|
curr = curr->next;
|
|
508
523
|
}
|
|
509
524
|
}
|
|
@@ -540,7 +555,13 @@ void nm_register_values(VALUE* values, size_t n) {
|
|
|
540
555
|
} else {
|
|
541
556
|
to_insert = NM_ALLOC_NONRUBY(NM_GC_LL_NODE);
|
|
542
557
|
}
|
|
543
|
-
to_insert->
|
|
558
|
+
to_insert->key = values;
|
|
559
|
+
if (n) {
|
|
560
|
+
to_insert->val = NM_ALLOC_N(VALUE, n);
|
|
561
|
+
memcpy(to_insert->val, values, sizeof(VALUE) * n);
|
|
562
|
+
} else {
|
|
563
|
+
to_insert->val = NULL;
|
|
564
|
+
}
|
|
544
565
|
to_insert->n = n;
|
|
545
566
|
to_insert->next = gc_value_holder_struct->start;
|
|
546
567
|
gc_value_holder_struct->start = to_insert;
|
|
@@ -557,13 +578,17 @@ void nm_unregister_values(VALUE* values, size_t n) {
|
|
|
557
578
|
NM_GC_LL_NODE* curr = gc_value_holder_struct->start;
|
|
558
579
|
NM_GC_LL_NODE* last = NULL;
|
|
559
580
|
while (curr) {
|
|
560
|
-
if (curr->
|
|
581
|
+
if (curr->key == values) {
|
|
561
582
|
if (last) {
|
|
562
583
|
last->next = curr->next;
|
|
563
584
|
} else {
|
|
564
585
|
gc_value_holder_struct->start = curr->next;
|
|
565
586
|
}
|
|
587
|
+
if (curr->val) {
|
|
588
|
+
NM_FREE(curr->val);
|
|
589
|
+
}
|
|
566
590
|
curr->next = allocated_pool->start;
|
|
591
|
+
curr->key = NULL;
|
|
567
592
|
curr->val = NULL;
|
|
568
593
|
curr->n = 0;
|
|
569
594
|
allocated_pool->start = curr;
|
|
@@ -602,14 +627,18 @@ void nm_completely_unregister_value(VALUE* val) {
|
|
|
602
627
|
NM_GC_LL_NODE* curr = gc_value_holder_struct->start;
|
|
603
628
|
NM_GC_LL_NODE* last = NULL;
|
|
604
629
|
while (curr) {
|
|
605
|
-
if (curr->
|
|
630
|
+
if (curr->key == val) {
|
|
606
631
|
if (last) {
|
|
607
632
|
last->next = curr->next;
|
|
608
633
|
} else {
|
|
609
634
|
gc_value_holder_struct->start = curr->next;
|
|
610
635
|
}
|
|
611
636
|
NM_GC_LL_NODE* temp_next = curr->next;
|
|
637
|
+
if (curr->val) {
|
|
638
|
+
NM_FREE(curr->val);
|
|
639
|
+
}
|
|
612
640
|
curr->next = allocated_pool->start;
|
|
641
|
+
curr->key = NULL;
|
|
613
642
|
curr->val = NULL;
|
|
614
643
|
curr->n = 0;
|
|
615
644
|
allocated_pool->start = curr;
|
|
@@ -1144,7 +1173,7 @@ static VALUE nm_init_new_version(int argc, VALUE* argv, VALUE self) {
|
|
|
1144
1173
|
// Get the shape.
|
|
1145
1174
|
size_t dim;
|
|
1146
1175
|
size_t* shape = interpret_shape(shape_ary, &dim);
|
|
1147
|
-
void* init;
|
|
1176
|
+
void* init = NULL;
|
|
1148
1177
|
void* v = NULL;
|
|
1149
1178
|
size_t v_size = 0;
|
|
1150
1179
|
|
|
@@ -779,7 +779,7 @@ void nm_list_storage_unregister(const STORAGE* s) {
|
|
|
779
779
|
*/
|
|
780
780
|
static NODE* list_storage_get_single_node(LIST_STORAGE* s, SLICE* slice) {
|
|
781
781
|
LIST* l = s->rows;
|
|
782
|
-
NODE* n;
|
|
782
|
+
NODE* n = NULL;
|
|
783
783
|
|
|
784
784
|
for (size_t r = 0; r < s->dim; r++) {
|
|
785
785
|
n = nm::list::find(l, s->offset[r] + slice->coords[r]);
|
|
@@ -1160,11 +1160,12 @@ void* nm_list_storage_get(const STORAGE* storage, SLICE* slice) {
|
|
|
1160
1160
|
void* nm_list_storage_ref(const STORAGE* storage, SLICE* slice) {
|
|
1161
1161
|
LIST_STORAGE* s = (LIST_STORAGE*)storage;
|
|
1162
1162
|
LIST_STORAGE* ns = NULL;
|
|
1163
|
+
NODE* n = NULL;
|
|
1163
1164
|
nm_list_storage_register(s);
|
|
1164
1165
|
|
|
1165
1166
|
//TODO: It needs a refactoring.
|
|
1166
1167
|
if (slice->single) {
|
|
1167
|
-
|
|
1168
|
+
n = list_storage_get_single_node(s, slice);
|
|
1168
1169
|
nm_list_storage_unregister(s);
|
|
1169
1170
|
return (n ? n->val : s->default_val);
|
|
1170
1171
|
} else {
|
data/lib/nmatrix/homogeneous.rb
CHANGED
|
@@ -69,7 +69,7 @@ class NMatrix
|
|
|
69
69
|
NMatrix.new(4, [1.0, 0.0, 0.0, 0.0,
|
|
70
70
|
0.0, c, -s, 0.0,
|
|
71
71
|
0.0, s, c, 0.0,
|
|
72
|
-
0.0, 0.0, 0.0, 1.0], {dtype: :float64}.merge(opts))
|
|
72
|
+
0.0, 0.0, 0.0, 1.0], **{dtype: :float64}.merge(opts))
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
def y_rotation angle_in_radians, opts={}
|
|
@@ -78,7 +78,7 @@ class NMatrix
|
|
|
78
78
|
NMatrix.new(4, [ c, 0.0, s, 0.0,
|
|
79
79
|
0.0, 1.0, 0.0, 0.0,
|
|
80
80
|
-s, 0.0, c, 0.0,
|
|
81
|
-
0.0, 0.0, 0.0, 1.0], {dtype: :float64}.merge(opts))
|
|
81
|
+
0.0, 0.0, 0.0, 1.0], **{dtype: :float64}.merge(opts))
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def z_rotation angle_in_radians, opts={}
|
|
@@ -87,7 +87,7 @@ class NMatrix
|
|
|
87
87
|
NMatrix.new(4, [ c, -s, 0.0, 0.0,
|
|
88
88
|
s, c, 0.0, 0.0,
|
|
89
89
|
0.0, 0.0, 1.0, 0.0,
|
|
90
|
-
0.0, 0.0, 0.0, 1.0], {dtype: :float64}.merge(opts))
|
|
90
|
+
0.0, 0.0, 0.0, 1.0], **{dtype: :float64}.merge(opts))
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
|
data/lib/nmatrix/mkmf.rb
CHANGED
|
@@ -69,14 +69,17 @@ if CONFIG['CXX'] == 'clang++'
|
|
|
69
69
|
$CXX_STANDARD = 'c++11'
|
|
70
70
|
else
|
|
71
71
|
version = gplusplus_version
|
|
72
|
-
|
|
72
|
+
major_version = version.split('.')[0].to_i # string comparison fails past 10.0.0
|
|
73
|
+
|
|
74
|
+
if major_version < 5 and
|
|
75
|
+
version < '4.3.0' && CONFIG['CXX'] == 'g++' # see if we can find a newer G++, unless it's been overridden by user
|
|
73
76
|
if !find_newer_gplusplus
|
|
74
77
|
raise("You need a version of g++ which supports -std=c++0x or -std=c++11. If you're on a Mac and using Homebrew, we recommend using mac-brew-gcc.sh to install a more recent g++.")
|
|
75
78
|
end
|
|
76
79
|
version = gplusplus_version
|
|
77
80
|
end
|
|
78
81
|
|
|
79
|
-
if version < '4.7.0'
|
|
82
|
+
if major_version < 5 and version < '4.7.0'
|
|
80
83
|
$CXX_STANDARD = 'c++0x'
|
|
81
84
|
else
|
|
82
85
|
$CXX_STANDARD = 'c++11'
|
data/lib/nmatrix/nmatrix.rb
CHANGED
|
@@ -1034,7 +1034,7 @@ class NMatrix
|
|
|
1034
1034
|
def clone_structure(capacity = nil)
|
|
1035
1035
|
opts = {stype: self.stype, default: self.default_value, dtype: self.dtype}
|
|
1036
1036
|
opts = {capacity: capacity}.merge(opts) if self.yale?
|
|
1037
|
-
NMatrix.new(self.shape, opts)
|
|
1037
|
+
NMatrix.new(self.shape, **opts)
|
|
1038
1038
|
end
|
|
1039
1039
|
|
|
1040
1040
|
#
|
|
@@ -1099,7 +1099,7 @@ protected
|
|
|
1099
1099
|
# We can generally predict the change in capacity for Yale.
|
|
1100
1100
|
opts = {capacity: self.capacity - self.shape[0] + new_shape[0]}.merge(opts)
|
|
1101
1101
|
end
|
|
1102
|
-
NMatrix.new(new_shape, opts)
|
|
1102
|
+
NMatrix.new(new_shape, **opts)
|
|
1103
1103
|
end
|
|
1104
1104
|
|
|
1105
1105
|
|
data/lib/nmatrix/shortcuts.rb
CHANGED
|
@@ -196,11 +196,8 @@ class NMatrix
|
|
|
196
196
|
i += 1
|
|
197
197
|
end
|
|
198
198
|
|
|
199
|
-
# A row vector should be stored as 1xN, not N
|
|
200
|
-
#shape.unshift(1) if shape.size == 1
|
|
201
|
-
|
|
202
199
|
# Then flatten the array.
|
|
203
|
-
NMatrix.new(shape, params.flatten, options)
|
|
200
|
+
NMatrix.new(shape, params.flatten, **options)
|
|
204
201
|
end
|
|
205
202
|
|
|
206
203
|
#
|
|
@@ -230,7 +227,7 @@ class NMatrix
|
|
|
230
227
|
# NMatrix.zeros([1, 5], dtype: :int32) # => 0 0 0 0 0
|
|
231
228
|
#
|
|
232
229
|
def zeros(shape, opts = {})
|
|
233
|
-
NMatrix.new(shape, 0, {:dtype => :float64}.merge(opts))
|
|
230
|
+
NMatrix.new(shape, 0, **{:dtype => :float64}.merge(opts))
|
|
234
231
|
end
|
|
235
232
|
alias :zeroes :zeros
|
|
236
233
|
|
|
@@ -255,7 +252,7 @@ class NMatrix
|
|
|
255
252
|
# 1 1 1
|
|
256
253
|
#
|
|
257
254
|
def ones(shape, opts={})
|
|
258
|
-
NMatrix.new(shape, 1, {:dtype => :float64
|
|
255
|
+
NMatrix.new(shape, 1, **{:dtype => :float64}.merge(opts))
|
|
259
256
|
end
|
|
260
257
|
|
|
261
258
|
# call-seq:
|
|
@@ -268,7 +265,7 @@ class NMatrix
|
|
|
268
265
|
# @return [NMatrix] a new nmatrix filled with ones.
|
|
269
266
|
#
|
|
270
267
|
def ones_like(nm)
|
|
271
|
-
NMatrix.ones(nm.shape, dtype: nm.dtype, stype: nm.stype, capacity: nm.capacity
|
|
268
|
+
NMatrix.ones(nm.shape, dtype: nm.dtype, stype: nm.stype, capacity: nm.capacity)
|
|
272
269
|
end
|
|
273
270
|
|
|
274
271
|
# call-seq:
|
|
@@ -281,7 +278,7 @@ class NMatrix
|
|
|
281
278
|
# @return [NMatrix] a new nmatrix filled with zeros.
|
|
282
279
|
#
|
|
283
280
|
def zeros_like(nm)
|
|
284
|
-
NMatrix.zeros(nm.shape, dtype: nm.dtype, stype: nm.stype, capacity: nm.capacity
|
|
281
|
+
NMatrix.zeros(nm.shape, dtype: nm.dtype, stype: nm.stype, capacity: nm.capacity)
|
|
285
282
|
end
|
|
286
283
|
|
|
287
284
|
#
|
|
@@ -345,7 +342,7 @@ class NMatrix
|
|
|
345
342
|
# 0.3333333333333333 0.25 0.2
|
|
346
343
|
#
|
|
347
344
|
def hilbert(shape, opts={})
|
|
348
|
-
m = NMatrix.new([shape,shape], {:dtype => :float64}.merge(opts))
|
|
345
|
+
m = NMatrix.new([shape,shape], **{:dtype => :float64}.merge(opts))
|
|
349
346
|
0.upto(shape - 1) do |i|
|
|
350
347
|
0.upto(i) do |j|
|
|
351
348
|
m[i,j] = 1.0 / (j + i + 1)
|
|
@@ -378,8 +375,8 @@ class NMatrix
|
|
|
378
375
|
#
|
|
379
376
|
def inv_hilbert(shape, opts={})
|
|
380
377
|
opts = {:dtype => :float64}.merge(opts)
|
|
381
|
-
m = NMatrix.new([shape,shape],opts)
|
|
382
|
-
combination = NMatrix.new([2*shape,2*shape],opts)
|
|
378
|
+
m = NMatrix.new([shape,shape], **opts)
|
|
379
|
+
combination = NMatrix.new([2*shape,2*shape], **opts)
|
|
383
380
|
#combinations refers to the combination of n things taken k at a time
|
|
384
381
|
0.upto(2*shape-1) do |i|
|
|
385
382
|
0.upto(i) do |j|
|
|
@@ -553,7 +550,7 @@ class NMatrix
|
|
|
553
550
|
NMatrix.size(shape).times { |i| random_values << rng.rand(scale) }
|
|
554
551
|
end
|
|
555
552
|
|
|
556
|
-
NMatrix.new(shape, random_values, {:dtype => :float64, :stype => :dense}.merge(opts))
|
|
553
|
+
NMatrix.new(shape, random_values, **{:dtype => :float64, :stype => :dense}.merge(opts))
|
|
557
554
|
end
|
|
558
555
|
alias :rand :random
|
|
559
556
|
|
|
@@ -595,7 +592,7 @@ class NMatrix
|
|
|
595
592
|
#
|
|
596
593
|
def magic(shape, opts={})
|
|
597
594
|
raise(ArgumentError, "shape of two is not allowed") if shape == 2
|
|
598
|
-
nm = NMatrix.new([shape,shape], 0, {:dtype => :float64}.merge(opts))
|
|
595
|
+
nm = NMatrix.new([shape,shape], 0, **{:dtype => :float64}.merge(opts))
|
|
599
596
|
if shape % 2 != 0
|
|
600
597
|
MagicHelpers.odd_magic nm, shape
|
|
601
598
|
elsif shape % 4 == 0
|
|
@@ -841,7 +838,7 @@ class NMatrix
|
|
|
841
838
|
values = (0 ... NMatrix.size(shape)).to_a
|
|
842
839
|
|
|
843
840
|
# It'll produce :int32, except if a dtype is provided.
|
|
844
|
-
NMatrix.new(shape, values, {:stype => :dense}.merge(options))
|
|
841
|
+
NMatrix.new(shape, values, **{:stype => :dense}.merge(options))
|
|
845
842
|
end
|
|
846
843
|
|
|
847
844
|
{:bindgen => :byte, :indgen => :int64, :findgen => :float32, :dindgen => :float64,
|
|
@@ -969,7 +966,7 @@ module NVector #:nodoc:
|
|
|
969
966
|
random_values = []
|
|
970
967
|
size.times { |i| random_values << rng.rand }
|
|
971
968
|
|
|
972
|
-
NMatrix.new([size,1], random_values, opts)
|
|
969
|
+
NMatrix.new([size,1], random_values, **opts)
|
|
973
970
|
end
|
|
974
971
|
|
|
975
972
|
#
|
data/lib/nmatrix/version.rb
CHANGED
|
@@ -27,9 +27,9 @@ class NMatrix
|
|
|
27
27
|
# native IO. If you change the format, please make sure that native
|
|
28
28
|
# IO can still understand NMatrix::VERSION.
|
|
29
29
|
module VERSION #:nodoc:
|
|
30
|
-
MAJOR =
|
|
31
|
-
MINOR =
|
|
32
|
-
TINY =
|
|
30
|
+
MAJOR = 2
|
|
31
|
+
MINOR = 0
|
|
32
|
+
TINY = 0
|
|
33
33
|
#PRE = "a"
|
|
34
34
|
|
|
35
35
|
STRING = [MAJOR, MINOR, TINY].compact.join(".")
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe NMatrix do
|
|
4
|
+
specify do
|
|
5
|
+
200.times do |i|
|
|
6
|
+
size = rand(500..1000)
|
|
7
|
+
m1 = NMatrix.new([size, size], 0, stype: :yale, dtype: :int32)
|
|
8
|
+
m2 = m1.clone
|
|
9
|
+
|
|
10
|
+
rand(1000).times do |j|
|
|
11
|
+
m1[rand(size), rand(size)] = 1
|
|
12
|
+
m2[rand(size), rand(size)] = 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
(m1*m2).det
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pnmatrix
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Woods
|
|
8
8
|
- Chris Wailes
|
|
9
9
|
- Aleksey Timin
|
|
10
|
-
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
12
|
date: 1980-01-01 00:00:00.000000000 Z
|
|
@@ -16,14 +15,14 @@ dependencies:
|
|
|
16
15
|
name: bundler
|
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
|
18
17
|
requirements:
|
|
19
|
-
- - "
|
|
18
|
+
- - ">"
|
|
20
19
|
- !ruby/object:Gem::Version
|
|
21
20
|
version: '1.6'
|
|
22
21
|
type: :development
|
|
23
22
|
prerelease: false
|
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
24
|
requirements:
|
|
26
|
-
- - "
|
|
25
|
+
- - ">"
|
|
27
26
|
- !ruby/object:Gem::Version
|
|
28
27
|
version: '1.6'
|
|
29
28
|
- !ruby/object:Gem::Dependency
|
|
@@ -44,28 +43,28 @@ dependencies:
|
|
|
44
43
|
name: rake
|
|
45
44
|
requirement: !ruby/object:Gem::Requirement
|
|
46
45
|
requirements:
|
|
47
|
-
- - "
|
|
46
|
+
- - ">"
|
|
48
47
|
- !ruby/object:Gem::Version
|
|
49
48
|
version: '10.3'
|
|
50
49
|
type: :development
|
|
51
50
|
prerelease: false
|
|
52
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
53
52
|
requirements:
|
|
54
|
-
- - "
|
|
53
|
+
- - ">"
|
|
55
54
|
- !ruby/object:Gem::Version
|
|
56
55
|
version: '10.3'
|
|
57
56
|
- !ruby/object:Gem::Dependency
|
|
58
57
|
name: rake-compiler
|
|
59
58
|
requirement: !ruby/object:Gem::Requirement
|
|
60
59
|
requirements:
|
|
61
|
-
- - "
|
|
60
|
+
- - ">"
|
|
62
61
|
- !ruby/object:Gem::Version
|
|
63
62
|
version: '0.8'
|
|
64
63
|
type: :development
|
|
65
64
|
prerelease: false
|
|
66
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
67
66
|
requirements:
|
|
68
|
-
- - "
|
|
67
|
+
- - ">"
|
|
69
68
|
- !ruby/object:Gem::Version
|
|
70
69
|
version: '0.8'
|
|
71
70
|
- !ruby/object:Gem::Dependency
|
|
@@ -92,28 +91,28 @@ dependencies:
|
|
|
92
91
|
name: rspec
|
|
93
92
|
requirement: !ruby/object:Gem::Requirement
|
|
94
93
|
requirements:
|
|
95
|
-
- - "
|
|
94
|
+
- - ">"
|
|
96
95
|
- !ruby/object:Gem::Version
|
|
97
96
|
version: '2.14'
|
|
98
97
|
type: :development
|
|
99
98
|
prerelease: false
|
|
100
99
|
version_requirements: !ruby/object:Gem::Requirement
|
|
101
100
|
requirements:
|
|
102
|
-
- - "
|
|
101
|
+
- - ">"
|
|
103
102
|
- !ruby/object:Gem::Version
|
|
104
103
|
version: '2.14'
|
|
105
104
|
- !ruby/object:Gem::Dependency
|
|
106
105
|
name: rspec-longrun
|
|
107
106
|
requirement: !ruby/object:Gem::Requirement
|
|
108
107
|
requirements:
|
|
109
|
-
- - "
|
|
108
|
+
- - ">"
|
|
110
109
|
- !ruby/object:Gem::Version
|
|
111
110
|
version: '1.0'
|
|
112
111
|
type: :development
|
|
113
112
|
prerelease: false
|
|
114
113
|
version_requirements: !ruby/object:Gem::Requirement
|
|
115
114
|
requirements:
|
|
116
|
-
- - "
|
|
115
|
+
- - ">"
|
|
117
116
|
- !ruby/object:Gem::Version
|
|
118
117
|
version: '1.0'
|
|
119
118
|
description: NMatrix is a linear algebra library for Ruby, written mostly in C and
|
|
@@ -232,6 +231,7 @@ files:
|
|
|
232
231
|
- spec/slice_set_spec.rb
|
|
233
232
|
- spec/spec_helper.rb
|
|
234
233
|
- spec/stat_spec.rb
|
|
234
|
+
- spec/stress_test_spec.rb
|
|
235
235
|
- spec/test.pcd
|
|
236
236
|
- spec/utm5940.mtx
|
|
237
237
|
homepage: http://sciruby.com
|
|
@@ -261,8 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
261
261
|
- !ruby/object:Gem::Version
|
|
262
262
|
version: '0'
|
|
263
263
|
requirements: []
|
|
264
|
-
rubygems_version: 3.2
|
|
265
|
-
signing_key:
|
|
264
|
+
rubygems_version: 3.7.2
|
|
266
265
|
specification_version: 4
|
|
267
266
|
summary: NMatrix is a linear algebra library for Ruby
|
|
268
267
|
test_files:
|
|
@@ -291,5 +290,6 @@ test_files:
|
|
|
291
290
|
- spec/slice_set_spec.rb
|
|
292
291
|
- spec/spec_helper.rb
|
|
293
292
|
- spec/stat_spec.rb
|
|
293
|
+
- spec/stress_test_spec.rb
|
|
294
294
|
- spec/test.pcd
|
|
295
295
|
- spec/utm5940.mtx
|