Hi, I’m just starting out with Julia and ran into a weird issue. I defined a function that can take float values (fp32 or fp64, but strictly no int) as follows
function elim(A::Array{float},b::Array{float})
#=
Function which transforms matrix
A into upper triangular matrix U
=#
n = size(b)[1]
# Pick a pivot row
for k in 1:n-1
for i in k+1:n
if A[i,k] != 0
lambda = A[i,k]/A[k,k]
A[i,k+1:n] -= lambda*A[k,k+1:n]
b[i,:] -= lambda*b[k,:]
end
end
end
return A, b
end
Now when I call this function and give inputs as Float32
A = [[6, -4, 1] [-4, 6, -4] [1, -4, 6]]
b = [[-14, 36, 6] [22, -18, 7]];
A = Float32.(A)
b = Float32.(b);
U, b_t = elim(A,b)
show(stdout, "text/plain", U)
println()
show(stdout, "text/plain", b_t)
I get an error saying
MethodError: no method matching elim(::Array{Float32,2}, ::Array{Float32,2})
Stacktrace:
[1] top-level scope at In[3]:1
[2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091
I get the same error when I input Float64. Is there any way that I can define a function that takes both Float32 and Float64? I don’t want to define two separate functions as it’ll just clutter everything for no reason.