"""
Utilities for numbers
"""

import numpy as np, math
from numpy import linalg

def round_up(num, divisor):
	if num%divisor: return num - (num%divisor) + divisor
	else: return num - (num%divisor)

def round_down(num, divisor):
	return num - (num%divisor)

def angle_between_vectors(v1, v2, radian=True):
	n = linalg.norm(v1)*linalg.norm(v2)
	assert n != 0
	c = np.dot(v1,v2)/n
	angle = np.arccos(np.clip(c, -1, 1))
	if radian: return angle
	else: return np.rad2deg(angle)

def angle_between_matrices(m1, m2, col_major=True,  radian=True):
	""" Compute angle between rows/cols of two matrices """
	assert m1.shape == m2.shape
	angle_list = []
	if col_major:
		for i in range(m1.shape[1]):
			angle_list.append( angle_between_vectors(m1[:,i], m2[:,i], radian=radian) )
	else:
		for i in range(m1.shape[0]):
			angle_list.append( angle_between_vectors(m1[i,:], m2[i,:], radian=radian) )
	return angle_list



if __name__ == "__main__":
	a1 = np.array( [[1,0],[1,1]]   )
	a2 = np.array( [[-1,1],[-1,1]] )
	x = angle_between_vectors(a1, a2, radian=False)
	x = angle_between_matrices(a1,a2,col_major=False,radian=False)
	print(x)


