]> git.donarmstrong.com Git - biopieces.git/commitdiff
memory optimization on bitarray.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 18 Oct 2011 11:22:15 +0000 (11:22 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 18 Oct 2011 11:22:15 +0000 (11:22 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1584 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/bitarray.rb

index 1b2bc9ea212268c5650f44c63c58f2a6d6ceaf99..efaba4fd69411cec34b56d2b5cddff47188d1151 100644 (file)
@@ -23,6 +23,7 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 require 'narray'
+require 'pp'
 
 BitsInChar = 8
 
@@ -83,14 +84,10 @@ class BitArray
   end
 
   # Method that returns the number of bits set "on" in a bit array.
-  def bits_on 
-    bits_on = 0
-
-    self.byte_array.each do |byte|
-      bits_on += @count_array[byte]
-    end
-
-    bits_on
+  def bits_on
+    index = NArray.sint(*self.byte_array.shape)
+    index[] = self.byte_array
+    NArray.to_na(@count_array)[index].sum
   end
 
   # Method that returns the number of bits set "off" in a bit array.