sparse_matrix 0.3.1 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d3bb6f0f82c1dac4b679ee0ecc93f2a45c9f556
4
- data.tar.gz: fa6fd2a910191e1a4f7ca60989e586b0303e41ce
3
+ metadata.gz: 4120f3a75b5bbe035792ea2d4591242c98e47b8f
4
+ data.tar.gz: fa31f06d130f45b3faf16c54f4856a3bc996d007
5
5
  SHA512:
6
- metadata.gz: edd4515e564e016b8f0b350cea8a5eef68e52d7c32147db28ccfbce08a3742f0673c893e07966e321528a316ec412001832b5eee5327b45c3ee6d064f542521b
7
- data.tar.gz: 06093fe0182f748338cdf1cc4d1b647ad15aa1d30a866d7afcaf0c5d5d90fcf73d98d507c3b07c0f7936259f24a0fe15515c209573fce7388fa552907439c41a
6
+ metadata.gz: 9705df1392dd449ce9e1c22a027800fb79acc56e3d43de157a0c991fe7432870a7e789d54dcf38ad3ddd70f862fd441b992cb32414dd266250a0c910236ec75d
7
+ data.tar.gz: 93eb2b3be78734d111532d11077a6e29b73bdeab7d20fcde756c755245050745ee8b99da043ccc8f263d367b4687521d082c535b39835c4e3cbe793c914a1068
data/README.md CHANGED
@@ -14,10 +14,6 @@ Build a sparce matrix from dense matrix
14
14
  ├── LICENSE.txt
15
15
  ├── README.md
16
16
  ├── Rakefile
17
- ├── input
18
- │   ├── matrix_a
19
- │   ├── matrix_b
20
- │   └── null
21
17
  ├── lib
22
18
  │   ├── sparse_matrix
23
19
  │   │   └── version.rb
@@ -1,3 +1,3 @@
1
1
  module SparseMatrix
2
- VERSION = "0.3.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/sparse_matrix.rb CHANGED
@@ -3,10 +3,39 @@ require "sparse_matrix/version"
3
3
  module SparseMatrix
4
4
  class AbstractMatrix
5
5
 
6
- def intialize ()
6
+ def initialize(r=0,c=0)
7
+ @row = r
8
+ @column = c
9
+ end
10
+
11
+ attr_accessor :row,:column
12
+
13
+ def read_matrix
7
14
 
8
15
  end
9
-
16
+
17
+ def to_s
18
+
19
+ end
20
+
21
+ def print_matrix
22
+
23
+ end
24
+
25
+ def +(b)
26
+
27
+ end
28
+
29
+ def *(b)
30
+
31
+ end
32
+ end
33
+
34
+ class SparseVector
35
+ @i
36
+ @j
37
+ @value
38
+
10
39
  end
11
40
 
12
41
  class SparseMatrix < AbstractMatrix
@@ -17,34 +46,13 @@ module SparseMatrix
17
46
 
18
47
  class DenseMatrix < AbstractMatrix
19
48
  @mat
20
- @filename
21
- def initialize(fn="./input/null")
22
- @filename=fn
23
- @mat = 0
49
+ def initialize(r=0,c=0,matrix=[])
50
+ super(r,c)
51
+ @mat = matrix
24
52
  end
25
53
 
26
54
  attr_accessor :mat
27
55
 
28
- def read_matrix
29
- text = File.open(@filename).read
30
- a = text.split(/\n\n+/)
31
- a = text.split(/\n/)
32
- @mat = to_m(a)
33
- end
34
-
35
- def mapmap(a)
36
- a.map { |r|
37
- r.map { |e|
38
- yield e
39
- }
40
- }
41
- end
42
-
43
- def to_m(a)
44
- a = a.map { |r| r.split(/\s+/) }
45
- a = mapmap(a) { |x| x.to_f }
46
- end
47
-
48
56
  def to_s()
49
57
  s="| "
50
58
  for i in (0... @mat.length)
@@ -78,7 +86,7 @@ module SparseMatrix
78
86
  end
79
87
 
80
88
  def +(b)
81
- c = DenseMatrix.new()
89
+ c = DenseMatrix.new(2,2,[[0.0,0.0],[0.0,0.0]])
82
90
  c.read_matrix
83
91
  for i in (0...@mat.length)
84
92
  for j in(0...@mat.length)
@@ -89,7 +97,7 @@ module SparseMatrix
89
97
  end
90
98
 
91
99
  def *(b)
92
- c=DenseMatrix.new()
100
+ c = DenseMatrix.new(2,2,[[0.0,0.0],[0.0,0.0]])
93
101
  c.read_matrix
94
102
  for i in(0...@mat.length)
95
103
  for j in(0...@mat.length)
@@ -4,7 +4,39 @@ include SparseMatrix
4
4
  describe SparseMatrix do
5
5
 
6
6
  describe AbstractMatrix do
7
-
7
+ before :all do
8
+ AA = AbstractMatrix.new
9
+ end
10
+
11
+ describe "Basic" do
12
+ it 'existe una clase Abstracta Matrix' do
13
+ AA.instance_of?(AbstractMatrix) == true
14
+ end
15
+ it 'se puede acceder a los atributos (row)?' do
16
+ AA.row.should == 0
17
+ end
18
+ it 'se puede acceder a los atributos (column)' do
19
+ AA.column.should == 0
20
+ end
21
+ end
22
+ describe "Existen los Metodos?" do
23
+ it 'Existe metodo imprimir matriz abstracto?' do
24
+ AA.should respond_to("print_matrix")
25
+ end
26
+ it 'Existe metodo to_s abstracto?' do
27
+ AA.should respond_to("to_s")
28
+ end
29
+ it 'Existe el operador sumar abstracto??' do
30
+ AA.should respond_to("+")
31
+ end
32
+ it 'Existe el operador multiplicar abstracto?' do
33
+ AA.should respond_to("*")
34
+ end
35
+ end
36
+ end
37
+
38
+ describe SparseVector do
39
+
8
40
  end
9
41
 
10
42
  describe SparseMatrix do
@@ -14,25 +46,19 @@ describe SparseMatrix do
14
46
 
15
47
  describe DenseMatrix do
16
48
  before :all do
17
- DMA = DenseMatrix.new("input/matrix_a")
18
- DMB = DenseMatrix.new("input/matrix_b")
49
+ DMA = DenseMatrix.new(2,2,[[1.0,2.0],[4.0,5.0]])
50
+ DMB = DenseMatrix.new(2,2,[[1.0,2.0],[3.0,4.0]])
19
51
  end
20
52
 
21
53
  it 'existe una clase Matrix' do
22
54
  DMA.instance_of?(DenseMatrix) == true
23
55
  end
24
56
 
25
- it 'No se ha cargado los datos del fichero al objeto Matrix_T' do
26
- DMA.mat.should eq(0)
27
- end
28
-
29
57
  it 'Se han cargado los datos al objeto A' do
30
- DMA.read_matrix
31
58
  DMA.mat.should be_kind_of(Array)
32
59
  end
33
60
 
34
61
  it 'Se han cargado los datos al objeto B' do
35
- DMB.read_matrix
36
62
  DMB.mat.should be_kind_of(Array)
37
63
  end
38
64
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparse_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - KevinRobayna
@@ -108,9 +108,6 @@ files:
108
108
  - LICENSE.txt
109
109
  - README.md
110
110
  - Rakefile
111
- - input/matrix_a
112
- - input/matrix_b
113
- - input/null
114
111
  - lib/sparse_matrix.rb
115
112
  - lib/sparse_matrix/version.rb
116
113
  - sparse_matrix.gemspec
data/input/matrix_a DELETED
@@ -1,3 +0,0 @@
1
- 1 2
2
- 4 5
3
-
data/input/matrix_b DELETED
@@ -1,4 +0,0 @@
1
- 1 2
2
- 3 4
3
-
4
-
data/input/null DELETED
@@ -1,2 +0,0 @@
1
- 0 0
2
- 0 0