@yuyichao So you’re saying `perm`

necessarily has to be an ordered basis and cannot be a set?

# The `perm`of `permutedims(A,perm)`

**hpoit**#1

**yuyichao**#2

Well, that sounds reasonable because the unordered set is always the same anyway. I don’t remember when/where/in which context I said that though.

**hpoit**#3

You didn’t say it, but this is the context. If an ordered basis is the case, then `permute_dims`

is ordered. I don’t understand what’s missing for `permutedims()`

to work.

**yuyichao**#4

I don’t think I mentioned anything about ordering at all. The input type is simply wrong.

**hpoit**#5

Right, I brought up ordering. The input type is the same as the one from `permutedims()`

in this other block, which passes. Should both `permutedims()`

not be `Vector{Int}`

? I don’t understand why not, from the definition of `perm`

below

```
help?> permutedims
search: permutedims permutedims! ipermutedims
permutedims(A, perm)
Permute the dimensions of array A. perm is a vector specifying a permutation
of length ndims(A). This is a generalization of transpose for
multi-dimensional arrays. Transpose is equivalent to permutedims(A, [2,1]).
```
```

**yuyichao**#7

And this is also why I posted the code in the one of the replies showing that the type is wrong.

**hpoit**#8

Do you mean `[Remain_dims,Remove_dims]`

is a 2x2 matrix? If yes, how do I turn it into an ordered vector? I’m sorry, thanks for the patience…

**yuyichao**#9

No, it’s a `Vector`

of `Vector`

.

That’s exactly the code I posted, on the julia-users thread.

```
julia> [[1]]
1-element Array{Array{Int64,1},1}:
[1]
julia> [[1];]
1-element Array{Int64,1}:
1
```

And for more than one element to concatenate

```
julia> [[1]; [2, 3]]
3-element Array{Int64,1}:
1
2
3
```

**hpoit**#10

Thanks, I switched it to `[Remain_dims;Remove_dims]`

… but now I got this

```
julia> Pkg.test("BN")
INFO: Testing BN
WARNING: Method definition (::Type{BN.Factor})(Array{String, 1}, Array{Int64, 1}, Array{Float64, 1}) in module BN at /Users/Corvus/.julia/v0.5/BN/src/Factor.jl:9 overwritten at /Users/Corvus/.julia/v0.5/BN/src/Factor.jl:9.
Test Summary: |
Define Factor arguments, create instances, permute Factor | No tests
Multiply and marginalize factor: Error During Test
Got an exception of type ArgumentError outside of a @test
ArgumentError: reduced dimension(s) must be integers
in reduced_dims(::Tuple{Int64,Int64,Int64}, ::Array{UnitRange{Int64},1}) at ./reducedim.jl:39
in reducedim_initarray(::Array{Float64,3}, ::Array{UnitRange{Int64},1}, ::Float64, ::Type{Float64}) at ./reducedim.jl:85
in mapreducedim at ./reducedim.jl:253 [inlined]
in sum at ./reducedim.jl:303 [inlined]
in sum(::Array{Float64,3}, ::Array{UnitRange{Int64},1}) at ./reducedim.jl:305
in FactorMargin(::BN.Factor, ::Array{String,1}, ::Array{String,1}, ::Array{Int64,1}, ::Array{Int64,1}) at /Users/Corvus/.julia/v0.5/BN/src/FactorOperations.jl:71
in FactorDropMargin(::BN.Factor, ::Array{String,1}) at /Users/Corvus/.julia/v0.5/BN/src/FactorOperations.jl:87
in macro expansion; at /Users/Corvus/.julia/v0.5/BN/test/runtests.jl:19 [inlined]
in macro expansion; at ./test.jl:672 [inlined]
in anonymous at ./<missing>:?
in include_from_node1(::String) at ./loading.jl:488
in include_from_node1(::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
in process_options(::Base.JLOptions) at ./client.jl:262
in _start() at ./client.jl:318
in _start() at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
Test Summary: | Error Total
Multiply and marginalize factor | 1 1
ERROR: LoadError: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.
in finish(::Base.Test.DefaultTestSet) at ./test.jl:495
in macro expansion; at ./test.jl:679 [inlined]
in anonymous at ./<missing>:?
in include_from_node1(::String) at ./loading.jl:488
in include_from_node1(::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
in process_options(::Base.JLOptions) at ./client.jl:262
in _start() at ./client.jl:318
in _start() at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
while loading /Users/Corvus/.julia/v0.5/BN/test/runtests.jl, in expression starting on line 14
=================================[ ERROR: BN ]==================================
failed process: Process(`/Applications/Julia-0.5.app/Contents/Resources/julia/bin/julia -Ccore2 -J/Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib --compile=yes --depwarn=yes --check-bounds=yes --code-coverage=none --color=yes --compilecache=yes /Users/Corvus/.julia/v0.5/BN/test/runtests.jl`, ProcessExited(1)) [1]
================================================================================
ERROR: BN had test errors
in #test#61(::Bool, ::Function, ::Array{AbstractString,1}) at ./pkg/entry.jl:740
in (::Base.Pkg.Entry.#kw##test)(::Array{Any,1}, ::Base.Pkg.Entry.#test, ::Array{AbstractString,1}) at ./<missing>:0
in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}})() at ./pkg/dir.jl:31
in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}}, ::String) at ./file.jl:59
in #cd#1(::Array{Any,1}, ::Function, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./pkg/dir.jl:31
in (::Base.Pkg.Dir.#kw##cd)(::Array{Any,1}, ::Base.Pkg.Dir.#cd, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./<missing>:0
in #test#3(::Bool, ::Function, ::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258
in test(::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258
julia>
```
[Factor.jl:9](https://github.com/hpoit/MLN.jl/blob/master/BN/src/Factor.jl#L9)
[FactorOperations.jl:71](https://github.com/hpoit/MLN.jl/blob/master/BN/src/FactorOperations.jl#L71)
[FactorOperations.jl:87](https://github.com/hpoit/MLN.jl/blob/master/BN/src/FactorOperations.jl#L87)
Your help is much appreciated, Yichao.
```

**yuyichao**#11

The backtrace was printed for a reason and you should use it to figure out how you are using the functions wrong. The method signature printed in this function that’s the first Base function you called in the backtrace should show clearly that you are giving `sum`

the wrong type as `dims`

. Note that the same wrong parameter is also passed to `squeeze`

below, which expects a tuple.

**hpoit**#12

Thanks Yichao. I’m not sure if I should just sum the `permuted_valuespace`

by the `Remain_dims`

to make sense. Factor marginalization here is just the sum over the relevant variables (`Remain_var`

).

To me this makes more sense, but I’m not sure

```
# Factor marginalization: computes the factor without the non-relevant variables (Remove_var)
function FactorMargin(A::Factor, Remove_var::Vector{String}, Remain_var::Vector{String}, Remove_dims::Vector{Int}, Remain_dims::Vector{Int})
Remain_card = A.card[Remain_dims]
valuespace = reshape(A.value, A.card...)
permute_dims = [Remain_dims;Remove_dims]
permuted_valuespace = permutedims(valuespace, permute_dims)
# squeeze_dims = [length(Remain_dims)+1:length(permute_dims)] (I would delete this line)
sumvaluespace = sum(permuted_valuespace, Remain_dims) # changed for Remain_dims
Remain_valuespace = squeeze(sumvaluespace, Remove_dims) # changed for Remove_dims
Factor(Remain_var, Remain_card, Remain_valuespace[:])
end
```

This is my reference.

FactorProduct.m

IndexToAssignment.m

AssignmentToIndex.m

**hpoit**#13

Also, some days past I was having a bad one and I

```
julia> include("/Users/Corvus/.julia/v0.5/BN/src/BN.jl")
julia> include("/Users/Corvus/.julia/v0.5/BN/src/Factor.jl")
julia> include("/Users/Corvus/.julia/v0.5/BN/test/runtests.jl")
julia> Package.test("BN")
ERROR: UndefVarError: Package not defined
```
... even though the BN folder is already exists, in `.julia/v0.5/BN`.
I don't know how to get back to using `.julia/v0.5/BN`.
```

**yuyichao**#14

I’m pretty sure `squeeze`

needs a tuple instead of a vector (and this operation is inherently type unstable if you pass in Vector as the dimensions)

Where did you get the `Package`

from? Please read the actual error more carefully since I think this one should be pretty clear from the error message. The package module in base is called `Pkg`

.

Using `include`

like that also won’t do anything about `Pkg.test`

. The tests are run in a script and has nothing to do with the calling process.

**hpoit**#15

Sorry, I didn’t pay attention to `Package`

.

The tuple is a non-issue, I agree. Does the logic of any version of the function make sense to you?