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 ++++ zipf.gemspec | 4 ++-- 3 files changed, 15 insertions(+), 2 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 diff --git a/zipf.gemspec b/zipf.gemspec index 676d319..199c61f 100644 --- a/zipf.gemspec +++ b/zipf.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'zipf' - s.version = '1.2.3' - s.date = '2015-03-04' + s.version = '1.2.4' + s.date = '2015-03-06' s.summary = 'zipf' s.description = 'NLP related tools and classes' s.authors = ['Patrick Simianer'] -- cgit v1.2.3