sparse_matrix 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/Guardfile +30 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/input/matrix_a +3 -0
- data/input/matrix_b +4 -0
- data/input/null +2 -0
- data/lib/matrix.rb +66 -0
- data/lib/sparse_matrix/version.rb +3 -0
- data/lib/sparse_matrix.rb +81 -0
- data/sparse_matrix.gemspec +28 -0
- data/spec/math/matrix_spec.rb +56 -0
- data/spec/math/sparsematrix_spec.rb +16 -0
- data/test/math/matrix_test.rb +0 -0
- data/test/math/sparsematrix_test.rb +0 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cefab8ce99739715090611dd4a221806e9e4711f
|
4
|
+
data.tar.gz: a9a7bf3c925db43e9761f75d39975b838428c3af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d040255afe87e2df3197474835d322f126d055fb11e429bbc33b6c25762a28ce6ac91dde6a2f515c62e2a9ef72aeec80122567f9cbec941b166a980f2b8273b3
|
7
|
+
data.tar.gz: 7649db8cc449535adff9f22e2916794ab88b7f124e110bbedc64dfab40d3b8c3c149c1f3f1db5bc8220b2f056824e76e97461dc30555f4340ac91a921633af43
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :bundler do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if your Gemfile contains the `gemspec' command.
|
7
|
+
# watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard :rspec do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec" }
|
14
|
+
|
15
|
+
# Rails example
|
16
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
17
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
18
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
19
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
20
|
+
watch('config/routes.rb') { "spec/routing" }
|
21
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
22
|
+
|
23
|
+
# Capybara features specs
|
24
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
25
|
+
|
26
|
+
# Turnip features and steps
|
27
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
28
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
29
|
+
end
|
30
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 KevinRobayna
|
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,44 @@
|
|
1
|
+
# SparseMatrix
|
2
|
+
|
3
|
+
Build a sparce matrix from dense matrix
|
4
|
+
|
5
|
+
## Tree
|
6
|
+
|
7
|
+
├── Gemfile
|
8
|
+
├── input
|
9
|
+
├── lib
|
10
|
+
│ ├── sparse_matrix
|
11
|
+
│ │ └── version.rb
|
12
|
+
│ └── sparse_matrix.rb
|
13
|
+
├── LICENSE.txt
|
14
|
+
├── Rakefile
|
15
|
+
├── README.md
|
16
|
+
├── sparse_matrix.gemspec
|
17
|
+
├── spec
|
18
|
+
│ └── math
|
19
|
+
│ ├── matrix_spec.rb
|
20
|
+
│ └── sparsematrix_spec.rb
|
21
|
+
└── test
|
22
|
+
└── math
|
23
|
+
├── matrix_test.rb
|
24
|
+
└── sparsematrix_test.rb
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
gem 'sparse_matrix'
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
$ gem install sparse_matrix
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
as soon as
|
41
|
+
|
42
|
+
## Authors
|
43
|
+
Kevin Robayna
|
44
|
+
Jose Antonio Rodriguez Leandro
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
$:.unshift File.dirname(__FILE__) + 'lib'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
task :default => :spec
|
8
|
+
desc "Ejecucion de pruebas rspec"
|
9
|
+
task :spec do
|
10
|
+
sh "rspec --color --format documentation -Ilib -Ispec spec/math/matrix_spec.rb"
|
11
|
+
sh "rspec --color --format documentation -Ilib -Ispec spec/math/sparsematrix_spec.rb"
|
12
|
+
end
|
data/input/matrix_a
ADDED
data/input/matrix_b
ADDED
data/input/null
ADDED
data/lib/matrix.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
class Matrix_T
|
2
|
+
@mat
|
3
|
+
@filename
|
4
|
+
|
5
|
+
def initialize(fn="./input/null")
|
6
|
+
@filename=fn
|
7
|
+
@mat=0
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :mat
|
11
|
+
|
12
|
+
def read_matrix
|
13
|
+
text = File.open(@filename).read
|
14
|
+
a = text.split(/\n\n+/)
|
15
|
+
a = text.split(/\n/)
|
16
|
+
@mat = to_m(a)
|
17
|
+
end
|
18
|
+
|
19
|
+
def mapmap(a)
|
20
|
+
a.map { |r|
|
21
|
+
r.map { |e|
|
22
|
+
yield e
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_m(a)
|
28
|
+
a = a.map { |r| r.split(/\s+/) }
|
29
|
+
a = mapmap(a) { |x| x.to_f }
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s()
|
33
|
+
s="| "
|
34
|
+
for i in (0... @mat.length)
|
35
|
+
for j in (0... @mat.length)
|
36
|
+
if j==0
|
37
|
+
s += "{ "
|
38
|
+
end
|
39
|
+
s += "#{@mat[i][j]}\t"
|
40
|
+
if j == @mat.length-1
|
41
|
+
s += " } , "
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
s += "|"
|
46
|
+
end
|
47
|
+
|
48
|
+
def print()
|
49
|
+
printf "| "
|
50
|
+
for i in (0... @mat.length)
|
51
|
+
for j in (0... @mat.length)
|
52
|
+
if j==0
|
53
|
+
printf "{ "
|
54
|
+
end
|
55
|
+
printf "#{@mat[i][j]}\t"
|
56
|
+
if j == @mat.length-1
|
57
|
+
printf " } , "
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
printf "|"
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "sparse_matrix/version"
|
2
|
+
|
3
|
+
class SparseMatrix
|
4
|
+
@sparse_mat
|
5
|
+
|
6
|
+
def initialize(b=0)
|
7
|
+
@sparse_mat=b
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class Matrix_T
|
17
|
+
@mat
|
18
|
+
@filename
|
19
|
+
|
20
|
+
def initialize(fn="./input/null")
|
21
|
+
@filename=fn
|
22
|
+
@mat=0
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor :mat
|
26
|
+
|
27
|
+
def read_matrix
|
28
|
+
text = File.open(@filename).read
|
29
|
+
a = text.split(/\n\n+/)
|
30
|
+
a = text.split(/\n/)
|
31
|
+
@mat = to_m(a)
|
32
|
+
end
|
33
|
+
|
34
|
+
def mapmap(a)
|
35
|
+
a.map { |r|
|
36
|
+
r.map { |e|
|
37
|
+
yield e
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_m(a)
|
43
|
+
a = a.map { |r| r.split(/\s+/) }
|
44
|
+
a = mapmap(a) { |x| x.to_f }
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s()
|
48
|
+
s="| "
|
49
|
+
for i in (0... @mat.length)
|
50
|
+
for j in (0... @mat.length)
|
51
|
+
if j==0
|
52
|
+
s += "{ "
|
53
|
+
end
|
54
|
+
s += "#{@mat[i][j]}\t"
|
55
|
+
if j == @mat.length-1
|
56
|
+
s += " } , "
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
s += "|"
|
61
|
+
end
|
62
|
+
|
63
|
+
def print()
|
64
|
+
printf "| "
|
65
|
+
for i in (0... @mat.length)
|
66
|
+
for j in (0... @mat.length)
|
67
|
+
if j==0
|
68
|
+
printf "{ "
|
69
|
+
end
|
70
|
+
printf "#{@mat[i][j]}\t"
|
71
|
+
if j == @mat.length-1
|
72
|
+
printf " } , "
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
printf "|"
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sparse_matrix/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sparse_matrix"
|
8
|
+
spec.version = SparseMatrix::VERSION
|
9
|
+
spec.authors = ["KevinRobayna"]
|
10
|
+
spec.email = ["k3vinaso@gmail.com"]
|
11
|
+
spec.description = %q{Build a sparse matrix from dense matrix}
|
12
|
+
spec.summary = %q{sparse matrix}
|
13
|
+
spec.homepage = "https://github.com/kevinrobayna/SparseMatrix"
|
14
|
+
spec.license = "MIT"
|
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
|
+
spec.add_development_dependency "guard"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
25
|
+
spec.add_development_dependency "guard-bundler"
|
26
|
+
spec.add_development_dependency "guard-gitpusher"
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'sparse_matrix'
|
2
|
+
|
3
|
+
describe Matrix_T do
|
4
|
+
before :all do
|
5
|
+
A = Matrix_T.new("input/matrix_a")
|
6
|
+
end
|
7
|
+
describe "Basicas" do
|
8
|
+
it 'Existe una clase Matrix?' do
|
9
|
+
A.instance_of?(Matrix_T) == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'Se puede acceder a la matriz?' do
|
13
|
+
A.mat.should == 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Construyendo Matriz" do
|
18
|
+
it 'Existe metodo para leer matrices (READ-MATRIX)?' do
|
19
|
+
A.should respond_to("read_matrix")
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'Existe sub-metodo para leer matrices (MAPMAP)?' do
|
23
|
+
A.should respond_to("mapmap")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'Existe sub-metodo para leer matrices (TO_M)?' do
|
27
|
+
A.should respond_to("to_m")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'Se han cargado los datos al objeto A' do
|
31
|
+
A.read_matrix
|
32
|
+
A.mat.should be_kind_of(Array)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Mostrando Matrices" do
|
38
|
+
it 'Existe metodo to_s para devolver una matriz?' do
|
39
|
+
A.should respond_to("to_s")
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'Existe metodo print para mostrar una matriz?' do
|
43
|
+
A.should respond_to("print")
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'El Metodo to_s devuelve correctamente la matriz?' do
|
47
|
+
A.to_s.should eq("| { 1.0\t2.0\t } , { 4.0\t5.0\t } , |")
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'El metodo print imprime correctamente la matriz?' do
|
51
|
+
A.print.should eq(nil)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
File without changes
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sparse_matrix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- KevinRobayna
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-gitpusher
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Build a sparse matrix from dense matrix
|
98
|
+
email:
|
99
|
+
- k3vinaso@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- Guardfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- input/matrix_a
|
112
|
+
- input/matrix_b
|
113
|
+
- input/null
|
114
|
+
- lib/matrix.rb
|
115
|
+
- lib/sparse_matrix.rb
|
116
|
+
- lib/sparse_matrix/version.rb
|
117
|
+
- sparse_matrix.gemspec
|
118
|
+
- spec/math/matrix_spec.rb
|
119
|
+
- spec/math/sparsematrix_spec.rb
|
120
|
+
- test/math/matrix_test.rb
|
121
|
+
- test/math/sparsematrix_test.rb
|
122
|
+
homepage: https://github.com/kevinrobayna/SparseMatrix
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.1.10
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: sparse matrix
|
146
|
+
test_files:
|
147
|
+
- spec/math/matrix_spec.rb
|
148
|
+
- spec/math/sparsematrix_spec.rb
|
149
|
+
- test/math/matrix_test.rb
|
150
|
+
- test/math/sparsematrix_test.rb
|