stair_car 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +21 -0
  2. data/Gemfile +14 -0
  3. data/Guardfile +18 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +223 -0
  6. data/Rakefile +1 -0
  7. data/lib/matlab/matlabcontrol-4.0.0.jar +0 -0
  8. data/lib/pcolt/lib/arpack-combo.jar +0 -0
  9. data/lib/pcolt/lib/csparsej.jar +0 -0
  10. data/lib/pcolt/lib/jplasma.jar +0 -0
  11. data/lib/pcolt/lib/jtransforms.jar +0 -0
  12. data/lib/pcolt/lib/junit.jar +0 -0
  13. data/lib/pcolt/lib/netlib-java.jar +0 -0
  14. data/lib/pcolt/lib/optimization.jar +0 -0
  15. data/lib/pcolt/parallelcolt-0.9.4.jar +0 -0
  16. data/lib/stair_car/mmatrix/matlab_interface.rb +9 -0
  17. data/lib/stair_car/mmatrix/mmatrix.rb +26 -0
  18. data/lib/stair_car/pmatrix/compare.rb +34 -0
  19. data/lib/stair_car/pmatrix/matrix_math.rb +169 -0
  20. data/lib/stair_car/pmatrix/pmatrix.rb +151 -0
  21. data/lib/stair_car/pmatrix/transforms.rb +74 -0
  22. data/lib/stair_car/pmatrix/types.rb +106 -0
  23. data/lib/stair_car/shared/errors.rb +7 -0
  24. data/lib/stair_car/shared/indicies.rb +33 -0
  25. data/lib/stair_car/shared/init_methods.rb +56 -0
  26. data/lib/stair_car/shared/inspect.rb +113 -0
  27. data/lib/stair_car/shared/iteration.rb +32 -0
  28. data/lib/stair_car/umatrix/compare.rb +34 -0
  29. data/lib/stair_car/umatrix/matrix_math.rb +190 -0
  30. data/lib/stair_car/umatrix/transforms.rb +49 -0
  31. data/lib/stair_car/umatrix/types.rb +42 -0
  32. data/lib/stair_car/umatrix/umatrix.rb +166 -0
  33. data/lib/stair_car.rb +35 -0
  34. data/lib/ujmp/ujmp-complete-0.2.5.jar +0 -0
  35. data/spec/pmatrix/matrix_math_spec.rb +65 -0
  36. data/spec/pmatrix/pmatrix_spec.rb +103 -0
  37. data/spec/pmatrix/transforms_spec.rb +44 -0
  38. data/spec/shared/indicies_spec.rb +52 -0
  39. data/spec/shared/inspect_spec.rb +23 -0
  40. data/spec/shared/iteration_spec.rb +17 -0
  41. data/spec/spec_helper.rb +5 -0
  42. data/spec/umatrix/matrix_math_spec.rb +68 -0
  43. data/spec/umatrix/transform_spec.rb +32 -0
  44. data/spec/umatrix/umatrix_spec.rb +104 -0
  45. data/stair_car.gemspec +19 -0
  46. metadata +120 -0
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'stair_car'
3
+
4
+ describe StairCar::Indicies do
5
+ before(:all) do
6
+ @matrix = StairCar::PMatrix.zeros(5,5)
7
+ end
8
+ it "should convert integers to arrays" do
9
+ @matrix.convert_indicies(1, 3).should == [1]
10
+ end
11
+
12
+ it "should support negative indicies" do
13
+ @matrix.convert_indicies(-1, 5).should == [4]
14
+ end
15
+
16
+ it "should support arrays" do
17
+ @matrix.convert_indicies([1,3],5).should == [1,3]
18
+ end
19
+
20
+ it "should support arrays with a negative number" do
21
+ @matrix.convert_indicies([1,-1],5).should == [1,4]
22
+ end
23
+
24
+ it "should support ranges" do
25
+ @matrix.convert_indicies(1..3,5).should == [1,2,3]
26
+ end
27
+
28
+ it "should support ranges and numbers in an array" do
29
+ @matrix.convert_indicies([1..3, 4],5).should == [1,2,3,4]
30
+ end
31
+
32
+ it "should support nested arrays" do
33
+ # Not sure why anyone would do this, but what the heck
34
+ @matrix.convert_indicies([[1,2],[4,5]], 5).should == [1,2,4,5]
35
+ end
36
+
37
+ it "should support a range then a negative index" do
38
+ @matrix.convert_indicies([1..2,-1],5).should == [1,2,4]
39
+ end
40
+
41
+ it "should support ranges with a negative end value" do
42
+ @matrix.convert_indicies([1..-1],5).should == [1,2,3,4]
43
+ end
44
+
45
+ it "should support ranges with a negative end value" do
46
+ @matrix.convert_indicies([1...-1],5).should == [1,2,3]
47
+ end
48
+
49
+ it "should support nil for all columns or rows" do
50
+ @matrix.convert_indicies(nil,5).should == nil
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'stair_car'
3
+
4
+ describe StairCar::Inspect do
5
+ before(:all) do
6
+ end
7
+
8
+ it "should inspect correctly" do
9
+ @matrix = StairCar::PMatrix.asc(5,5)
10
+ @matrix[2,3] = 49.1384245
11
+
12
+ @matrix.inspect.should == "<#PMatrix(double) 5x5 dense>\n1 2 3 4 5 \n6 7 8 9 10 \n11 12 13 49.138 15 \n16 17 18 19 20 \n21 22 23 24 25 "
13
+ end
14
+
15
+ it "should hide rows within the view" do
16
+ @matrix = StairCar::PMatrix.asc(50,50)
17
+
18
+ inspect_val = "<#PMatrix(double) 50x50 dense>\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 ..... 50 \n51 52 53 54 55 56 57 58 59 60 61 62 63 64 ..... 100 \n101 102 103 104 105 106 107 108 109 110 111 112 113 114 ...3. 150 \n151 152 153 154 155 156 157 158 159 160 161 162 163 164 ...6. 200 \n201 202 203 204 205 206 207 208 209 210 211 212 213 214 ... . 250 \n251 252 253 254 255 256 257 258 259 260 261 262 263 264 ...c. 300 \n301 302 303 304 305 306 307 308 309 310 311 312 313 314 ...o. 350 \n351 352 353 354 355 356 357 358 359 360 361 362 363 364 ...l. 400 \n401 402 403 404 405 406 407 408 409 410 411 412 413 414 ...s. 450 \n451 452 453 454 455 456 457 458 459 460 461 462 463 464 ..... 500 \n501 502 503 504 505 506 507 508 509 510 511 512 513 514 ..... 550 \n....................................39 rows.....................................\n2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 ..... 2500"
19
+
20
+ @matrix.inspect.should == inspect_val
21
+ end
22
+
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'stair_car'
3
+
4
+ describe StairCar::Iteration do
5
+ it "should loop through each element" do
6
+ matrix = StairCar::PMatrix.asc(3,4)
7
+ total = 0
8
+ called = 0
9
+ matrix.each {|i| total += i ; called += 1 }
10
+ total.should == 78.0
11
+ called.should == 12
12
+ end
13
+
14
+ it "should loop through each row" do
15
+ matrix = StairCar::PMatrix.asc(3,4)
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+
5
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'stair_car'
3
+
4
+ describe StairCar::UMatrixMatrixMath do
5
+ before(:all) do
6
+ @a = StairCar::UMatrix.asc(5,5)
7
+ @b = StairCar::UMatrix.asc(5,5)
8
+ end
9
+
10
+ it 'should add matricies' do
11
+ c = @a + @b
12
+ c[0,0].should == 2
13
+
14
+ d = @a[nil,nil] + @b
15
+ d[0,0].should == 2
16
+ end
17
+
18
+ it 'should add scalars' do
19
+ c = @a + 5
20
+ # Should copy
21
+ @a[0,0].should == 1
22
+
23
+ c[0,0].should == 6
24
+ end
25
+
26
+ # it 'should add vectors' do
27
+ # c = StairCar::UMatrix.new([[1,2,3,4,5]])
28
+ # # (@a + c).should == StairCar::UMatrix.new([[2,4,6,8,10]])
29
+ # end
30
+
31
+
32
+ it 'should sum all' do
33
+ matrix = StairCar::UMatrix.asc(3,3)
34
+ matrix.sum.should == 45
35
+ end
36
+
37
+ it 'should sum columns' do
38
+ matrix = StairCar::UMatrix.asc(3,5)
39
+ matrix.sum(0).should == StairCar::UMatrix.new([[18, 21, 24, 27, 30]])
40
+ end
41
+
42
+ it 'should get the max on columns or rows' do
43
+ matrix = StairCar::UMatrix.asc(3,5)
44
+ matrix.max(1).should == StairCar::UMatrix.new([[5],[10],[15]])
45
+ matrix.max(0).should == StairCar::UMatrix.new([[11, 12, 13, 14, 15]])
46
+ end
47
+
48
+ it 'should get the mins on columns or rows' do
49
+ matrix = StairCar::UMatrix.asc(3,5)
50
+ matrix.min(1).should == StairCar::UMatrix.new([[1],[6],[11]])
51
+ matrix.min(0).should == StairCar::UMatrix.new([[1, 2, 3, 4, 5]])
52
+ end
53
+
54
+ it "should return the mean on each dimension" do
55
+ matrix = StairCar::UMatrix.asc(3,5)
56
+ matrix.mean.should == 8.0
57
+ matrix.mean(1).should == StairCar::UMatrix.new([[3],[8],[13]])
58
+ matrix.mean(0).should == StairCar::UMatrix.new([[6, 7, 8, 9, 10]])
59
+ end
60
+
61
+ # it "should return the variance" do
62
+ #
63
+ # end
64
+ #
65
+ # it "should return the standard deviation" do
66
+ #
67
+ # end
68
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'stair_car'
3
+
4
+ describe StairCar::UMatrixTransforms do
5
+ it "should transpose" do
6
+ matrix = StairCar::UMatrix.asc(3,4)
7
+ (~matrix).should_not == matrix
8
+ (~~matrix).should == matrix
9
+ end
10
+
11
+ it "should map and map_non_zero" do
12
+ matrix = StairCar::UMatrix.spzeros(2,3)
13
+ matrix[0,0] = 5
14
+ matrix[1,2] = 10
15
+ mapped_matrix = matrix.map {|v| v * 2 }
16
+ mapped_matrix[0,0].should == 10
17
+ mapped_matrix[1,2].should == 20
18
+ mapped_matrix[0,1].should == 0
19
+
20
+ calls = 0
21
+ matrix.map_non_zero! {|v,row,col| calls += 1; v + 2 }
22
+ calls.should == 2
23
+ matrix[0,0].should == 7
24
+ matrix[1,2].should == 12
25
+ end
26
+
27
+ it "should convert back to a ruby array" do
28
+ matrix = StairCar::UMatrix.asc(3,3)
29
+ matrix.to_a.should == [[1,2,3],[4,5,6],[7,8,9]]
30
+ end
31
+
32
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+ require 'stair_car'
3
+
4
+ describe StairCar::UMatrix do
5
+ it "should initialize" do
6
+ matrix = StairCar::UMatrix.zeros(5,4)
7
+ matrix.cols.should == 4
8
+ matrix.rows.should == 5
9
+ matrix.size.should == 20
10
+
11
+ matrix = StairCar::UMatrix.spzeros(5,4)
12
+ matrix.size.should == 20
13
+ end
14
+
15
+ it "should initialize with values" do
16
+ matrix1 = StairCar::UMatrix.new([[3,8,13]])
17
+ matrix1[0,0].should == 3
18
+ matrix1[0,2].should == 13
19
+
20
+ matrix2 = StairCar::UMatrix.new([[3],[8],[13]])
21
+ matrix2[0,0].should == 3
22
+ matrix2[2,0].should == 13
23
+ end
24
+
25
+ it "should set and get" do
26
+ matrix = StairCar::UMatrix.zeros(3,4)
27
+ matrix[0,0] = 5
28
+ matrix[0,0].should == 5
29
+ end
30
+
31
+ # it "should allow set and get with a single index on vectors" do
32
+ # matrix = StairCar::UMatrix.spzeros(3,5)
33
+ #
34
+ # matrix[1,nil][2] == 4
35
+ # matrix[1,2].should == 4
36
+ # end
37
+
38
+ it "should set via arrays" do
39
+ matrix = StairCar::UMatrix.zeros(3,4)
40
+ matrix[0,nil] = [1,2,3,4]
41
+ matrix[0,nil].should == StairCar::UMatrix.new([1,2,3,4])
42
+ matrix[nil,0] = [1,2,3]
43
+ matrix[nil,nil] = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
44
+ end
45
+ #
46
+ it "should raise an error when trying to assign an array with invalid dimensions" do
47
+ matrix = StairCar::UMatrix.zeros(3,4)
48
+
49
+ lambda {
50
+ matrix[0,nil] = [1,2,3,4,5,6]
51
+ }.should raise_error(StairCar::MatrixDimensionsError)
52
+ end
53
+
54
+ it "should get and set with negative values" do
55
+ matrix = StairCar::UMatrix.zeros(5,4)
56
+ matrix[4,3] = 5
57
+ matrix[-1,-1].should == 5
58
+ end
59
+
60
+ it "should allow you to setup ones" do
61
+ matrix = StairCar::UMatrix.ones(5,5)
62
+ matrix[2,2].should == 1
63
+ end
64
+
65
+
66
+ it 'should compare matrix values' do
67
+ matrix1 = StairCar::UMatrix.asc(3,3)
68
+ matrix2 = StairCar::UMatrix.asc(3,3)
69
+ matrix3 = StairCar::UMatrix.zeros(3,3)
70
+
71
+ matrix1.should == matrix2
72
+ matrix1.should_not == matrix3
73
+ end
74
+
75
+ it "should allow you to set with an array" do
76
+ matrix = StairCar::UMatrix.zeros(2,2)
77
+ matrix[nil,nil] = [[1,2],[3,4]]
78
+ matrix[0,0].should == 1.0
79
+ matrix[1,1].should == 4.0
80
+ end
81
+
82
+ it "should allow you to initialize by an array" do
83
+ matrix = StairCar::UMatrix.new([[1,2],[3,4]])
84
+ matrix[0,0].should == 1.0
85
+ matrix[1,1].should == 4.0
86
+ end
87
+
88
+ describe "dimensions" do
89
+ before(:all) do
90
+ @matrix = StairCar::UMatrix.zeros(3,2)
91
+ end
92
+ it "should return its shape" do
93
+ @matrix.shape.should == [3,2]
94
+ end
95
+
96
+ it "should return the rows" do
97
+ @matrix.rows.should == 3
98
+ end
99
+
100
+ it "should return the cols" do
101
+ @matrix.cols.should == 2
102
+ end
103
+ end
104
+ end
data/stair_car.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "stair_car"
7
+ gem.version = "0.0.1"
8
+ gem.authors = ["Ryan Stout"]
9
+ gem.email = ["ryanstout@gmail.com"]
10
+ gem.description = "StairCar is a fully featured matrix for jruby (think matlab or numpy)"
11
+ gem.summary = "StairCar makes it easy to do large scale matrix operations in jruby"
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ gem.add_development_dependency "rspec"
19
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stair_car
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Stout
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: !binary |-
21
+ MA==
22
+ none: false
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: !binary |-
28
+ MA==
29
+ none: false
30
+ prerelease: false
31
+ type: :development
32
+ description: StairCar is a fully featured matrix for jruby (think matlab or numpy)
33
+ email:
34
+ - ryanstout@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - Guardfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - lib/matlab/matlabcontrol-4.0.0.jar
46
+ - lib/pcolt/lib/arpack-combo.jar
47
+ - lib/pcolt/lib/csparsej.jar
48
+ - lib/pcolt/lib/jplasma.jar
49
+ - lib/pcolt/lib/jtransforms.jar
50
+ - lib/pcolt/lib/junit.jar
51
+ - lib/pcolt/lib/netlib-java.jar
52
+ - lib/pcolt/lib/optimization.jar
53
+ - lib/pcolt/parallelcolt-0.9.4.jar
54
+ - lib/stair_car.rb
55
+ - lib/stair_car/mmatrix/matlab_interface.rb
56
+ - lib/stair_car/mmatrix/mmatrix.rb
57
+ - lib/stair_car/pmatrix/compare.rb
58
+ - lib/stair_car/pmatrix/matrix_math.rb
59
+ - lib/stair_car/pmatrix/pmatrix.rb
60
+ - lib/stair_car/pmatrix/transforms.rb
61
+ - lib/stair_car/pmatrix/types.rb
62
+ - lib/stair_car/shared/errors.rb
63
+ - lib/stair_car/shared/indicies.rb
64
+ - lib/stair_car/shared/init_methods.rb
65
+ - lib/stair_car/shared/inspect.rb
66
+ - lib/stair_car/shared/iteration.rb
67
+ - lib/stair_car/umatrix/compare.rb
68
+ - lib/stair_car/umatrix/matrix_math.rb
69
+ - lib/stair_car/umatrix/transforms.rb
70
+ - lib/stair_car/umatrix/types.rb
71
+ - lib/stair_car/umatrix/umatrix.rb
72
+ - lib/ujmp/ujmp-complete-0.2.5.jar
73
+ - spec/pmatrix/matrix_math_spec.rb
74
+ - spec/pmatrix/pmatrix_spec.rb
75
+ - spec/pmatrix/transforms_spec.rb
76
+ - spec/shared/indicies_spec.rb
77
+ - spec/shared/inspect_spec.rb
78
+ - spec/shared/iteration_spec.rb
79
+ - spec/spec_helper.rb
80
+ - spec/umatrix/matrix_math_spec.rb
81
+ - spec/umatrix/transform_spec.rb
82
+ - spec/umatrix/umatrix_spec.rb
83
+ - stair_car.gemspec
84
+ homepage: ''
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: !binary |-
95
+ MA==
96
+ none: false
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: !binary |-
102
+ MA==
103
+ none: false
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.24
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: StairCar makes it easy to do large scale matrix operations in jruby
110
+ test_files:
111
+ - spec/pmatrix/matrix_math_spec.rb
112
+ - spec/pmatrix/pmatrix_spec.rb
113
+ - spec/pmatrix/transforms_spec.rb
114
+ - spec/shared/indicies_spec.rb
115
+ - spec/shared/inspect_spec.rb
116
+ - spec/shared/iteration_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/umatrix/matrix_math_spec.rb
119
+ - spec/umatrix/transform_spec.rb
120
+ - spec/umatrix/umatrix_spec.rb