0

I am struggling to understand the symbolic API nuances of MXNet in Julia. I saw an example in MXNet documentation which has the following line:

act1 = mx.Activation(data = fc1, name=:relu1, act_type=:relu)

Why is act_type assigned the symbol :relu.?

Is :relu a function pointer? If not, then where do we assign the value to :relu symbol? Why is data not assigned a symbol? Why is name assigned a symbol rather than a string?

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Abhishek Kishore
  • 340
  • 2
  • 13

1 Answers1

1

A symbol is a valid value for a variable, of type "Symbol". My guess is that internally there is a switch style statement which applies a particular subroutine depending on the symbol passed, or, as you said, the symbol itself is used to call a particular function. The fact it's a symbol rather than a string is presumably just a matter of design; there's nothing stopping one from defining such a function as taking a string argument and then using that string to call a function.

Note that a symbol is not the same as a "function handle" (which I think is what you're confusing it with). In other words, no, you are not passing a "function pointer" as an argument with this syntax.

Data is not assigned a symbol because presumably you're supposed to pass actual data as the first argument when calling the function.

Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57
  • When you say switch style statement which executes depending on the symbol passed - does that mean that :relu symbol can be checked for some name. typeof(:relu) will give the result -Symbol. So how can we check which type of symbol was passed – Abhishek Kishore Jan 29 '17 at 18:43
  • yes. it may be something as simple as `if name == :relu; callrelu(); elseif name == :expo; callexpo(); end`. Having said that, looking at the source code, the MXNet library seems to be python based. Symbols are sometimes used within PyCall to call the respective members of a python module. e.g. if in python you have `mx.relu`, in julia that usually becomes `mx[:relu]`. It's more than likely that this is what's happening here, and `relu` is a member of the `mx` python module or something along those lines. – Tasos Papastylianou Jan 30 '17 at 03:43
  • as I suspected, it's PyCall syntax. Look at the equivalent documentation in python. (e.g. install mxnet using pip, then in python do `import mxnet` then `help(mxnet.symbol.Activation)` ). Note that (as long as the python module is installed) you can get to the same information via julia by doing `using PyCall`, `mxnet = pyimport("mxnet");`, `pybuiltin("help")(mxnet[:symbol][:Activation])` – Tasos Papastylianou Jan 30 '17 at 04:01
  • Thanks for the explanation – Abhishek Kishore Jan 30 '17 at 06:21