Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndefVarError: .+ not defined #24

Closed
ValeriiBaidin opened this issue May 28, 2020 · 27 comments
Closed

UndefVarError: .+ not defined #24

ValeriiBaidin opened this issue May 28, 2020 · 27 comments

Comments

@ValeriiBaidin
Copy link

julia ver. 1.1.1

UndefVarError: .+ not defined

Stacktrace:
 [1] update_elbo!(::LDA) at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/LDA.jl:91
 [2] LDA(::TopicModelsVB.Corpus, ::Int64) at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/LDA.jl:42
 [3] top-level scope at In[35]:1
@ericproffitt
Copy link
Owner

Hi Valerii,

Can you please provide me with a minimal code sample with which I can replicate this error.

@ValeriiBaidin
Copy link
Author

I don't have problem on my computer. It works perfectly. But on server, I have these errors.
I will give little example later. That code is too big to copy.
model = LDA(corpus_t, 10)

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

If it works on your computer, but not on your server, then it may have to do with the Linux distribution of Julia.

If I'm not able to replicate the error on my computer, then it may be difficult or impossible for me to fix.

Have you tried upgrading Julia to the latest version, to see if that fixes it?

@ValeriiBaidin
Copy link
Author

If it works on your computer, but not on your server, then it may have to do with the Linux distribution of Julia.

If I'm not able to replicate the error on my computer, then it may be difficult or impossible for me to fix.

Yes, I understand it.

But do you know your code in the lines? What can cause the error?

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

So that line is modified by an internal macro. The code is,

@positive model.phi[1] = model.beta_old[:,terms] .* exp.(model.Elogtheta_old[d])

Which should result in the following expression at compile time,

model.phi[1] = EPSILON .+ model.beta_old[:,terms] .* exp.(model.Elogtheta_old[d])

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

Are you able to to perform coordinate-wise addition of a scalar with an array on your server's version of Julia?

@ValeriiBaidin
Copy link
Author

Maybe it can be useful

WARNING: Method definition additive_logistic(Array{#s17, 2} where #s17<:Real) in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:113 overwritten at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:135.
WARNING: Method definition binomlogpdf(Real, Real, Real) in module StatsFuns at /home/vbaidin/.julia/packages/StatsFuns/CXyCV/src/distrs/binom.jl:19 overwritten in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:164.
WARNING: Method definition entropy(Distributions.Dirichlet{T} where T<:Real) in module Distributions at /home/vbaidin/.julia/packages/Distributions/ZJ0hQ/src/multivariate/dirichlet.jl:118 overwritten in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:168.
WARNING: Method definition (::Type{TopicModelsVB.Corpus})(Array{TopicModelsVB.Document, 1}) in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:76 overwritten at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:77.
WARNING: Method definition (::Type{TopicModelsVB.Corpus})(TopicModelsVB.Document) in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:78 overwritten at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:79.

@ValeriiBaidin
Copy link
Author

this is a simple exercise, with the same problem

c= Corpus([Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),
            Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),
            Document([7,7,7]),Document([7,7,7]),Document([7,7,7]),Document([7,7,7])],
            vocab = split("1 2 3 4 5 6 7"))
model = LDA(c, 2)

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

c= Corpus([Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),
            Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),
            Document([7,7,7]),Document([7,7,7]),Document([7,7,7]),Document([7,7,7])],
            vocab = split("1 2 3 4 5 6 7"))
model = LDA(c, 2)

This code works fine for me on the MacOS distribution of Julia 1.4.2.

@ValeriiBaidin
Copy link
Author

c= Corpus([Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),
            Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),
            Document([7,7,7]),Document([7,7,7]),Document([7,7,7]),Document([7,7,7])],
            vocab = split("1 2 3 4 5 6 7"))
model = LDA(c, 2)

This code works fine for me on the MacOS distribution of Julia 1.4.2.

it works on Julia 1.3 on my PC.

So is the problem of Julia 1.1.1? Can I do something to patch it?

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

If you unable to upgrade your server's version of Julia (which may or may not fix the problem), then patching your copy of TopicModelsVB.jl will be difficult if the problem is the element-wise addition operator, since that operator is used in many places in the source code.

So even if you manually fix this particular line, the error will just then pop up somewhere else. Can you please run the following code on your server, and let me know if it works:

3 .+ [1 2; 3 4]

@ValeriiBaidin
Copy link
Author

If you unable to upgrade your server's version of Julia (which may or may not fix the problem), then patching your copy of TopicModelsVB.jl will be difficult if the problem is the element-wise addition operator, since that operator is used in many places in the source code.

So even if you manually fix this particular line, the error will just then pop up somewhere else. Can you please run the following code on your server, and let me know if it works:

3 .+ [1 2; 3 4]

Thank you for your help.

it works perfectly.

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

Ok, now can you please try this code:

EPSILON = 1

macro positive(expr::Expr)
	"Add EPSILON to a numerical variable or array during variable assignment."

	if (expr.head == :.) || (expr.head == :ref)
		expr_out = :(:($($expr)) .+= EPSILON)
	
	elseif expr.head == :(=)
		expr_out = :(:($($(expr.args[1]))) = EPSILON .+ :($($(expr.args[2]))))
	end

	return expr_out
end

@positive x = 3

The result should be 4.

And then if that works, try this:

@positive x = [1 2; 3 4]

@ValeriiBaidin
Copy link
Author

Ok, now can you please try this code:

EPSILON = 1

macro positive(expr::Expr)
	"Add EPSILON to a numerical variable or array during variable assignment."

	if (expr.head == :.) || (expr.head == :ref)
		expr_out = :(:($($expr)) .+= EPSILON)
	
	elseif expr.head == :(=)
		expr_out = :(:($($(expr.args[1]))) = EPSILON .+ :($($(expr.args[2]))))
	end

	return expr_out
end

@positive x = 3

The result should be 4.

And then if that works, try this:

@positive x = [1 2; 3 4]

the same error

UndefVarError: .+ not defined

Stacktrace:
 [1] top-level scope at In[6]:15

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

Which gave you the error, @positive x = 3 or @positive x = [1 2; 3 4]?

@ValeriiBaidin
Copy link
Author

ValeriiBaidin commented May 28, 2020

Which gave you the error, @positive x = 3 or @positive x = [1 2; 3 4]?

The first, I can't even define the macro

@ericproffitt
Copy link
Owner

Ok, so this is something I will need to discuss with the Julia Dev team, and then I can get back to you hopefully with a solution at a future date.

In the mean time, my only suggestion is to try upgrading Julia to the latest version (if you can), as that may fix the issue.

@ValeriiBaidin
Copy link
Author

Thank.
Unfortunately, I can't update it right now. =(

Thank you for your help.

@ValeriiBaidin
Copy link
Author

macro test_macro(e::Expr)
    return esc( :( ones(size($e)[1]) .+ $e) )
end

@test_macro [1 2 ; 3 4]

This code works on Julia ver 1.1.1

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

Could you try out the following code on your command line:

macro positive(expr::Expr)
	"Add EPSILON to a numerical variable or array during variable assignment."

	if (expr.head == :.) || (expr.head == :ref)
		expr_out = :($expr .+= EPSILON)
	
	elseif expr.head == :(=)
		expr_out = :($(expr.args[1]) = EPSILON .+ $(expr.args[2]))
	end

	return expr_out
end

If it works, then you could try patching the macros.jl file by replacing the positive macro with the above.

It appears to be working for my preliminary tests, but I'll need to test it further before I open a PR.

@ValeriiBaidin
Copy link
Author

ValeriiBaidin commented May 28, 2020

Try out the following code on your command line:

macro positive(expr::Expr)
	"Add EPSILON to a numerical variable or array during variable assignment."

	if (expr.head == :.) || (expr.head == :ref)
		expr_out = :($expr .+= EPSILON)
	
	elseif expr.head == :(=)
		expr_out = :($(expr.args[1]) = EPSILON .+ $(expr.args[2]))
	end

	return expr_out
end

If it works, then you could try patching the macros.jl file by replacing the positive macro with the above.

It appears to be working for my preliminary tests, but I'll need to test it further before I open a PR.

Unfortunately, it doesn't work.
But the next code works!!!!

EPSILON = 1
macro positive(expr::Expr)
	"Add EPSILON to a numerical variable or array during variable assignment."
	if (expr.head == :.) || (expr.head == :ref)
		expr_out =  :($expr .+= EPSILON)
	
	elseif expr.head == :(=)
		expr_out =  :($(expr.args[1]) = EPSILON .+ $(expr.args[2])) 
	end
	return  esc( expr_out )
end

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

Ok so I did find this related dicussion concerning unresolved issues in Julia's metaprogramming functionality.

If escaping the return value is what's fixing the problem for you, then a potential patch would be to go into macros.jl and replace return expr_out with return esc(expr_out) for the following macros:

macro juliadots(str::String)
macro juliadots(expr::Expr)
macro boink(expr::Expr)
macro positive(expr::Expr)
macro finite(expr::Expr)

@ericproffitt
Copy link
Owner

ericproffitt commented May 28, 2020

Ok, so I've modified the offending macros.

You can see the changes made here fcd6f8d.

Could you let me know if this fixes the problem for you?

@ValeriiBaidin
Copy link
Author

ValeriiBaidin commented May 29, 2020

Ok, so I've modified the offending macros.

You can see the changes made here fcd6f8d.

Could you let me know if this fixes the problem for you?

thank you.

Shall I replace only macro.jl file, or should I update the whole package?

P.S. right now, I am working with my hand fixing macro. jl

@ericproffitt
Copy link
Owner

The changes have been committed to the master branch.

So if you just run,

pkg> add https://github.com/ericproffitt/TopicModelsVB.jl

Then you should be good to go, no need to modify the macros.jl file yourself.

@ValeriiBaidin
Copy link
Author

The changes have been committed to the master branch.

So if you just run,

pkg> add https://github.com/ericproffitt/TopicModelsVB.jl

Then you should be good to go, no need to modify the macros.jl file yourself.

Thank you, I will check a lit bit later.

Thank you so much

@ericproffitt
Copy link
Owner

I'm going to close this issue, if you're still having problems with the macro functionality, please feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants