#!/usr/bin/python -Wall

# ================================================================
# This software is released under the terms of the GNU GPL.
# Please see LICENSE.txt in the same directory as this file.
# Copyright (c) John Kerl 2007
# kerl.john.r@gmail.com
# ================================================================

from __future__ import division # 1/2 = 0.5, not 0.
import sys
import math
from sackmat_m import *

argc = len(sys.argv)
if (argc != 2):
	print >> sys.stderr, "Usage: %s {file name}" % (sys.argv[0])
	sys.exit(1)

u = read_column_vector(float, sys.argv[1])
height = len(u)

# Compute ||u|| and v.
v0 = math.sqrt(vecdot(u, u))
if (u[0] >= 0):
	v0 = -v0
v = [0] * height
v[0] = v0

# Compute axis = u - v.
axis = vecsub(u, v)

# Compute the Householder transformation.
[Q, sign] = householder_vector_to_Q(axis)

print_matrix(Q)
