Error in method definition: function Base.sub2ind must be explicated imported


#1

Goode evening
I’m not familiar with Julia programming and I’m trying to run the code below that was made on Julia 0.4.5. I got two errors messages. I’m working on Julia 0.6.4 - Atom 1.29> I suppose I have to import something but I don’t know how the syntax should be. Can Somebody help?

Error in method definition: function Base.sub2ind must be explicited imported to be extended
Error in method definition: function Base.ind2sub must be explicited imported to be extended

unction sub2ind(feat_size,feat_ind)

#================================================================
Get the single index corresponding to the feature indices given
================================================================#

total_feat = length(feat_ind)

index = 0

for i in range(1,total_feat)
    if i < total_feat
        index = index +  (feat_ind[i]-1) * prod(feat_size[i+1:end])
    else
        index = index + (feat_ind[i]-1)
    end
end

return (index+1)

end

function ind2sub(feat_size,index)

#================================================================
Get the feature indices corresponding to the given index
================================================================#

last = length(feat_size);

subscripts = zeros(Int,length(feat_size))

index = index - 1

while last>=1
    subscripts[last]   = (index % feat_size[last]) + 1
    index              = floor(Int,index / feat_size[last])
    last               = last - 1;
end

return subscripts

end


#2

import Base: sub2ind, ind2sub


#3

Please quote your code and copy and paste full error messages precisely.


#4

Thanks. It works, but I got a new different error when I execute the script Run.jl

LoadError: UndefVarError: save not definede

while loading /Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/Takeoff/Run.jl, in expression starting on line 10

include_string(::String, ::String) at loading.jl:522

include_string(::Module, ::String, ::String) at Compat.jl:88

(::Atom.##112#116{String,String})() at eval.jl:109

withpath(::Atom.##112#116{String,String}, ::String) at utils.jl:30

withpath(::Function, ::String) at eval.jl:38

hideprompt(::Atom.##111#115{String,String}) at repl.jl:67

macro expansion at eval.jl:106 [inlined]

(::Atom.##110#114{Dict{String,Any}})() at task.jl:80

==============


#5

Here is the code of script Run.jl

‘’'using JLD2

include(“MonteCarlo.jl”)
include(“Abstraction.jl”)
include(“PlotMCSim.jl”)

Run Monte carlo trials with pilot

RunMCSim(1)
save("./PilotData.jld",“X”,X,“U”,U,“D”,D,“Tend”,Tend)

#PlotSim()
GetTransMat!(X,U,D,Tend,TM_P)

Run Monte carlo trials with envelope-aware controlle

RunMCSim(2)
save("./EAData.jld2",“X”,X,“U”,U,“D”,D,“Tend”,Tend)

#for i=1:trials
#PlotSim(i)
#end

GetTransMat!(X,U,D,Tend,TM_EA)

#===============================================
Use Pilot and Envelope-aware transition matrices
to construct transition matrices for actions
NOOP and TOGL
===============================================#

TM_NOOP = zeros(TotalN2,TotalN2)
TM_TOGL = zeros(TotalN2,TotalN2)

TM_NOOP[1:TotalN,1:TotalN] = TM_P[:,:]
TM_NOOP[TotalN+1:2TotalN,
TotalN+1:2
TotalN] = TM_EA[:,:]

TM_TOGL[1:TotalN,TotalN+1:2TotalN] = TM_EA[:,:]
TM_TOGL[TotalN+1:2
TotalN,1:TotalN] = TM_P[:,:]

writedlm(“TensorNOOP.txt”,TM_NOOP)
writedlm(“TensorTOGL.txt”,TM_TOGL)’’’


#6

Backticks (`, just to the left of the ‘1’ key on most keyboards) are different from single quotes (’). Please use backticks to quote your code as described in this post and check the result in the preview window.


#7

include("MonteCarlo.jl")
include("Abstraction.jl")
include("PlotMCSim.jl")


# Run Monte carlo trials with pilot
RunMCSim(1)
save("./PilotData.jld","X",X,"U",U,"D",D,"Tend",Tend)

#PlotSim()
GetTransMat!(X,U,D,Tend,TM_P)

# Run Monte carlo trials with envelope-aware controlle
RunMCSim(2)
save("./EAData.jld","X",X,"U",U,"D",D,"Tend",Tend)

#for i=1:trials
    #PlotSim(i)
#end

GetTransMat!(X,U,D,Tend,TM_EA)

#===============================================
Use Pilot and Envelope-aware transition matrices
to construct transition matrices for actions
NOOP and TOGL
===============================================#


TM_NOOP = zeros(TotalN*2,TotalN*2)
TM_TOGL = zeros(TotalN*2,TotalN*2)

TM_NOOP[1:TotalN,1:TotalN] = TM_P[:,:]
TM_NOOP[TotalN+1:2*TotalN,
        TotalN+1:2*TotalN] = TM_EA[:,:]

TM_TOGL[1:TotalN,TotalN+1:2*TotalN] = TM_EA[:,:]
TM_TOGL[TotalN+1:2*TotalN,1:TotalN] = TM_P[:,:]

writedlm("TensorNOOP.txt",TM_NOOP)
writedlm("TensorTOGL.txt",TM_TOGL```

#8

Is it ok ?


#9

No. You’re using backticks now, which is good, but not in the right way. See this post (again) for what it should look like and how to do it.


#10

I think, I finally understood. Can somebody help to fix the error in the code above. The error is:
UndefVarErrror: save not defined

while loading /Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/Takeoff/Run.jl, in expression starting on line 10
include_string(::String, ::String) at loading.jl:522
include_string(::Module, ::String, ::String) at Compat.jl:88
(::Atom.##112#116{String,String})() at eval.jl:109
withpath(::Atom.##112#116{String,String}, ::String) at utils.jl:30
withpath(::Function, ::String) at eval.jl:38
hideprompt(::Atom.##111#115{String,String}) at repl.jl:67
macro expansion at eval.jl:106 [inlined]
(::Atom.##110#114{Dict{String,Any}})() at task.jl:80```

#11

Probably missing using FileIO? See https://github.com/simonster/JLD2.jl/tree/v0.0.6#save-and-load-functions.