Class: NumRu::NVector

Inherits:
NArray
  • Object
show all
Defined in:
lib/numru/nmatrix.rb,
ext/numru/narray/na_linalg.c

Overview

—— NumRu::NVector ——

Constant Summary collapse

CLASS_DIMENSION =
1

Constants inherited from NArray

NumRu::NArray::BYTE, NumRu::NArray::COMPLEX, NumRu::NArray::DCOMPLEX, NumRu::NArray::DFLOAT, NumRu::NArray::ENDIAN, NumRu::NArray::FLOAT, NumRu::NArray::INT, NumRu::NArray::LINT, NumRu::NArray::LLINT, NumRu::NArray::NARRAY_VERSION, NumRu::NArray::NONE, NumRu::NArray::OBJECT, NumRu::NArray::ROBJ, NumRu::NArray::SCOMPLEX, NumRu::NArray::SFLOAT, NumRu::NArray::SINT, NumRu::NArray::SUPPORT_BIGMEM

Instance Method Summary collapse

Methods inherited from NArray

#%, #&, #-@, #<=>, #==, [], #[], #[]=, #^, #abs, #accum, #add!, #all?, #and, #angle, #any?, byte, cast, #ceil, #clone, #coerce, #collect, #collect!, complex, #complex?, #conj, #conj!, #count_false, #count_true, #cumprod, #cumprod!, #cumsum, #cumsum!, dcomplex, #delete_at, dfloat, div, #div!, #each, #element_size, #empty?, #eq, #eql?, #fill!, #flatten, #flatten!, float, #floor, #ge, #gt, #hash, #hton, #htov, #im, #imag, #imag=, #indgen!, #inspect, int, #integer?, #le, lint, llint, #lt, #mask, #max, #mean, #median, #min, #mod!, mul, #mul!, #mul_accum, #mul_add, mul_add, #ne, new, #newdim, #newdim!, #none?, #not, object, #or, #original, #prod, #random, #random!, #randomn, #randomn!, #rank, #rank_total, #real, #recip, ref, refer, #refer, #reshape, #reshape!, #reverse, #rms, #rmsdev, #rot90, #round, #sbt!, scomplex, sfloat, #shape, sint, #size, #slice, #sort, #sort!, #sort_index, srand, #stddev, #sum, #swap_byte, #to_a, #to_binary, #to_f, #to_i, to_na, to_narray, #to_s, #to_s_refer, #to_string, #to_type, #to_type_as_binary, #transpose, #typecode, #where, #where2, #xor, #|, #~

Instance Method Details

#*(other) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/numru/nmatrix.rb', line 188

def *(other)
  case other
  when NumRu::NMatrix
    NumRu::NVector.mul_add( NumRu::NArray.refer(self).newdim!(0), other, 1 )
  when NumRu::NVector
    NumRu::NArray.mul_add( NumRu::NArray.refer(self), other, 0 ) # inner product
  when NumRu::NArray
    if other.instance_of?(NumRu::NArray)
	NumRu::NVector.mul( NumRu::NArray.refer(self), other.newdim(0) )
    else
	other.coerce_rev( self, :* )
    end
  when Numeric
    NumRu::NVector.mul( NumRu::NArray.refer(self), other )
  else
    raise TypeError,"Illegal operation: NumRu::NVector * %s" % other.class
  end
end

#**(n) ⇒ Object



226
227
228
229
230
231
232
# File 'lib/numru/nmatrix.rb', line 226

def **(n)
  if n==2
    self*self
  else
    raise ArgumentError,"Only v**2 is implemented"
  end
end

#+(other) ⇒ Object

Raises:

  • (TypeError)


164
165
166
167
168
169
170
171
172
173
174
# File 'lib/numru/nmatrix.rb', line 164

def +(other)
  case other
  when NumRu::NVector
    return super(NumRu::NArray.refer(other))
  when NumRu::NArray
    unless other.instance_of?(NumRu::NArray)
      return other.coerce_rev( self, :+ )
    end
  end
  raise TypeError,"Illegal operation: NumRu::NVector + %s" % other.class
end

#-(other) ⇒ Object

Raises:

  • (TypeError)


176
177
178
179
180
181
182
183
184
185
186
# File 'lib/numru/nmatrix.rb', line 176

def -(other)
  case other
  when NumRu::NVector
    return super(NumRu::NArray.refer(other))
  when NumRu::NArray
    unless other.instance_of?(NumRu::NArray)
      return other.coerce_rev( self, :- )
    end
  end
  raise TypeError,"Illegal operation: NumRu::NVector - %s" % other.class
end

#/(other) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/numru/nmatrix.rb', line 207

def /(other)
  case other
  when NumRu::NMatrix
    other.lu.solve(self)
  when NumRu::NVector
    raise TypeError,"Illegal operation: NumRu::NVector / %s" % other.class
  when NumRu::NArray
    if other.instance_of?(NumRu::NArray)
	NumRu::NVector.div( NumRu::NArray.refer(self), other.newdim(0) )
    else
	other.coerce_rev( self, :/ )
    end
  when Numeric
    NumRu::NVector.div( NumRu::NArray.refer(self), other )
  else
    raise TypeError,"Illegal operation: NumRu::NVector / %s" % other.class
  end
end

#coerce_rev(other, id) ⇒ Object

Raises:

  • (TypeError)


234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/numru/nmatrix.rb', line 234

def coerce_rev(other,id)
  case id
  when :*
	if other.instance_of?(NumRu::NArray)
 return NumRu::NVector.mul( other.newdim(0), self )
	end
	if other.instance_of?(NumRu::NArrayScalar)
 return NumRu::NVector.mul( other, self )
	end
  end
  raise TypeError,"Illegal operation: %s %s NumRu::NVector" %
    [other.class, id.id2name]
end