From d46baaca83b0a94eb43f4a131d19c45c11b229c4 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Fri, 6 Mar 2015 19:05:39 +0100 Subject: fileutil: rewind, SV: division -> bump to 1.2.4 --- lib/zipf/SparseVector.rb | 9 +++++++++ lib/zipf/fileutil.rb | 4 ++++ 2 files changed, 13 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3