#  JLMatrix - Matrix support for JRuby
#  Copyright (C) 2008 Approximatrix, LLC
#  http://www.approximatrix.com
#  
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#  NOTE: This software is licensed under the GPL and does not allow
#        linking to closed-source software.
#

# Extends some functions in math
module Math

	alias_method :sqrt_original, :sqrt

	def sqrt(*args)
		if(args.length == 1) 
			x = args[0]
			if(x.is_a? Array)  
				sqrt(*x)
			elsif(x.is_a? Vector)
			  ele = []
			  x.each do |one|
			    ele <<  sqrt(one)
			  end
			  Vector.elements(ele, copy=false)
			elsif(x.is_a? Matrix)
				newcol = []
				x.column_vectors.each do |vec|
					newcol << sqrt(vec)
				end
				Matrix.columns(newcol)
			else
				sqrt_original(x)
			end
		else
			ret = []
			args.each do |x|
				ret << sqrt(x)
			end
			ret
		end
	end

end 