Converting python code to julia

884 views
Skip to first unread message

ccsv.1...@gmail.com

unread,
May 20, 2014, 8:49:14 AM5/20/14
to julia...@googlegroups.com
I want to convert some of my python code for exponential smoothing and Neural networks from python over to julia.

My questions are:

What should I do about the classes? I have not seen classes in julia yet so I am guessing they are all functions.

Secondly what library should they go in. Julia has tons of math libraries scattered all over and not very consolidated (no library like 'Julia stats' or something).

Leah Hanson

unread,
May 20, 2014, 10:48:50 AM5/20/14
to julia...@googlegroups.com
I don't know much about Julia's math libraries, so I'll leave that for someone else.

In Julia, types are just data and functions use multiple dispatch to select which values they work with.

For example, a Python class A with methods foo(self, x, y) and bar(self, z) would become:

~~~
type A
  #properties of A go here
end

function foo(self::A, x, y)
  # whatever foo does
end

function bar(self::A, z)
  # whatever bar does
end
~~~

The function operate on A rather than being a part of it. The type declaration on self (the "::A") makes the function operate on the type A, similar to how the member functions of the Python class A operate on A. This also provides flexibility, in that you can later define functions on type A in a different file/module/library, without needing the edit type A or the file/module/library that it's in at all.

Hope this is helpful,
Leah

Tobias Knopp

unread,
May 20, 2014, 10:49:30 AM5/20/14
to julia...@googlegroups.com
Python classes map pretty much 1 to 1 to Julia composite types. One just has to feed in the type a the first argument in functions.

Toivo Henningsson

unread,
May 20, 2014, 12:09:36 PM5/20/14
to julia...@googlegroups.com
We really should have a FAQ entry on this. It's a frequently asked question :)
 / Toivo
Reply all
Reply to author
Forward
0 new messages