I have a Fortran function like below,
subroutine f(i,weight)
integer(kind=i8) :: i
real(kind=r8) :: weight(i,i)
return
end
The matrix weight is a i by i matrix, and i is also an argument.
I want the same thing in Julia, I did below
function f(i::Int64, weight::Array{Float64,2}(undef,i,i))
return nothing
end
However it just give me an error,
UndefVarError: i not defined
But if I just do below without the weight matrix as an argument, it does not give error,
function f(i::Int64)
return nothing
end
But obviously this is not what I want.
Or, the following also no error,
function f(i::Int64, weight::Array{Float64,2})
return nothing
end
But this is not what I want. I want the weight matrix in the argument have particular dimensions i by i.
Do I have to do things like
function f(i::Int64, weight::Array{Float64,2})
weight = Array{Float64,2}(undef,i,i)
return nothing
end
But again, I want the weight in the argument have the i by i definition. How to do that in Julia?
Thank you very much indeed!
ias an argument? Why not just get it from the size of the matrix?i = size(weight, 1)should do the trick.