methods - Why does eye(size(X)) (where X is some array) throw an error? -


why can use

x = randn(size(y)); 

and

x = eye(size(y,1), size(y,2)); 

but not

x = eye(size(y)); 

? throws following error, don't understand:

error: eye has no method matching eye(::(int64,int64))

the error

error: eye has no method matching eye(::(int64,int64))

should tip off on nature of problem. when in doubt, have @ function's methods , check whether types align of them.

eye methods

you can list methods provided eye calling methods on it:

julia> methods(eye) # 7 methods generic function "eye": eye{t}(::type{diagonal{t}},n::int64) @ linalg/diagonal.jl:92 eye(t::type{t<:top},m::integer,n::integer) @ array.jl:176 eye(m::integer,n::integer) @ array.jl:182 eye(t::type{t<:top},n::integer) @ array.jl:183 eye(n::integer) @ array.jl:184 eye(s::sparsematrixcsc{tv,ti<:integer}) @ sparse/sparsematrix.jl:413 eye{t}(x::abstractarray{t,2}) @ array.jl:185 

do types align?

first, let's generate random data:

julia> y=rand(3,3) 3x3 array{float64,2}:  0.323068  0.759352   0.684859  0.357021  0.0706659  0.78324   0.128993  0.763624   0.458284 

so, why eye(size(y,1), size(y,2)) work? because both size(y,1) , size(y,2) of type int64,

julia> typeof(size(y,1)) int64  julia> typeof(size(y,2)) int64 

which subtype of integer,

julia> int64 <: integer true 

and eye provides method expects 2 arguments of type integer:

eye(m::integer,n::integer) 

and why does't eye(size(y)) work? because size returns pair,

julia> typeof(size(y)) (int64,int64) 

and eye provides no method takes pair argument.

relation currying

what need function f such that

f(eye)(size(y)) 

would equivalent to

eye(size(y,1), size(y,2)) 

you f uncurry eye. unfortunately you, julia devs have no plans introduce such function.

solution

anyway, you're overcomplicating things. there no need use size, here; applying eye array y produces desired result:

julia> eye(y) 3x3 array{float64,2}:  1.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  1.0 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -