From b46e1bb50ce4bf511e1e3a89c5f64767778e8ff9 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Tue, 18 Oct 2011 11:22:15 +0000 Subject: [PATCH] memory optimization on bitarray.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1584 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/lib/maasha/bitarray.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/code_ruby/lib/maasha/bitarray.rb b/code_ruby/lib/maasha/bitarray.rb index 1b2bc9e..efaba4f 100644 --- a/code_ruby/lib/maasha/bitarray.rb +++ b/code_ruby/lib/maasha/bitarray.rb @@ -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. -- 2.39.5