rmatrix 0.1.18 → 0.1.19

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
  SHA1:
3
- metadata.gz: 9829c8d78878d7413b7136080244726dd48a0499
4
- data.tar.gz: 4ce19066f2407123a6bcdbce084d9c1701be6a6e
3
+ metadata.gz: 9fdaca317864fc78691e5a7326da776a3c35d18b
4
+ data.tar.gz: 7f1502ddf8c910b243f7447012223045c9632d41
5
5
  SHA512:
6
- metadata.gz: 7f663caa0b96e5f80b16960adccd25d911be1e4b8e810fe68b5023a968e043a36da7041faec1b103639419610fb2a505438da6a87df6e3961dca6e2ffd12ddf0
7
- data.tar.gz: 515388b00480af403af56f60b5ba38e3c0ab71fe257a84c47b33c220eaaee86d827f43e3bd5a037b427c2007c6e1cb680efdfa5abe808ac2b16b32604f2386e2
6
+ metadata.gz: 7302e71b8a4d550644cfa75e9b1afa90ed472ffa8f965aaeb50fe6088f695cb19d85aaa1b09cd911d740b303989b0a1351b6024b821f23a211798870f165c0a2
7
+ data.tar.gz: 52f4fb7f0f9a31174817253a380c327c77d9a94ba6fdf22aceb3e9b4590119f0ac88085ade5725a3169f41e01d9d032acadf4cf7157659130b41db09fdaee70c
@@ -130,12 +130,13 @@ module RMatrix
130
130
  end
131
131
 
132
132
  def mmap
133
+ return self.class.new(matrix, typecode) if shape.length == 0
133
134
  as_na = NArray.to_na(
134
135
  matrix.each.map do |elm|
135
136
  yield elm
136
137
  end
137
138
  ).to_type(typecode)
138
- Matrix.new(as_na.reshape(*shape), typecode)
139
+ self.class.new(as_na.reshape(*shape), typecode)
139
140
  end
140
141
 
141
142
  def mask
@@ -225,9 +226,9 @@ module RMatrix
225
226
  def join(other)
226
227
  case true
227
228
  when self.rows == 1 && other.rows == 1
228
- Vector.new(NArray.to_na([self.narray,other.narray]).to_type(self.typecode).reshape(self.columns + other.columns, 1))
229
+ self.class.new(NArray.to_na([self.narray,other.narray]).to_type(self.typecode).reshape(self.columns + other.columns, 1))
229
230
  when self.columns == 1 && other.columns == 1
230
- Vector.new(NArray.to_na([self.narray,other.narray]).to_type(self.typecode).reshape(1, self.rows + other.rows))
231
+ self.class.new(NArray.to_na([self.narray,other.narray]).to_type(self.typecode).reshape(1, self.rows + other.rows))
231
232
  else
232
233
  raise "Couldn't join mismatched dimensions"
233
234
  end
@@ -303,12 +304,12 @@ module RMatrix
303
304
  raise "Matrix A columns(#{self.columns}) != Matrix B rows(#{other.columns})" if other.rows != self.columns
304
305
  Matrix.new(self.matrix * other.matrix, typecode)
305
306
  else
306
- Matrix.new(apply_scalar(:*, other), typecode)
307
+ self.class.new(apply_scalar(:*, other), typecode)
307
308
  end
308
309
  end
309
310
 
310
311
  def mult(other)
311
- Matrix.new(self.narray * other.narray, typecode)
312
+ self.class.new(self.narray * other.narray, typecode)
312
313
  end
313
314
 
314
315
  def ==(other)
@@ -432,8 +433,8 @@ TEX
432
433
  def self.gen_vec_or_matrix_delegator(name)
433
434
  define_method(name) do |*args, &blk|
434
435
  case self
435
- when Matrix then Matrix.new(matrix.send(name, *args, &blk), typecode)
436
436
  when Vector then Vector.new(matrix.send(name, *args, &blk), typecode)
437
+ when Matrix then Matrix.new(matrix.send(name, *args, &blk), typecode)
437
438
  end
438
439
  end
439
440
  end
@@ -454,7 +455,7 @@ TEX
454
455
  end
455
456
 
456
457
  def to_type(type)
457
- Matrix.new(narray.to_type(type), type)
458
+ self.class.new(narray.to_type(type), type)
458
459
  end
459
460
 
460
461
  def self.gen_delegator(name)
@@ -496,7 +497,7 @@ TEX
496
497
  else
497
498
  apply_scalar(op, other)
498
499
  end
499
- Matrix.new(
500
+ self.class.new(
500
501
  result, typecode
501
502
  )
502
503
  end
@@ -1,25 +1,22 @@
1
1
  module RMatrix
2
2
  class Vector < RMatrix::Matrix
3
3
 
4
- def initialize(source, typecode=Typecode::FLOAT)
5
- if narray
6
- self.narray = narray
7
- self.matrix = NMatrix.refer(matrix)
8
- else
9
- super
4
+ def initialize(source, typecode=Typecode::FLOAT, column_map: nil, row_map: nil)
5
+ super
6
+ unless (shape.length == 2 && [rows, columns].include?(1)) || shape.length == 0
7
+ raise "Invalid dimensions #{shape.join(?x).reverse}. Vector must be eiter Nx1 or 1xM"
10
8
  end
11
- raise "Invalid dimensions #{shape.join(?x).reverse}. Vector must be eiter Nx1 or 1xM" unless [rows, columns].include?(1) && shape.length == 2
12
9
  end
13
10
 
14
- def self.[](*inputs)
11
+ def self.[](*inputs, typecode: Typecode::FLOAT, row_map: nil, column_map: nil, column_label_map: nil, row_label_map: nil)
15
12
  if inputs.length == 1 && [String, Symbol].include?(inputs[0].class)
16
13
  if ['byte', 'sint', 'int', 'sfloat', 'float', 'scomplex', 'complex', 'object'].include?(inputs[0].to_s)
17
- ->(*source){ Matrix.new(source, inputs[0].to_s) }
14
+ ->(*source){ V.new(source, inputs[0].to_s) }
18
15
  else
19
16
  Vector.new(inputs[0])
20
17
  end
21
18
  else
22
- Vector.new(inputs)
19
+ Vector.new(inputs, typecode, row_map: nil, column_map: nil)
23
20
  end
24
21
  end
25
22
 
@@ -1,3 +1,3 @@
1
1
  module RMatrix
2
- VERSION = "0.1.18"
2
+ VERSION = "0.1.19"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters