# Oscar and Matlab both call nrows

**URL:** <https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157>\
**Category:** General Usage\
**Tags:** question, package, matlab, warning, algebra\
**Created:** [May 12, 2024, 4:58am UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157 "2024-05-12T04:58:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilovemath](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@ilovemath](https://discourse.julialang.org/u/ilovemath)\
**Post date:** [May 12, 2024, 4:58am UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/1 "2024-05-12T04:58:04Z")

</div>

Hi there,

So, I am calling both Oscar and Matlab packages. Both call nrows in their subroutines under the hood in their often typical function calls. I was able to write the code so that I would not get the warning saying both Oscar and Matlab call nrows (which would lead to the code crashing immediately). However, the minute I wrap my perfectly functional code in a function format then call said function (to ensure that my looping does not adjust global variables when calling the script), it gives the nrows double label warning, and the code crashes. I am calling SymbolicWedderburn to automatically rotate a polynomial, and this is what is causing the issue.

This question is similar to [this question](https://discourse.julialang.org/t/functions-from-different-modules-with-the-same-name/61505/15). The reason this is different is I am not specifically calling the doubly named subroutine, which makes this a much trickier problem to solve. I am hoping there is an easy hack to fix this, because it does seem to be pretty artificial. Thanks.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 12, 2024, 5:21am UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/2 "2024-05-12T05:21:26Z")

</div>

It would be slightly easier to understand your problem if you showed us the some example code demonstrating the issue as well as the full error that you receive.

What I’m understanding is that there is an `Oscar.nrows` and `Matlab.nrows` function, which they both try to export. If you load them via `import` rather than `using`, you can avoid the name collision. To refer to either `nrows`, you could then fully qualify which function you are referring to.

```julia
module ModuleWhereYouNeedImportBothOscarAndMatlab
    import Oscar
    import Matlab

    function foo(...)
        Oscar.nrows(...)
        Matlab.nrows(...)
    end
end

```

---

<div class="post-metadata">

**Author:** ![ilovemath](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@ilovemath](https://discourse.julialang.org/u/ilovemath)\
**Post date:** [May 12, 2024, 5:29pm UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/3 "2024-05-12T17:29:12Z")

</div>

You interpreted my problem completely correctly, the error was the standard error from the linked post.

I am still having some trouble in my for loop with this as I am generally because decided to be “using Oscar” and just “import MATLAB”, due to frequency of usage. The new error is

```julia
LoadError: MethodError: no method matching (::Colon)(::Int64, ::typeof(nrows))

Closest candidates are:
  (::Colon)(::Integer, ::Any, ::ZZRingElem)
   @ Nemo ~/.julia/packages/Nemo/Tj33G/src/HeckeMiscInteger.jl:471
  (::Colon)(::T, ::Any, ::T) where T<:Real
   @ Base range.jl:45
  (::Colon)(::A, ::Any, ::C) where {A<:Real, C<:Real}
   @ Base range.jl:10

```

I am hoping that it should be fixable if I just change to importing Oscar throughout, the only annoyance is that is going to take forever because it is buried in multiple commands in two separate scripts (hence why I did not include a minimal example). If I fix this when I can get back to it in a couple hours then I will edit this post. Thanks for helping the scientific computer 🙂

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 12, 2024, 6:56pm UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/4 "2024-05-12T18:56:29Z")

</div>

What is the line that caused the error?

---

<div class="post-metadata">

**Author:** ![ilovemath](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@ilovemath](https://discourse.julialang.org/u/ilovemath)\
**Post date:** [May 12, 2024, 7:42pm UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/5 "2024-05-12T19:42:43Z")

</div>

poly\_90 = SymbolicWedderburn.action(NinetyRot(), CyclicGroupElement(1, G90), poly)

For some polynomial poly. This polynomial changes at each iteration in the for loop, hence why I have this wrapped in a function to make sure it’s a local declaration.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 12, 2024, 8:42pm UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/6 "2024-05-12T20:42:38Z")

</div>

You have cut off the error message, so it is hard to understand how this error occurred. Please include the whole thing.

At the moment, `(::Colon)(::Int64, ::typeof(nrows))` implies you are trying to invoke something as follows.

```julia
julia> 1:nrows
ERROR: MethodError: no method matching (::Colon)(::Int64, ::typeof(nrows))

```

I cannot tell where that might be from your error message, but something is very wrong.

It appears that at some point you tried to use `nrows` as a variable when it is a function.

If you are trying to use it as a variable, consider changing the name of the variable. For example use `N_rows` or `_nrows`.

---

<div class="post-metadata">

**Author:** ![ilovemath](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@ilovemath](https://discourse.julialang.org/u/ilovemath)\
**Post date:** [May 12, 2024, 9:26pm UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/7 "2024-05-12T21:26:25Z")

</div>

Yeah, this why I don’t generally debug live in a chat haha. I did send the whole error minus the stacktrace, but here is the stacktrace for reference.

```julia
Stacktrace:
  [1] action(#unused#::NinetyRot, el::CyclicGroupElement, mono::Monomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}})
    @ Main ~/Documents/Code/JULIA_SOS_Couette/patternGen.jl:8
  [2] action(a::NinetyRot, el::CyclicGroupElement, term::Term{AffExpr, Monomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}})
    @ SumOfSquares.Certificate.Symmetry ~/.julia/packages/SumOfSquares/xNLIR/src/Certificate/Symmetry/wedderburn.jl:43
  [3] (::SumOfSquares.Certificate.Symmetry.var"#11#12"{NinetyRot, CyclicGroupElement})(term::Term{AffExpr, Monomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}})
    @ SumOfSquares.Certificate.Symmetry ./none:0
  [4] iterate
    @ ./generator.jl:47 [inlined]
  [5] collect
    @ ./array.jl:782 [inlined]
  [6] action(a::NinetyRot, el::CyclicGroupElement, poly::Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, AffExpr})
    @ SumOfSquares.Certificate.Symmetry ~/.julia/packages/SumOfSquares/xNLIR/src/Certificate/Symmetry/wedderburn.jl:51
  [7] main()
    @ Main ~/Documents/Code/JULIA_SOS_Couette/main_noTailSplit_forIteration.jl:177
  [8] top-level scope
    @ ~/Documents/Code/JULIA_SOS_Couette/main_noTailSplit_forIteration.jl:413
  [9] include(fname::String)
    @ Base.MainInclude ./client.jl:478
 [10] top-level scope
    @ REPL[1]:1
in expression starting at /Users/elizabethc/Documents/Code/JULIA_SOS_Couette/main_noTailSplit_forIteration.jl:413

```

I know this is a stupid error, and I am not trying to invoke anything like 1:nrows without specifying nrows. I do have nrows stated throughout the code separately (it was this way before I knew MATLAB and Oscar called it under the hood), but I do not get this error in the original code without the loop (the loop is not over nrows). This simply means something very stupid is happening, and I just need to dig through the code with and without iterations with a vimdiff, it’s probably minor error somewhere with the way I wrapped things so I can run this code for multiple iterations. I reran it, using “import MAT” instead of “using MAT” (for the purpose of writing to .mat files, yes there’s a reason for this) and now it is simply giving me the following error:

```julia
ERROR: LoadError: UndefVarError: `nrows` not defined
Stacktrace:
  [1] action(#unused#::NinetyRot, el::CyclicGroupElement, mono::Monomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}})
    @ Main ~/Documents/Code/JULIA_SOS_Couette/patternGen.jl:8
  [2] action(a::NinetyRot, el::CyclicGroupElement, term::Term{AffExpr, Monomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}})
    @ SumOfSquares.Certificate.Symmetry ~/.julia/packages/SumOfSquares/xNLIR/src/Certificate/Symmetry/wedderburn.jl:43
  [3] #11
    @ ~/.julia/packages/DynamicPolynomials/MqIhr/src/mono.jl:0 [inlined]
  [4] iterate
    @ ./generator.jl:47 [inlined]
  [5] collect(itr::Base.Generator{DynamicPolynomials.TermIterator{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, AffExpr}, SumOfSquares.Certificate.Symmetry.var"#11#12"{NinetyRot, CyclicGroupElement}})
    @ Base ./array.jl:782
  [6] action(a::NinetyRot, el::CyclicGroupElement, poly::Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, AffExpr})
    @ SumOfSquares.Certificate.Symmetry ~/.julia/packages/SumOfSquares/xNLIR/src/Certificate/Symmetry/wedderburn.jl:51
  [7] main()
    @ Main ~/Documents/Code/JULIA_SOS_Couette/main_noTailSplit_forIteration.jl:177
  [8] top-level scope
    @ ~/Documents/Code/JULIA_SOS_Couette/main_noTailSplit_forIteration.jl:413
  [9] include(fname::String)
    @ Base.MainInclude ./client.jl:478
 [10] top-level scope
    @ REPL[1]:1
in expression starting at /Users/elizabethc/Documents/Code/JULIA_SOS_Couette/main_noTailSplit_forIteration.jl:413

```

Again, the stacktrace is not particularly helpful other than it is very unhappy about something on that line. This does not occur in a nearly identical copy of this script without file writing. Means I probably have a small typo somewhere.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 12, 2024, 11:29pm UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/8 "2024-05-12T23:29:57Z")

</div>

What is `~/Documents/Code/JULIA_SOS_Couette/patternGen.jl:8`?

To clarify Matlab.jl and Oscars.jl call their `nrows` function within their packages, and they also export the `nrows` function. The exported `nrows` only gets imported into your namespace if you invoke `using Matlab` or if you explicitly `import` it.

Now that I know you actually have a third variable called `nrows` that is not supposed to be invoking `nrows` from a package, my recommendation is to rename your variable.

My current guess is that you have a situation like this.

```julia
L = nrows
for i = 1:L
end

```

---

<div class="post-metadata">

**Author:** ![ilovemath](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@ilovemath](https://discourse.julialang.org/u/ilovemath)\
**Post date:** [May 13, 2024, 11:43pm UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/9 "2024-05-13T23:43:59Z")

</div>

patternGen.jl is a separate external script I call that does not use Oscar or MATLAB.

I narrowed the error down to the following:

If I run

```julia
import MATLAB 
import Oscar

**some code creating polynomials bases using Oscar**

**a bunch of code not using Oscar, only SymbolicWedderburn and GroupsCore on polynomials built from base in previous block of code**

```

Then, if I instead write this as

```julia
import MATLAB 
import Oscar

**some code creating polynomials bases using Oscar**

function main()
     **same bunch of code not using Oscar, only SymbolicWedderburn and GroupsCore on polynomials built from base in previous block of code**
end
main()

```

then I get the error that there do not exist nrows, occurring on the line  
polyT = SymbolicWedderburn.action(NinetyRot(), CyclicGroupElement(1, G90), poly).

It doesn’t matter whether or not I rename my personal nrows variable.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 14, 2024, 3:42am UTC](https://discourse.julialang.org/t/oscar-and-matlab-both-call-nrows/114157/10 "2024-05-14T03:42:46Z")

</div>

The stack trace suggests that there is a reference to `nrows` on Line 8 of `~/Documents/Code/JULIA_SOS_Couette/patternGen.jl`.

```julia
[1] action(#unused#::NinetyRot, el::CyclicGroupElement, mono::Monomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}})
    @ Main ~/Documents/Code/JULIA_SOS_Couette/patternGen.jl:8

```
