Class: NMatrix
- Inherits:
-
Object
- Object
- NMatrix
- Defined in:
- lib/narray_extext.rb
Class Method Summary collapse
- .array2typecode(ary) ⇒ Object
- .diagonal(a, shape = [a.size, a.size], typecode = nil) ⇒ Object
- .I(n, typecode = NArray::DFLOAT) ⇒ Object
Instance Method Summary collapse
- #adjoint ⇒ Object
- #as_vector ⇒ Object
- #column_vector(i) ⇒ Object
- #column_vectors ⇒ Object
- #row_vector(i) ⇒ Object
- #row_vectors ⇒ Object
Class Method Details
.array2typecode(ary) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/narray_extext.rb', line 83 def self.array2typecode(ary) if ary.kind_of?(NArray) ary.typecode else case ary[0] when Float then NArray::DFLOAT when Integer then NArray::INT when Complex then NArray::DCOMPLEX else NArray::OBJECT end end end |
.diagonal(a, shape = [a.size, a.size], typecode = nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/narray_extext.rb', line 74 def self.diagonal(a, shape=[a.size, a.size], typecode=nil) typecode ||= array2typecode(a) m = NMatrix.new(typecode, *shape) a = a.refer if a.kind_of?(NArray) m.diagonal!(a) m end |
.I(n, typecode = NArray::DFLOAT) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/narray_extext.rb', line 96 def self.I(n, typecode=NArray::DFLOAT) m = NMatrix.new(typecode, n, n) m.I m end |
Instance Method Details
#adjoint ⇒ Object
59 60 61 62 |
# File 'lib/narray_extext.rb', line 59 def adjoint ret = self.transpose; ret.conj! ret end |
#as_vector ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/narray_extext.rb', line 64 def as_vector if rank != 2 || (shape[0] != 1 && shape[1] != 1) raise(ArgumentError, "NMatrix#as_vector: the matrix should be column matrix" + "or row matrix") end NVector.ref(flatten) end |
#column_vector(i) ⇒ Object
50 51 52 |
# File 'lib/narray_extext.rb', line 50 def column_vector(i) NVector.ref(NArray.ref(self)[i, false]) end |
#column_vectors ⇒ Object
54 55 56 57 |
# File 'lib/narray_extext.rb', line 54 def column_vectors d = self.shape[0] (0 ... d).map{|i| column_vector(i) } end |
#row_vector(i) ⇒ Object
41 42 43 |
# File 'lib/narray_extext.rb', line 41 def row_vector(i) NVector.ref(NArray.ref(self)[true, i, false]) end |
#row_vectors ⇒ Object
45 46 47 48 |
# File 'lib/narray_extext.rb', line 45 def row_vectors d = self.shape[1] (0 ... d).map{|i| row_vector(i) } end |