diff options
author | Patrick Simianer <p@simianer.de> | 2015-03-06 19:05:39 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-03-06 19:05:39 +0100 |
commit | d46baaca83b0a94eb43f4a131d19c45c11b229c4 (patch) | |
tree | 0be18196638906d82a893cacbb75ba2f1ccf4852 /lib | |
parent | 2ab23ec844862b3ec034f805f74420f36ac639f5 (diff) |
fileutil: rewind, SV: division -> bump to 1.2.4
Diffstat (limited to 'lib')
-rw-r--r-- | lib/zipf/SparseVector.rb | 9 | ||||
-rw-r--r-- | lib/zipf/fileutil.rb | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/zipf/SparseVector.rb b/lib/zipf/SparseVector.rb index 837403a..5d219b8 100644 --- a/lib/zipf/SparseVector.rb +++ b/lib/zipf/SparseVector.rb @@ -179,6 +179,15 @@ class SparseVector < Hash return new end + def / scalar + raise ArgumentError, "Arg is not numeric #{scalar}" unless scalar.is_a? Numeric + new = SparseVector.new + self.keys.each { |k| + new[k] = self[k] / scalar + } + return new + end + def self.mean a mean = SparseVector.new a.each { |i| diff --git a/lib/zipf/fileutil.rb b/lib/zipf/fileutil.rb index ac701da..7ae0c55 100644 --- a/lib/zipf/fileutil.rb +++ b/lib/zipf/fileutil.rb @@ -18,6 +18,10 @@ class ReadFile @f.gets { |line| yield line } end + def rewind + @f.rewind + end + def readlines @f.readlines end |