Implementation of Octave functions in Julia

Hello everyone,

I wonder if there is a way to implement Matlab functions via Octave in Julia. I know there exists Matlab.jl but for using it you need to install a Matlab version in your computer.

I ask this question because I want to use a library for robotic learning only available as Matlab/Octave. The idea is to implement it as completely free open-source code without the need of reimplementations.

I will be very grateful if you could help me :slight_smile:

2 Likes

Maybe this question is too obvious, but… if you wan to use a library available for Matlab/Octave in a “completely free open-source code without the need of reimplementations”, why don’t just use Octave?

Octave is completely free open-source, and you woudn’t need to reimplement anything. I’m pretty sure that using the library directly in Octave will work far better than trying to use Julia or any other engine with Octave code, except maybe Matlab.

EDIT: After re-reading, I understand your point better: You want to use the Octave functions as part of your study, but the rest you want to do it in Julia, right?

If that’s the case, I don’t know of a straightforward solution. There have been some attempts in the past, e.g. MatlabCompat.jl, but I don’t know of any one which has not been abandoned. If you say what’s the library you want to use, maybe someone can tell if there is a convenient alternative for Julia.

2 Likes

Hi @heliosdrm, thanks for your answer.

Indeed, I would like to build a benchmark in Julia. I already can integrate libraries from python and my own one in Julia. However, sadly some labs still only offer libraries developed for Matlab, which decreases their reachability to all the community.

I have already taken a look at MatlabCompat.jl, but it seems that the authors stop their maintenance in Julia 0.4.

So, I hope there are other solutions to integrate octave instead of just Matlab.

https://github.com/JuliaInterop/MATLAB.jl ?

Hi @dpsanders thanks for your answer.

The problem is that you can use this package without having a MATLAB license. That is why I am looking for integration, that in case I need to download it I know that is free open-source software :slight_smile:

Ah you’re right, sorry about that.

This
https://julia-users.narkive.com/M85LtrGP/running-octave-scrips-from-julia

suggests that you may be able to use oct2py and PyCall.
(It wasn’t working then but maybe is now?)

1 Like

A better answer would be “rewrite it in Julia” since you will gain performance and generality.

1 Like

And are you aware that Julia has sophisticated packaged for robotics? https://juliarobotics.org/

1 Like

Thanks, I will take a look at oct2py. And thanks for suggesting me the robotics package. Maybe, I will be able to contribute to it in the future :wink:

[Note also the MATLAB to Julia translator | MATLAB to Julia converter translator that was helpful (but not complete) for me for my first professional Julia project (migrating from MATLAB). Getting oct2py to work at the time would have helped, while I just called/used MATLAB (Octave wouldn’t have fully worked because of Toolbox code, I had to find substitutes for).]

I could (indirectly) call Octave from Julia, using oct2py, but not even, at first, directly from Python (or R).

julia> using PyCall

julia> o = pyimport("oct2py").Oct2Py();

julia> A = o.hw(1)  # or as strict as Julia would have been about types: o.hw([1 2; 3 4]);
Hello world!
2×2 Array{Float64,2}:
 2.0  3.0
 4.0  5.0

shell> less hw.m

function result = hw(A)    
  disp("Hello world!");
  result = A + [1 2; 3 4];
end

Be sure to first to set-up PyCall.jl and:

$ sudo apt-get install octave
$ pip3 install oct2py

DO NOT use the octave snap (maybe it’s 32-bit, as the julia snap, that I also had a problem with, when using with e.g. PyCall, for that reason, conflicting with 64-bit Python), then I couldn’t even call Octave from Python, and note pip3 unlike using pip as documented, as PyCall uses Python3 by default.

Since Julia and Octave (and R) are row-major, but Python is column-major [EDIT: other way around, either would have been a potential problem], I wasn’t sure if this was as fast as calling R to call Octave, but I got errors trying that way (more trouble than it was worth to me):

julia> R"""install.packages("RcppOctave")"""
┌ Warning: RCall.jl: Installing package into ‘/home/pharaldsson_sym/R/x86_64-pc-linux-gnu-library/3.6’
│ (as ‘lib’ is unspecified)
│ Warning: package ‘RcppOctave’ is not available (for R version 3.6.3)
└ @ RCall ~/.julia/packages/RCall/g7dhB/src/io.jl:113

and even with finding package in archive (there seems to be a reason it was moved there, but using it could work for you, at least with older version of R installed?):

$ R CMD INSTALL ../Downloads/RcppOctave_0.18.1.tar.gz
* installing to library ‘/home/pharaldsson_sym/R/x86_64-pc-linux-gnu-library/3.6’
ERROR: dependency ‘pkgmaker’ is not available for package ‘RcppOctave’
* removing ‘/home/pharaldsson_sym/R/x86_64-pc-linux-gnu-library/3.6/RcppOctave’

One other option I didn’t look into, it’s possible to call Octave from Sage, and I saw:

Julia is not shipped with SageMath, but it is installed on SageMathCloud at http://cloud.sagemath.com.

2 Likes

Isn’t this the other way around?

5 Likes

Yes: Julia, Fortran, Matlab, Octave and R are all column-major while Python and C are row-major.

2 Likes

It may be helpful to add, you may need to use with Oct2Py:
ENV[“OPENBLAS_NUM_THREADS”]=“1” # https://github.com/xianyi/OpenBLAS/wiki/faq#multi-threaded

Oct2Py worked for me until I got “Session died” (with no line number), and Julia has threading enabled, calling Python and then Octave, but it calling OpenBLAS didn’t handle threads 8for me the inv function).

Also, it might be helpful to use Octave 4.4+ (how?) as while older you get in Ubuntu (18.04), you need that version to pkg install URL in Octave.

I tried both snap and flatpak, and I can get the newer Octave installed, but unclear how to make it work with Oct2Py. You may need:

ENV[“OCTAVE_EXECUTABLE”]= path

flatpak override --filesystem=/tmp org.octave.Octave