octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integrating Pytave and Nnet


From: Mike Miller
Subject: Re: Integrating Pytave and Nnet
Date: Fri, 31 Mar 2017 10:32:22 -0700
User-agent: NeoMutt/20170113 (1.7.2)

On Fri, Mar 31, 2017 at 10:03:26 -0700, enricobertino wrote:
> Hi all,
> 
> I have some questions about how namespaces are treated in Pytave and how
> modules are imported. 
> 
> 1) If I understand correctly, the global namespace is shared between pyexec
> and pyeval. Local namespaces can also be used, defining python dictionaries
> and passing them as arguments to the functions. For example I can run:
> 
>  NS = pyeval ("{}");
>  pyexec ("import numpy as np", NS)
>  pyeval("np.sqrt(2)", NS)
> 
> and it works correctly. But what about pycall? The global namespace is
> shared between pyexec and pycall? Because for example if I define a function
> with pyexec as
> 
>  pyexec (["import numpy as np\n" ...
>            "def squareroot(x):\n" ...
>            "    s = np.sqrt(x)\n" ...
>            "    return s"]);
> 
> than I can recall the function as 
> 
>  pycall ("squareroot", 4)
> 
> but I can not call
> 
>  pycall ("np.sqrt", 4)
> 
> getting the error: "pycall: no such Python function or callable: np.sqrt"
> 
> Is there a reason for that? 

Hi. First of all, I would suggest that this is not really the preferred
way to be using the Python interface. The goal is to be able to import
Python modules and call Python functions, passing Octave data back and
forth. The goal is not to be able to run arbitrary Python code.

The right (supported) way to call numpy sqrt is

    >> py.numpy.sqrt(2)
    ans =  1.4142
    >> py.numpy.sqrt([1 2 3 4])
    ans =
    
       1.0000   1.4142   1.7321   2.0000
    

> 2) Unfortunately, I am not able to import Tensorflow, that is the module
> that should be used for the project. I tried to import several others
> modules, both with pyexec ("import MODULE") and
> pyeval("__import__('MODULE')") and everything was good. I also tried to
> implement a basic nnet with an other neural networks module, Theano, and it
> worked. But when I try 
> 
>  pyexec("import tensorflow")
> 
> I get two different errors, first time
> 
>  error: pyexec: AttributeError: 'module' object has no attribute 'argv'
> 
> and second time
> 
>  error: pyexec: ImportError: Traceback (most recent call last):
>  File
> "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line
> 61, in <module>
>  from tensorflow.python import pywrap_tensorflow
>  ImportError: cannot import name pywrap_tensorflow
> 
> that is a weird Tensorflow error. The Tensorflow package is correctly
> installed as the others modules and I can use it normally in python. Any
> idea on how this problem could be solved?
> 
> Thank you very much!
> 
> Enrico
> 
> Ps. I'm using Ubuntu 16.10, Octave 4.3.0+ installed from source and Python
> 2.7.12+

I'd be happy for you to debug this and fix anything that you think needs
fixing in the way that the Python interface interacts with TensorFlow.
It could be something with the way the TensorFlow modules import
themselves that we are not handling yet.

If it's something like nested namespaces, then there may yet be some
work that needs to be done to handle different ways of specifying
modules and namespaces in Python. I remember running into some
difficulty with Matplotlib, for example, but I was able to work around
it and get it to work.

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]