Code Monkey home page Code Monkey logo

Comments (27)

blink1073 avatar blink1073 commented on July 19, 2024

Nargout is inferred by oct2py, so you need to put all of the variables on the lhs.

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

This does not seem to work either:

In [77]: f,h1f,h2f,A,theta,psi = %octave monofilt(b, 3, 4, 2, 0.65) -i b

ans = 
{
  [1,1] =

    -0.41105  -0.13702
    0.13702  0.41105

  [1,2] =

  1.0e-03  *

    -8.45872  -2.81957
    2.81957  8.45872

  [1,3] =

  1.0e-05  *

    -1.30714  -0.43571
    0.43571  1.30714

}
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-77-2bec253f83ef> in <module>()
----> 1 f,h1f,h2f,A,theta,psi = get_ipython().magic(u'octave monofilt(b, 3, 4, 2, 0.65) -i b')

ValueError: need more than 3 values to unpack

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Whoops, I was thinking from a direct command perspective. You need to use the -o option for the magic. Try:

%octave monofilt(b, 3, 4, 2, 0.65) -i b -o f,h1f,h2f,A,theta,psi
print(f,h1f,h2f,A,theta,psi)

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

That worked.
So the first argument is automatically / implicitly copied from Octave to Python but the remaining but be specified?

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

When you call a method of an Oct2Py object or eval, the number of items on the LHS is reflected in the call to Octave, but if there aren't any then ans is caputured. The magic works differently to be consistent with other magics.

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

This might be related to that. I am getting different results for these two different calls:

In [101]:

octave.monofilt(b, 3, 4, 2, 0.65)
Out[101]:
[array([[ 0.,  0.],
        [ 0.,  0.]]), array([[ 0.,  0.],
        [ 0.,  0.]]), array([[ 0.,  0.],
        [ 0.,  0.]])]

vs this:

In [102]:

%octave monofilt(b, 3, 4, 2, 0.65) -i b -o f,h1f,h2f,A,theta,psi
ans = 
{
  [1,1] =

    -0.41105  -0.13702
    0.13702  0.41105

  [1,2] =

  1.0e-03  *

    -8.45872  -2.81957
    2.81957  8.45872

  [1,3] =

  1.0e-05  *

    -1.30714  -0.43571
    0.43571  1.30714

}
Out[102]:
[array([[-0.41104991, -0.13701664],
        [ 0.13701664,  0.41104991]]), array([[-0.00845872, -0.00281957],
        [ 0.00281957,  0.00845872]]), array([[ -1.30713648e-05,  -4.35712159e-06],
        [  4.35712159e-06,   1.30713648e-05]])]

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

So in the first case nargout is 1, is that the expect output? For the second, you need to put a semicolon after the function call to suppress the output since it is evaled. Otherwise, are those the expected outputs when nargout=6?

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Ok. Adding the semicolon to improve readability:

In [101]:

octave.monofilt(b, 3, 4, 2, 0.65)
Out[101]:
[array([[ 0.,  0.],
        [ 0.,  0.]]), array([[ 0.,  0.],
        [ 0.,  0.]]), array([[ 0.,  0.],
        [ 0.,  0.]])]
In [113]:

%octave monofilt(b, 3, 4, 2, 0.65); -i b -o f,h1f,h2f,A,theta,psi
Out[113]:
[array([[-0.41104991, -0.13701664],
        [ 0.13701664,  0.41104991]]), array([[-0.00845872, -0.00281957],
        [ 0.00281957,  0.00845872]]), array([[ -1.30713648e-05,  -4.35712159e-06],
        [  4.35712159e-06,   1.30713648e-05]])]

All 0s is not the expected output.

The second case it my reference and I believe the values look good.

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Actually on closer inspection, I do not think this is working right:

In [28]:

b = np.array([[1, 2], [3, 4]])
%octave monofilt(b, 3, 4, 2, 0.65); -i b -o f,h1f,h2f,A,theta,psi
print(f,h1f,h2f,A,theta,psi)
(None, None, None, None, None, None)

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

I don't think you can define an input and use it in the same block. Same for output.

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Still does not look to work:

In [30]:

b = np.array([[1, 2], [3, 4]])
In [31]:

%octave monofilt(b, 3, 4, 2, 0.65); -i b -o f,h1f,h2f,A,theta,psi
Out[31]:
[array([[-0.41104991, -0.13701664],
        [ 0.13701664,  0.41104991]]), array([[-0.00845872, -0.00281957],
        [ 0.00281957,  0.00845872]]), array([[ -1.30713648e-05,  -4.35712159e-06],
        [  4.35712159e-06,   1.30713648e-05]])]
In [32]:

print(f,h1f,h2f,A,theta,psi)
(None, None, None, None, None, None)

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Hmm, try with no space after -o

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Nope. Using the roundtrip from the docs (with semicolons added to assignments):

In [44]:

%octave roundtrip(b); -i b -o q,g
Out[44]:
array([[1, 2],
       [3, 4]])
In [45]:

print(q,g)
(None, None)
In [46]:

%octave roundtrip(b); -i b -oq,g
Out[46]:
array([[1, 2],
       [3, 4]])
In [47]:

print(q,g)
(None, None)

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Ah, I finally see the problem with the magic:

%octave f,h1f,h2f,A,theta,psi = octave.monofilt(b, 3, 4, 2, 0.65); -i b -o f,h1f,h2f,A,theta,psi 

or without using magic:

f,h1f,h2f,A,theta,psi = octave.monofilt(b, 3, 4, 2, 0.65)
print(f,h1f,h2f,A,theta,psi)

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Whoops, you'll need brackets:

%octave [f,h1f,h2f,A,theta,psi] = octave.monofilt(b, 3, 4, 2, 0.65); -i b -o f,h1f,h2f,A,theta,psi 

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Time to add a few more examples to the notebook methinks...

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Should be:

%octave [f,h1f,h2f,A,theta,psi] = monofilt(b, 3, 4, 2, 0.65); -i b -o f,h1f,h2f,A,theta,psi

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

The example without the magic does not work:

In [79]:

f,h1f,h2f,A,theta,psi = octave.monofilt(b, 3, 4, 2, 0.65)
print(f,h1f,h2f,A,theta,psi)
([array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])])

whereas this works:

In [81]:

%octave [f,h1f,h2f,A,theta,psi] = monofilt(b, 3, 4, 2, 0.65); -i b -o f,h1f,h2f,A,theta,psi
print(f,h1f,h2f,A,theta,psi)
([array([[-0.41104991, -0.13701664],
       [ 0.13701664,  0.41104991]]), array([[-0.00845872, -0.00281957],
       [ 0.00281957,  0.00845872]]), array([[ -1.30713648e-05,  -4.35712159e-06],
       [  4.35712159e-06,   1.30713648e-05]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[ 0.41104991,  0.13701664],
       [ 0.13701664,  0.41104991]]), array([[ 0.00845872,  0.00281957],
       [ 0.00281957,  0.00845872]]), array([[  1.30713648e-05,   4.35712159e-06],
       [  4.35712159e-06,   1.30713648e-05]])], [array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]]), array([[ 0.,  0.],
       [ 0.,  0.]])], [array([[-1.57079633, -1.57079633],
       [ 1.57079633,  1.57079633]]), array([[-1.57079633, -1.57079633],
       [ 1.57079633,  1.57079633]]), array([[-1.57079633, -1.57079633],
       [ 1.57079633,  1.57079633]])])

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

I'm not sure what to say about the non-magic version not working. It is getting the right number of nargout... Can you share the monofilt function?

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

http://www.csse.uwa.edu.au/~pk/research/matlabfns/PhaseCongruency/monofilt.m

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

We've exposed a source of friction. Oct2Py sends integers to Octave as integer type, since they are interpreted as such by numpy. The following works:

f,h1f,h2f,A,theta,psi = octave.monofilt(b,3.,4.,2.,0.65)

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Why does the magic version perform differently?

On Fri, Jan 2, 2015, 21:53 Steven Silvester [email protected]
wrote:

We've exposed a source of friction. Oct2Py sends integers to Octave as
integer type, since they are interpreted as such by numpy. The following
works:

f,h1f,h2f,A,theta,psi = octave.monofilt(b,3.,4.,2.,0.65)


Reply to this email directly or view it on GitHub
#66 (comment).

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

In the magic version, everything is wrapped in octave.eval, so the arguments are sent as plain text, instead of through a MAT file.


Sent from Mailbox

On Fri, Jan 2, 2015 at 10:08 PM, Alex Rothberg [email protected]
wrote:

Why does the magic version perform differently?
On Fri, Jan 2, 2015, 21:53 Steven Silvester [email protected]
wrote:

We've exposed a source of friction. Oct2Py sends integers to Octave as
integer type, since they are interpreted as such by numpy. The following
works:

f,h1f,h2f,A,theta,psi = octave.monofilt(b,3.,4.,2.,0.65)


Reply to this email directly or view it on GitHub
#66 (comment).


Reply to this email directly or view it on GitHub:
#66 (comment)

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Okay. If that fact isn't in the docs, it would be worth adding it. I
assumed the two worked using the same mechanism.

On Fri Jan 02 2015 at 11:15:49 PM Steven Silvester [email protected]
wrote:

In the magic version, everything is wrapped in octave.eval, so the
arguments are sent as plain text, instead of through a MAT file.


Sent from Mailbox

On Fri, Jan 2, 2015 at 10:08 PM, Alex Rothberg [email protected]
wrote:

Why does the magic version perform differently?
On Fri, Jan 2, 2015, 21:53 Steven Silvester [email protected]
wrote:

We've exposed a source of friction. Oct2Py sends integers to Octave as
integer type, since they are interpreted as such by numpy. The
following
works:

f,h1f,h2f,A,theta,psi = octave.monofilt(b,3.,4.,2.,0.65)


Reply to this email directly or view it on GitHub
#66 (comment).


Reply to this email directly or view it on GitHub:
#66 (comment)


Reply to this email directly or view it on GitHub
#66 (comment).

from oct2py.

cancan101 avatar cancan101 commented on July 19, 2024

Something else is still not right between these two.
I download this file: http://4.bp.blogspot.com/-ruV5mllFtxA/TjosZziIddI/AAAAAAAAAIw/o8aU8O1ZfqM/s1600/BlackWhite.gif
and then load it using:

import numpy as np
from PIL import Image
a = np.asarray(Image.open('BlackWhite.gif'))/255.

This takes a few seconds:

%octave [f,h1f,h2f,A,theta,psi] = monofilt(a, 3, 4, 2, 0.65); -i a -o f,h1f,h2f,A,theta,psi

but this never returns / takes a VERY long time:

f,h1f,h2f,A,theta,psi = octave.monofilt(a, 3., 4., 2., 0.65)

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Thanks for the feedback. The problem was that the output was not suppressed on the second version, causing it to print a lot to the console, (but not displayed on this end, since the logger is not set to DEBUG by default). I'm going to release version 3.0 that converts int -> float by default and suppresses that output (hopefully by this weekend).

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

I just released 3.0, which fixes this issue.

from oct2py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.