SparseMatrixProject 0.0.1 → 0.0.2
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.
- data/Gemfile +1 -10
- data/Rakefile +0 -1
- data/SparseMatrixProject.gemspec +12 -12
- data/lib/SparseMatrixProject/version.rb +1 -1
- data/lib/SparseMatrixProject.rb +172 -38
- metadata +4 -6
- data/bin/SparseMatrixProject +0 -3
data/Gemfile
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in SparseMatrixProject.gemspec
|
4
|
-
|
5
|
-
gem 'rack', '~>1.1'
|
6
|
-
gem 'rspec', :require => 'spec'
|
7
|
-
|
8
|
-
gem 'rake'
|
9
|
-
gem 'rspec'
|
10
|
-
gem 'guard'
|
11
|
-
gem 'guard-rspec'
|
12
|
-
gem 'guard-bundler'
|
13
|
-
gem 'guard-gitpusher'
|
4
|
+
gemspec
|
data/Rakefile
CHANGED
data/SparseMatrixProject.gemspec
CHANGED
@@ -4,20 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'SparseMatrixProject/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.description
|
12
|
-
spec.summary
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
7
|
+
spec.name = "SparseMatrixProject"
|
8
|
+
spec.version = SparseMatrixProject::VERSION
|
9
|
+
spec.authors = ["Jacobo Saavedra Valdes", "Aaron Jose Vera Cerdeña"]
|
10
|
+
spec.email = ["alu0100658682@ull.edu.es", "alu0100537451@ull.edu.es"]
|
11
|
+
spec.description = %q{Gema para realizar suma, resta y producto entre matrices densas y dispersas}
|
12
|
+
spec.summary = %q{Matrices dispersas y densas}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = ""
|
15
15
|
|
16
|
-
spec.files
|
17
|
-
spec.executables
|
18
|
-
spec.test_files
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
end
|
23
|
+
end
|
data/lib/SparseMatrixProject.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "SparseMatrixProject/version"
|
2
|
-
require "racional.rb"
|
3
2
|
|
4
3
|
module SparseMatrixProject
|
5
4
|
class Matrices
|
@@ -8,30 +7,37 @@ class Matrices
|
|
8
7
|
|
9
8
|
attr_accessor :filas, :columnas, :matriz
|
10
9
|
|
11
|
-
def initialize(f, c)
|
10
|
+
def initialize(f, c)#Crea la matriz con las dimensiones especificadas
|
12
11
|
#atributo
|
13
12
|
@filas=f.to_i; #Numero de filas
|
14
13
|
@columnas=c.to_i; #Numero de columnas
|
15
14
|
end
|
16
15
|
|
17
|
-
|
18
|
-
def +(other)
|
16
|
+
|
17
|
+
def +(other)#Método suma para matrices densas y dispersas
|
19
18
|
if(self.filas == other.filas and self.columnas == other.columnas)
|
20
19
|
# SELF Matrices densas
|
21
20
|
if self.instance_of?Densa
|
22
21
|
temp = Densa.new(self.filas, self.columnas, nil)
|
23
22
|
if other.instance_of?Densa
|
24
23
|
|
25
|
-
for i in (0...@filas.to_i)
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
0.upto(@filas-1) do |i| #for i in (0...@filas.to_i)
|
25
|
+
##0.upto(@columnas-1) do |j| #for j in (0...@columnas.to_i)
|
26
|
+
j=0
|
27
|
+
(0..(@columnas-1)).collect {
|
28
|
+
temp.matriz[i][j] = (self.matriz[i][j]) + (other.matriz[i][j])
|
29
|
+
j+=1;
|
30
|
+
##end
|
31
|
+
}
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
35
|
if other.instance_of?Dispersa
|
33
|
-
|
34
|
-
|
36
|
+
|
37
|
+
0.upto(@filas-1) do |i| ## for i in (0...@filas.to_i)
|
38
|
+
|
39
|
+
j=0
|
40
|
+
(0..(@columnas-1)).collect { ##for j in (0...@columnas.to_i)
|
35
41
|
encontrado = 0
|
36
42
|
for k in (0...other.posx.size)
|
37
43
|
if (i==other.posx[k] and j==other.posy[k] and encontrado==0)
|
@@ -42,7 +48,9 @@ class Matrices
|
|
42
48
|
if (encontrado == 0)
|
43
49
|
temp.matriz[i][j] = self.matriz[i][j]
|
44
50
|
end
|
45
|
-
|
51
|
+
j+= 1
|
52
|
+
}
|
53
|
+
##end
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
@@ -51,8 +59,8 @@ class Matrices
|
|
51
59
|
if self.instance_of?Dispersa
|
52
60
|
if other.instance_of?Densa
|
53
61
|
temp = Densa.new(self.filas, self.columnas, nil)
|
54
|
-
for i in (0...@filas.to_i)
|
55
|
-
for j in (0...@columnas.to_i)
|
62
|
+
0.upto(@filas-1) do |i| ##for i in (0...@filas.to_i)
|
63
|
+
0.upto(@columnas-1) do |j|##for j in (0...@columnas.to_i)
|
56
64
|
encontrado = 0
|
57
65
|
for k in (0...self.posx.size.to_i)
|
58
66
|
if (i==self.posx[k] and j==self.posy[k] and encontrado==0)
|
@@ -95,14 +103,131 @@ class Matrices
|
|
95
103
|
return temp
|
96
104
|
else
|
97
105
|
return nil
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def *(other) #Método producto para matrices densas y dispersas
|
111
|
+
temp=Densa.new(self.filas,other.columnas,nil)
|
112
|
+
|
113
|
+
|
114
|
+
# SELF Matrices densas
|
115
|
+
if self.instance_of?Densa
|
116
|
+
if other.instance_of?Densa
|
117
|
+
###########################DENSA*DENSA#####################################
|
118
|
+
self.filas.times do |i|
|
119
|
+
other.columnas.times do |j|
|
120
|
+
temp.matriz[i][j]=0
|
121
|
+
other.columnas.times do |k|
|
122
|
+
temp.matriz[i][j] = temp.matriz[i][j] + (self.matriz[i][k] * other.matriz[k][j])
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
if other.instance_of?Dispersa
|
128
|
+
disptodens = Densa.new(self.filas,other.columnas,[0,0,0,0,0,0,0,0,0])
|
129
|
+
|
130
|
+
@filas.times do |i|
|
131
|
+
@columnas.times do |j|
|
132
|
+
encontrado = 0
|
133
|
+
0.upto(other.posx.size) do |k|
|
134
|
+
if (i==other.posx[k] and j==other.posy[k] and encontrado==0)
|
135
|
+
disptodens.matriz[i][j] = other.valor[k]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
#puts disptodens.to_s
|
141
|
+
|
142
|
+
self.filas.times do |i|
|
143
|
+
disptodens.columnas.times do |j|
|
144
|
+
temp.matriz[i][j]=0
|
145
|
+
disptodens.columnas.times do |k|
|
146
|
+
temp.matriz[i][j] = temp.matriz[i][j] + (self.matriz[i][k] * disptodens.matriz[k][j])
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
if self.instance_of?Dispersa
|
155
|
+
if other.instance_of?Dispersa
|
156
|
+
###########################DISPERSA*DISPERSA#####################################
|
157
|
+
##1 dispersa a densa
|
158
|
+
disptodens = Densa.new(self.filas,other.columnas,[0,0,0,0,0,0,0,0,0])
|
159
|
+
@filas.times do |i|
|
160
|
+
@columnas.times do |j|
|
161
|
+
encontrado = 0
|
162
|
+
0.upto(other.posx.size) do |k|
|
163
|
+
if (i==other.posx[k] and j==other.posy[k] and encontrado==0)
|
164
|
+
disptodens.matriz[i][j] = other.valor[k]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
##2 dispersa a densa
|
171
|
+
disptodens2 = Densa.new(other.filas,self.columnas,[0,0,0,0,0,0,0,0,0])
|
172
|
+
@filas.times do |i|
|
173
|
+
@columnas.times do |j|
|
174
|
+
encontrado = 0
|
175
|
+
0.upto(self.posx.size) do |k|
|
176
|
+
if (i==self.posx[k] and j==self.posy[k] and encontrado==0)
|
177
|
+
disptodens2.matriz[i][j] = self.valor[k]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
temp=Densa.new(self.filas, self.columnas,[0,0,0,0,0,0,0,0,0])
|
185
|
+
puts disptodens.to_s####################################################################
|
186
|
+
puts disptodens2.to_s###################################################################
|
187
|
+
disptodens.filas.times do |i|
|
188
|
+
disptodens2.columnas.times do |j|
|
189
|
+
temp.matriz[i][j]=0
|
190
|
+
disptodens2.columnas.times do |k|
|
191
|
+
temp.matriz[i][j] = temp.matriz[i][j] + (disptodens2.matriz[i][k] * disptodens.matriz[k][j])
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
if other.instance_of?Densa
|
198
|
+
###########################DISPERSA*DENSA#####################################
|
199
|
+
disptodens = Densa.new(other.filas,self.columnas,[0,0,0,0,0,0,0,0,0])
|
200
|
+
@filas.times do |i|
|
201
|
+
@columnas.times do |j|
|
202
|
+
encontrado = 0
|
203
|
+
0.upto(self.posx.size) do |k|
|
204
|
+
if (i==self.posx[k] and j==self.posy[k] and encontrado==0)
|
205
|
+
disptodens.matriz[i][j] = self.valor[k]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
#puts disptodens.to_s
|
212
|
+
|
213
|
+
#puts other.to_s
|
214
|
+
|
215
|
+
temp=Densa.new(self.filas, self.columnas,[0,0,0,0,0,0,0,0,0])
|
216
|
+
other.filas.times do |i|
|
217
|
+
other.columnas.times do |j|
|
218
|
+
disptodens.columnas.times do |k|
|
219
|
+
temp.matriz[i][j] = temp.matriz[i][j] + (disptodens.matriz[i][k] * other.matriz[k][j])
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
temp
|
226
|
+
end
|
102
227
|
|
103
228
|
##############################RESTA###########################################
|
104
229
|
|
105
|
-
def -(other)
|
230
|
+
def -(other) #Resta de matrices Densas y Dispersas##
|
106
231
|
if(self.filas == other.filas and self.columnas == other.columnas)
|
107
232
|
# SELF Matrices densas
|
108
233
|
if self.instance_of?Densa
|
@@ -186,8 +311,15 @@ def -(other)
|
|
186
311
|
|
187
312
|
end
|
188
313
|
|
189
|
-
|
190
|
-
|
314
|
+
# === Clase Dispersa
|
315
|
+
#
|
316
|
+
# Definición de la clase _Dispersa_ compuesta por
|
317
|
+
# * metodo initialize
|
318
|
+
# * metodo to_s(other)
|
319
|
+
# * metodo max(other)
|
320
|
+
# * metodo min(other)
|
321
|
+
# * método pos
|
322
|
+
#
|
191
323
|
class Dispersa < Matrices
|
192
324
|
attr_accessor :posx, :posy, :valor
|
193
325
|
def initialize(f,c,posx, posy, valor)
|
@@ -237,12 +369,19 @@ attr_accessor :posx, :posy, :valor
|
|
237
369
|
end
|
238
370
|
|
239
371
|
end
|
240
|
-
|
241
|
-
|
372
|
+
# === Clase Densa
|
373
|
+
#
|
374
|
+
# Definición de la clase _Matrices_ compuesta por
|
375
|
+
# * metodo initialize
|
376
|
+
# * metodo pos(a,b)
|
377
|
+
# * metodo to_s
|
378
|
+
# * metodo max
|
379
|
+
# * metodo min
|
380
|
+
#
|
242
381
|
class Densa < Matrices
|
243
382
|
attr_accessor :matriz
|
244
383
|
|
245
|
-
def initialize(f,c,m)
|
384
|
+
def initialize(f,c,m)#Estructura de datos de la matriz densa
|
246
385
|
super(f,c)
|
247
386
|
@matriz = Array.new(@filas.to_i){Array.new(@columnas.to_i)}
|
248
387
|
|
@@ -255,21 +394,19 @@ def initialize(f,c,m)
|
|
255
394
|
end
|
256
395
|
end
|
257
396
|
end
|
258
|
-
|
397
|
+
|
259
398
|
|
260
|
-
def pos(a,b)
|
399
|
+
def pos(a,b)# Metodos getter devuelve el valor de una posicion determinada
|
261
400
|
@matriz[a][b]
|
262
401
|
end
|
263
402
|
|
264
|
-
|
265
|
-
def to_s
|
403
|
+
|
404
|
+
def to_s#Metodo que devuelve la matriz en forma de string
|
266
405
|
"#{@matriz}"
|
267
406
|
end
|
268
407
|
|
269
408
|
|
270
|
-
|
271
|
-
####Traspuesta de una matriz
|
272
|
-
def traspuesta
|
409
|
+
def traspuesta#Método que calcula la traspuesta de una matriz
|
273
410
|
i=0
|
274
411
|
mtrasp = Array.new(@filas) {Array.new(self.columnas)}
|
275
412
|
while i < @filas
|
@@ -284,8 +421,8 @@ def initialize(f,c,m)
|
|
284
421
|
end
|
285
422
|
|
286
423
|
|
287
|
-
|
288
|
-
def opuesta
|
424
|
+
|
425
|
+
def opuesta#Método que calcula el opuesto de una matriz
|
289
426
|
|
290
427
|
i=0
|
291
428
|
mop = Array.new(@filas) {Array.new(self.columnas)}
|
@@ -301,8 +438,7 @@ def initialize(f,c,m)
|
|
301
438
|
|
302
439
|
end
|
303
440
|
|
304
|
-
|
305
|
-
def minimo
|
441
|
+
def minimo#Método que devuelve el elemento menor de la matriz
|
306
442
|
|
307
443
|
min = self.matriz[0][0]
|
308
444
|
i=0
|
@@ -319,8 +455,7 @@ def initialize(f,c,m)
|
|
319
455
|
return min
|
320
456
|
end
|
321
457
|
|
322
|
-
|
323
|
-
def maximo
|
458
|
+
def maximo#Método que devuelve el elemento mayor de la matriz
|
324
459
|
|
325
460
|
max = self.matriz[0][0]
|
326
461
|
i = 0
|
@@ -336,5 +471,4 @@ def initialize(f,c,m)
|
|
336
471
|
end
|
337
472
|
return max
|
338
473
|
end
|
339
|
-
|
340
|
-
end
|
474
|
+
endend
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SparseMatrixProject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-11-
|
13
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -44,12 +44,11 @@ dependencies:
|
|
44
44
|
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
-
description: Gema para realizar suma y
|
47
|
+
description: Gema para realizar suma, resta y producto entre matrices densas y dispersas
|
48
48
|
email:
|
49
49
|
- alu0100658682@ull.edu.es
|
50
50
|
- alu0100537451@ull.edu.es
|
51
|
-
executables:
|
52
|
-
- SparseMatrixProject
|
51
|
+
executables: []
|
53
52
|
extensions: []
|
54
53
|
extra_rdoc_files: []
|
55
54
|
files:
|
@@ -59,7 +58,6 @@ files:
|
|
59
58
|
- README.md
|
60
59
|
- Rakefile
|
61
60
|
- SparseMatrixProject.gemspec
|
62
|
-
- bin/SparseMatrixProject
|
63
61
|
- lib/SparseMatrixProject.rb
|
64
62
|
- lib/SparseMatrixProject/version.rb
|
65
63
|
homepage: ''
|
data/bin/SparseMatrixProject
DELETED