summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-03-06 19:05:39 +0100
committerPatrick Simianer <p@simianer.de>2015-03-06 19:05:39 +0100
commitd46baaca83b0a94eb43f4a131d19c45c11b229c4 (patch)
tree0be18196638906d82a893cacbb75ba2f1ccf4852
parent2ab23ec844862b3ec034f805f74420f36ac639f5 (diff)
fileutil: rewind, SV: division -> bump to 1.2.4
-rw-r--r--lib/zipf/SparseVector.rb9
-rw-r--r--lib/zipf/fileutil.rb4
-rw-r--r--zipf.gemspec4
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']