<commit_before>require 'extendmatrix'

class Vector
	alias :index :[]
	def [](i)
		case i
		when Range
			Vector[*to_a.slice(i)]
		else
			index(i)
		end	
	end
	def []=(i, v)
		case i
		when Range
			i.each{|e| self[e]=v[e - i.begin]}	
		else
			@elements[i]=v 
		end
	end
end

class Matrix
	def slice(lines, cols)
			return Matrix[*lines.collect{|l| row(l).slice(cols).to_a}] if lines.is_a?(Range) and cols.is_a?(Range)
			return column(cols).slice(lines) if lines.is_a?(Range) and cols.is_a?(Fixnum)
		  return row(lines).slice(cols) if lines.is_a?(Fixnum) and cols.is_a?(Range)
			return self[lines, cols] if lines.is_a?(Fixnum) and cols.is_a?(Fixnum)

	end

	def slice=(args)
		case args[1]
		when Range 
			case args[2]
			when Range
				args[1].each{|l| row = l, args[0].row(l - args[1].begin), args[2]}
			else
				column=args[2], args[0], args[1]	
			end
		else
			case args[2]
			when Range
				row=args[1], args[0],args[2]
			else
				self[args[1],args[2]] = args[0]
			end
		end		
	end

	alias :ids :[]
	def [](i, j)
		case i
		when Range 
			case j
			when Range
				Matrix[*i.collect{|l| self.row(l)[j].to_a}]
			else
				column(j)[i]	
			end
		else
			case j
			when Range
				row(i)[j]
			else
				ids(i, j)
			end
		end		
	end

	def []=(i, j, v)
		case i
		when Range 
			case j
			when Range
				i.each{|l| self.row= l, v.row(l - i.begin), j}
			else
				self.column= j, v, i	
			end
		else
			case j
			when Range
				self.row= i, v, j
			else
				@rows[i][j] = v
			end
		end		
	end	

	def QR
		m = row_size
		n = column_size
		print "#{m} #{n}"
		m.times{|j|
			v, beta = slice(j..m, j).house
			p v
			p beta
			p m-j
			slice=(Matrix.I(m-j) - beta * (v * v.t)) * slice(j..m, j..n) , j..m, j..n
			slice= v.slice(2..(m-j+1)), j+1..m, j if j < m
		}
	end
end<commit_msg>fixed QR factorization<commit_after>require 'extendmatrix'

class Vector
	alias :index :[]
	def [](i)
		case i
		when Range
			Vector[*to_a.slice(i)]
		else
			index(i)
		end	
	end
	def []=(i, v)
		case i
		when Range
			i.each{|e| self[e]=v[e - i.begin]}	
		else
			@elements[i]=v 
		end
	end
end

class Matrix
	def slice(lines, cols)
			return Matrix[*lines.collect{|l| row(l).slice(cols).to_a}] if lines.is_a?(Range) and cols.is_a?(Range)
			return column(cols).slice(lines) if lines.is_a?(Range) and cols.is_a?(Fixnum)
		  return row(lines).slice(cols) if lines.is_a?(Fixnum) and cols.is_a?(Range)
			return self[lines, cols] if lines.is_a?(Fixnum) and cols.is_a?(Fixnum)

	end

	def slice=(args)
		case args[1]
		when Range 
			case args[2]
			when Range
				args[1].each{|l| row = l, args[0].row(l - args[1].begin), args[2]}
			else
				column=args[2], args[0], args[1]	
			end
		else
			case args[2]
			when Range
				row=args[1], args[0],args[2]
			else
				self[args[1],args[2]] = args[0]
			end
		end		
	end

	alias :ids :[]
	def [](i, j)
		case i
		when Range 
			case j
			when Range
				Matrix[*i.collect{|l| self.row(l)[j].to_a}]
			else
				column(j)[i]	
			end
		else
			case j
			when Range
				row(i)[j]
			else
				ids(i, j)
			end
		end		
	end

	def []=(i, j, v)
		case i
		when Range 
			case j
			when Range
				i.each{|l| self.row= l, v.row(l - i.begin), j}
			else
				self.column= j, v, i	
			end
		else
			case j
			when Range
				self.row= i, v, j
			else
				@rows[i][j] = v
			end
		end		
	end	

	def QR
		m = row_size - 1
		n = column_size - 1
		print "m:#{m} n:#{n} \n"
		m.times{|j|
			v, beta = slice(j..m, j).house
			p v
			p  v[2..(m-j+1)]
			self[j..m, j..n] = (Matrix.I(m-j+1) - beta * (v * v.t)) * self[j..m, j..n]
			self[(j+1)..m,j] = v[2..(m-j+1)] if j < m
		}
	end
end
{'fraction_non_alphanumeric': 0.170508192168842, 'fraction_numerical': 0.011941127464593169, 'mean_word_length': 2.394910461828464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5838172', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1623, 'n_words': 408}