Class: Mgmg::Vec

Inherits:
Array
  • Object
show all
Defined in:
lib/mgmg/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.irange(size) ⇒ Object



337
338
339
# File 'lib/mgmg/utils.rb', line 337

def self.irange(size)
	Vec.new(size, &:itself)
end

Instance Method Details

#[]=(*arg) ⇒ Object



340
341
342
343
344
345
346
347
348
# File 'lib/mgmg/utils.rb', line 340

def []=(*arg)
	case arg.size
	when 1
		self.replace(arg[0])
		arg[0]
	else
		super
	end
end

#add!(other) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/mgmg/utils.rb', line 285

def add!(other)
	case other
	when Array
		self.map!.with_index do |e, i|
			e + other[i]
		end
	else
		self.map! do |e|
			e + other
		end
	end
	self
end

#e_div!(other) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/mgmg/utils.rb', line 324

def e_div!(other)
	case other
	when Array
		self.map!.with_index do |e, i|
			e.cdiv(other[i])
		end
	else
		self.map! do |e|
			e.cdiv(other)
		end
	end
	self
end

#e_mul!(other) ⇒ Object



311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/mgmg/utils.rb', line 311

def e_mul!(other)
	case other
	when Array
		self.map!.with_index do |e, i|
			e * other[i]
		end
	else
		self.map! do |e|
			e * other
		end
	end
	self
end

#sub!(other) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/mgmg/utils.rb', line 298

def sub!(other)
	case other
	when Array
		self.map!.with_index do |e, i|
			e - other[i]
		end
	else
		self.map! do |e|
			e - other
		end
	end
	self
end