Error on incompatibility of matrix multiplications

I wrote a code where I have many matrix multiplications. While running the code after opening Julia1.0.4, I got an error that the matrix sizes are incompatible. However, when I ran the code for the second time, the error is gone. Moreover, in the first run, when I displayed the sizes of the matrices for which I got the error, the code was running without any error.

Here is how the error can be regenerated:

  • open Julia.
    -include the code (you need to also include the data by adjusting the code)
    then you will get:

julia> include(“C:/…/debug.jl”)
(5, 45)
ERROR: LoadError: DimensionMismatch(“second dimension of A, 45, does not match length of x, 55”)
[1] gemv!(::Array{Float64,1}, ::Char, ::Array{Float64,2}, ::Array{Float64,1}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\LinearAlgebra\src\matmul.jl:349
[2] mul! at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\LinearAlgebra\src\matmul.jl:64 [inlined]
[3] *(::Array{Float64,2}, ::Array{Float64,1}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\LinearAlgebra\src\matmul.jl:46
[4] top-level scope at C:\Users\20176914\surfdrive\scientific\Codes\Julia\Spare-Part\debug.jl:168
[5] include at .\boot.jl:317 [inlined]
[6] include_relative(::Module, ::String) at .\loading.jl:1044
[7] include(::Module, ::String) at .\sysimg.jl:29
[8] include(::String) at .\client.jl:392
[9] top-level scope at none:0
in expression starting at C:\Users\20176914\surfdrive\scientific\Codes\Julia\Spare-Part\debug.jl:129

Now if you run it again, there won’t be any error. Now close Julia and open it again. Then, include the same code while including lines 103, 104, 105, 106. Surprising you don’t get any error!!!
Code link:

Data link:

So, it is a bug or am I missing something?
I would appreciate if I can get any help.

Here is also the version info:

julia> versioninfo()
Julia Version 1.0.4
Commit 38e9fb7f80 (2019-05-16 03:38 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel® Core™ i5-7300U CPU @ 2.60GHz
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

Most likely it is a bug in your code. You could try writing small and simple functions — it is the idiomatic style in Julia — and wrap nontrivial code (such as the last let block) in a function, too.

Also, please use standard indentation (4 spaces).

This post was temporarily hidden by the community for possibly being off-topic, inappropriate, or spammy.

Most likely it is a bug in your code

Well, that is what I thought, and I am working in the past two weeks to figure out. Unfortunately, the bug is weird as it appears only in the first run!

You could try writing small and simple functions
well, this is a small function got from 4000 lines of code!

please use standard indentation (4 spaces): that is a fair point, but that shouldn’t change the output, should it?

no, but it would make it easier for others to read your code.

1 Like