Class: Dispersa

Inherits:
Matriz show all
Defined in:
lib/p10lppt13.rb

Overview

Clase de Matrices Dispersas

Instance Attribute Summary collapse

Attributes inherited from Matriz

#ncol, #nfil

Instance Method Summary collapse

Methods inherited from Matriz

#*, #+, #-, #colum, #filas, #max, #min, #por, #porf, #primervalor, #to_s, #trasponer, #vectorizar

Constructor Details

#initialize(nfil, ncol, h = {}) ⇒ Dispersa

Returns a new instance of Dispersa.



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/p10lppt13.rb', line 251

def initialize(nfil, ncol, h = {})
	super(nfil, ncol)
	@pos = Hash.new({})
	for k in h.keys do 
	@pos[k] = if h[k].is_a? VectorDisperso
					h[k]
				 else 
					@pos[k] = VectorDisperso.new(h[k])
                    end
	end
end

Instance Attribute Details

#posObject (readonly)

Returns the value of attribute pos.



249
250
251
# File 'lib/p10lppt13.rb', line 249

def pos
  @pos
end

Instance Method Details

#[](i) ⇒ Object

for i in self.pos.keys do



265
266
267
# File 'lib/p10lppt13.rb', line 265

def [](i)
	@pos[i]
end

#col(j) ⇒ Object



269
270
271
272
273
274
275
# File 'lib/p10lppt13.rb', line 269

def col(j)
	c = {}
	for r in @pos.keys do
		c[r] = @pos[r].vector[j] if @pos[r].vector.keys.include? j
	end
	VectorDisperso.new c
end