SparseMatrixProject 0.0.1
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/.gitignore +17 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +15 -0
- data/SparseMatrixProject.gemspec +23 -0
- data/bin/SparseMatrixProject +3 -0
- data/lib/SparseMatrixProject/version.rb +3 -0
- data/lib/SparseMatrixProject.rb +340 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in SparseMatrixProject.gemspec
|
4
|
+
gem 'nokogiri'
|
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'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jacobo Saavedra
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# SparseMatrixProject
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'SparseMatrixProject'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install SparseMatrixProject
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__) + 'lib'
|
4
|
+
$:.unshift './lib', './spec'
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
desc "Run UniTest Matrices"
|
11
|
+
task :test do
|
12
|
+
sh "ruby -Ilib -Itest test/tc_Matrices.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'SparseMatrixProject/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
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 y resta entre matrices densas y dispersas}
|
12
|
+
spec.summary = %q{Matrices dispersas y densas}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = ""
|
15
|
+
|
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
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,340 @@
|
|
1
|
+
require "SparseMatrixProject/version"
|
2
|
+
require "racional.rb"
|
3
|
+
|
4
|
+
module SparseMatrixProject
|
5
|
+
class Matrices
|
6
|
+
include Comparable
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
attr_accessor :filas, :columnas, :matriz
|
10
|
+
|
11
|
+
def initialize(f, c)
|
12
|
+
#atributo
|
13
|
+
@filas=f.to_i; #Numero de filas
|
14
|
+
@columnas=c.to_i; #Numero de columnas
|
15
|
+
end
|
16
|
+
|
17
|
+
#################################################
|
18
|
+
def +(other)
|
19
|
+
if(self.filas == other.filas and self.columnas == other.columnas)
|
20
|
+
# SELF Matrices densas
|
21
|
+
if self.instance_of?Densa
|
22
|
+
temp = Densa.new(self.filas, self.columnas, nil)
|
23
|
+
if other.instance_of?Densa
|
24
|
+
|
25
|
+
for i in (0...@filas.to_i)
|
26
|
+
for j in (0...@columnas.to_i)
|
27
|
+
temp.matriz[i][j] = (self.matriz[i][j]) + (other.matriz[i][j])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if other.instance_of?Dispersa
|
33
|
+
for i in (0...@filas.to_i)
|
34
|
+
for j in (0...@columnas.to_i)
|
35
|
+
encontrado = 0
|
36
|
+
for k in (0...other.posx.size)
|
37
|
+
if (i==other.posx[k] and j==other.posy[k] and encontrado==0)
|
38
|
+
temp.matriz[i][j] = (self.matriz[i][j]) + (other.valor[k])
|
39
|
+
encontrado = 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
if (encontrado == 0)
|
43
|
+
temp.matriz[i][j] = self.matriz[i][j]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# SELF Matriz Dispersa
|
51
|
+
if self.instance_of?Dispersa
|
52
|
+
if other.instance_of?Densa
|
53
|
+
temp = Densa.new(self.filas, self.columnas, nil)
|
54
|
+
for i in (0...@filas.to_i)
|
55
|
+
for j in (0...@columnas.to_i)
|
56
|
+
encontrado = 0
|
57
|
+
for k in (0...self.posx.size.to_i)
|
58
|
+
if (i==self.posx[k] and j==self.posy[k] and encontrado==0)
|
59
|
+
temp.matriz[i][j] = (other.matriz[i][j]) + (self.valor[k])
|
60
|
+
encontrado = 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
if (encontrado == 0)
|
64
|
+
temp.matriz[i][j] = other.matriz[i][j]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
if other.instance_of?Dispersa
|
72
|
+
temp = Dispersa.new(self.filas,self.columnas,[],[],[])
|
73
|
+
temp.valor = self.valor
|
74
|
+
temp.posx = self.posx
|
75
|
+
temp.posy = self.posy
|
76
|
+
|
77
|
+
for j in (0...other.posx.size.to_i)
|
78
|
+
encontrado = false
|
79
|
+
for k in (0...self.posx.size.to_i)
|
80
|
+
if(other.posx[j] == temp.posx[k] and other.posy[j] == temp.posy[k])
|
81
|
+
temp.valor[k] = temp.valor[k] + other.valor[j]
|
82
|
+
encontrado = true
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
if (encontrado == false)
|
87
|
+
temp.posx << other.posx[j]
|
88
|
+
temp.posy << other.posy[j]
|
89
|
+
temp.valor << other.valor[j]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
return temp
|
96
|
+
else
|
97
|
+
return nil
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
##############################################################################
|
102
|
+
|
103
|
+
##############################RESTA###########################################
|
104
|
+
|
105
|
+
def -(other)
|
106
|
+
if(self.filas == other.filas and self.columnas == other.columnas)
|
107
|
+
# SELF Matrices densas
|
108
|
+
if self.instance_of?Densa
|
109
|
+
temp = Densa.new(self.filas, self.columnas, nil)
|
110
|
+
if other.instance_of?Densa
|
111
|
+
for i in (0...@filas.to_i)
|
112
|
+
for j in (0...@columnas.to_i)
|
113
|
+
temp.matriz[i][j] = (self.matriz[i][j]) - (other.matriz[i][j])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
if other.instance_of?Dispersa
|
119
|
+
for i in (0...@filas.to_i)
|
120
|
+
for j in (0...@columnas.to_i)
|
121
|
+
encontrado = 0
|
122
|
+
for k in (0...other.posx.size)
|
123
|
+
if (i==other.posx[k] and j==other.posy[k] and encontrado==0)
|
124
|
+
temp.matriz[i][j] = (self.matriz[i][j]) - (other.valor[k])
|
125
|
+
encontrado = 1
|
126
|
+
end
|
127
|
+
end
|
128
|
+
if (encontrado == 0)
|
129
|
+
temp.matriz[i][j] = self.matriz[i][j]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# SELF Matriz Dispersa
|
137
|
+
if self.instance_of?Dispersa
|
138
|
+
if other.instance_of?Densa
|
139
|
+
temp = Densa.new(self.filas, self.columnas, nil)
|
140
|
+
for i in (0...@filas.to_i)
|
141
|
+
for j in (0...@columnas.to_i)
|
142
|
+
encontrado = 0
|
143
|
+
for k in (0...self.posx.size.to_i)
|
144
|
+
if (i==self.posx[k] and j==self.posy[k] and encontrado==0)
|
145
|
+
temp.matriz[i][j] = (other.matriz[i][j]) - (self.valor[k])
|
146
|
+
encontrado = 1
|
147
|
+
end
|
148
|
+
end
|
149
|
+
if (encontrado == 0)
|
150
|
+
temp.matriz[i][j] = other.matriz[i][j]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
if other.instance_of?Dispersa
|
158
|
+
temp = Dispersa.new(self.filas,self.columnas,[],[],[])
|
159
|
+
temp.valor = self.valor
|
160
|
+
temp.posx = self.posx
|
161
|
+
temp.posy = self.posy
|
162
|
+
|
163
|
+
for j in (0...other.posx.size.to_i)
|
164
|
+
encontrado = false
|
165
|
+
for k in (0...self.posx.size.to_i)
|
166
|
+
if(other.posx[j] == temp.posx[k] and other.posy[j] == temp.posy[k])
|
167
|
+
temp.valor[k] = temp.valor[k] - other.valor[j]
|
168
|
+
encontrado = true
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
if (encontrado == false)
|
173
|
+
temp.posx << other.posx[j]
|
174
|
+
temp.posy << other.posy[j]
|
175
|
+
temp.valor << other.valor[j]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
return temp
|
182
|
+
else
|
183
|
+
return nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
class Dispersa < Matrices
|
192
|
+
attr_accessor :posx, :posy, :valor
|
193
|
+
def initialize(f,c,posx, posy, valor)
|
194
|
+
super(f,c)
|
195
|
+
@posx = posx
|
196
|
+
@posy = posy
|
197
|
+
@valor = valor
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
def to_s
|
202
|
+
s=String.new
|
203
|
+
s << "["
|
204
|
+
for i in (0...@filas.to_i)
|
205
|
+
s << "[#{posx[i]},#{posy[i]},#{valor[i]}]"
|
206
|
+
end
|
207
|
+
s << "]"
|
208
|
+
end
|
209
|
+
|
210
|
+
def max
|
211
|
+
m = self.valor[0]
|
212
|
+
for i in (0...self.valor.size.to_i)
|
213
|
+
if (self.valor[i]> m)
|
214
|
+
m = self.valor[i]
|
215
|
+
end
|
216
|
+
end
|
217
|
+
return m
|
218
|
+
end
|
219
|
+
|
220
|
+
def min
|
221
|
+
m = self.valor[0]
|
222
|
+
for i in (0...self.valor.size.to_i)
|
223
|
+
if (self.valor[i]< m)
|
224
|
+
m = self.valor[i]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
return m
|
228
|
+
end
|
229
|
+
|
230
|
+
def pos(a,b)
|
231
|
+
for i in (0...self.posx.size)
|
232
|
+
if(posx[i]==a and posy[i]==b)
|
233
|
+
return valor[i]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
return nil
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
class Densa < Matrices
|
243
|
+
attr_accessor :matriz
|
244
|
+
|
245
|
+
def initialize(f,c,m)
|
246
|
+
super(f,c)
|
247
|
+
@matriz = Array.new(@filas.to_i){Array.new(@columnas.to_i)}
|
248
|
+
|
249
|
+
if (m != nil)
|
250
|
+
#Rellenamos la matriz con lo valores recibidos
|
251
|
+
for i in (0...@filas.to_i)
|
252
|
+
for j in (0...@columnas.to_i)
|
253
|
+
@matriz[i][j]=m[i*@columnas.to_i+j];
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
# Metodos getter devuelve el valor de una posicion determinada
|
259
|
+
|
260
|
+
def pos(a,b)
|
261
|
+
@matriz[a][b]
|
262
|
+
end
|
263
|
+
|
264
|
+
#Metodo que devuelve la matriz en forma de string
|
265
|
+
def to_s
|
266
|
+
"#{@matriz}"
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
####Traspuesta de una matriz
|
272
|
+
def traspuesta
|
273
|
+
i=0
|
274
|
+
mtrasp = Array.new(@filas) {Array.new(self.columnas)}
|
275
|
+
while i < @filas
|
276
|
+
j=0
|
277
|
+
while j < @columnas
|
278
|
+
mtrasp[i][j] = self.matriz[j][i]
|
279
|
+
j+=1
|
280
|
+
end
|
281
|
+
i+=1
|
282
|
+
end
|
283
|
+
Matrices.new(mtrasp)
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
####Opuesta de una matriz
|
288
|
+
def opuesta
|
289
|
+
|
290
|
+
i=0
|
291
|
+
mop = Array.new(@filas) {Array.new(self.columnas)}
|
292
|
+
while i < @filas
|
293
|
+
j=0
|
294
|
+
while j < @columnas
|
295
|
+
mop[i][j] = (self.matriz[i][j]) * (- 1)
|
296
|
+
j+=1
|
297
|
+
end
|
298
|
+
i+=1
|
299
|
+
end
|
300
|
+
Matrices.new(mop)
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
############Método Mínimo######################################
|
305
|
+
def minimo
|
306
|
+
|
307
|
+
min = self.matriz[0][0]
|
308
|
+
i=0
|
309
|
+
while i < @filas
|
310
|
+
j=0
|
311
|
+
while j < @columnas
|
312
|
+
if(self.matriz[i][j] < min)
|
313
|
+
min = self.matriz[i][j]
|
314
|
+
end
|
315
|
+
j+= 1
|
316
|
+
end
|
317
|
+
i+= 1
|
318
|
+
end
|
319
|
+
return min
|
320
|
+
end
|
321
|
+
|
322
|
+
##############Método Máximo######################################
|
323
|
+
def maximo
|
324
|
+
|
325
|
+
max = self.matriz[0][0]
|
326
|
+
i = 0
|
327
|
+
while i < @filas
|
328
|
+
j = 0
|
329
|
+
while j < @columnas
|
330
|
+
if(self.matriz[i][j] > max)
|
331
|
+
max = self.matriz[i][j]
|
332
|
+
end
|
333
|
+
j+= 1
|
334
|
+
end
|
335
|
+
i+= 1
|
336
|
+
end
|
337
|
+
return max
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SparseMatrixProject
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jacobo Saavedra Valdes
|
9
|
+
- Aaron Jose Vera Cerdeña
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-11-22 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.3'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.3'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Gema para realizar suma y resta entre matrices densas y dispersas
|
48
|
+
email:
|
49
|
+
- alu0100658682@ull.edu.es
|
50
|
+
- alu0100537451@ull.edu.es
|
51
|
+
executables:
|
52
|
+
- SparseMatrixProject
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- SparseMatrixProject.gemspec
|
62
|
+
- bin/SparseMatrixProject
|
63
|
+
- lib/SparseMatrixProject.rb
|
64
|
+
- lib/SparseMatrixProject/version.rb
|
65
|
+
homepage: ''
|
66
|
+
licenses:
|
67
|
+
- ''
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.25
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Matrices dispersas y densas
|
90
|
+
test_files: []
|