File: test_time_eigen.rb

package info (click to toggle)
jblas 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,164 kB
  • sloc: java: 11,050; ansic: 4,152; ruby: 2,290; xml: 289; makefile: 132; sh: 22
file content (35 lines) | stat: -rw-r--r-- 930 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'tictoc'
require 'jmatrix'
require 'benchmark'

include JBLAS

def char(s)
  case s
  when String
    java.lang.Character.new(s[0])
  when Fixnum
    java.lang.Character.new(s)
  end
end

n = 1000

def time_it(n, i)
  x = DoubleVector.randn(n).sort
  k = Geometry.pairwiseSquaredDistances(x, x).muli(-2).expi
  ev = DoubleVector.new(n)

  puts "Benchmark for n = #{n} (reported numbers are #{i} iterations)"

  Benchmark.benchmark do |r|
    r.report("syev eigenvalues:  ") { i.times { SimpleBlas.syev(char('N'), char('U'), k.dup, ev) } }    
    r.report("syevd eigenvalues: ") { i.times { SimpleBlas.syevd(char('N'), char('U'), k.dup, ev) } }    
    r.report("syev eigenvectors: ") { i.times { SimpleBlas.syev(char('V'), char('U'), k.dup, ev) } }    
    r.report("syevd eigenvectors:") { i.times { SimpleBlas.syevd(char('V'), char('U'), k.dup, ev) } }    
  end
end

time_it(100, 100)
time_it(500, 20)
time_it(1000, 5)