Because size() doesn't work

I want to size the array dimensions which in this case are 5 and 6, but I don’t know why it doesn’t

A=zeros(5,6)
size(A)

and I get the following error

MethodError: objects of type Tuple{Int64,Int64} are not callable

I think something in your environment overwrote the size() method. On my machine with 1.4.1:

julia> A=zeros(5,6)
5×6 Array{Float64,2}:
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0

julia> size(A)
(5, 6)

Try starting a clean session and retry it…

1 Like

If you type size you’ll probably see a 2-item tuple returned. Maybe sometime earlier you wrote size = size(A)?

Thanks restart julia I solve it, sometimes julia goes crazy, it could also be for having written this

size = width, height = 600, 600
1 Like

yep, that would definitely do it

you could still use Base.size, but the better answer is to not call variables size.

3 Likes

Note that this same problem happens if you have a line like size = size(...) in a function. And the error message that you get is a bit confusing:

julia> function foo()
           size = size([1, 2])
       end
foo (generic function with 1 method)

julia> foo()
ERROR: UndefVarError: size not defined

It’s even more confusing if first you call size() in a function and then later assign to a variable called size in the same function:

julia> function bar()
           s = size([1, 2])
           size = 1
           return nothing
       end
bar (generic function with 1 method)

julia> bar()
ERROR: UndefVarError: size not defined

This is an example of the effect proceeding the cause. Basically, if you assign to a local variable size anywhere inside a function, then the compiler treats each instance of size within that function scope as a local variable, even if an instance of size proceeds the local variable assignment.

6 Likes