Comments (27)
Nargout is inferred by oct2py, so you need to put all of the variables on the lhs.
from oct2py.
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.
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.
That worked.
So the first argument is automatically / implicitly copied from Octave to Python but the remaining but be specified?
from oct2py.
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.
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.
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 eval
ed. Otherwise, are those the expected outputs when nargout=6?
from oct2py.
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.
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.
I don't think you can define an input and use it in the same block. Same for output.
from oct2py.
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.
Hmm, try with no space after -o
from oct2py.
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.
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.
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.
Time to add a few more examples to the notebook methinks...
from oct2py.
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.
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.
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.
http://www.csse.uwa.edu.au/~pk/research/matlabfns/PhaseCongruency/monofilt.m
from oct2py.
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.
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.
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.
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 MailboxOn 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.
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.
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.
I just released 3.0, which fixes this issue.
from oct2py.
Related Issues (20)
- [Question] Properly end session HOT 4
- Using `system ("cat ~/.octaverc")` on Winows HOT 2
- initialization: graphics_toolkit: 2004h toolkit is not available HOT 5
- Run doesn't create new variables in the octave environment HOT 3
- Conflict with opencv HOT 5
- bracketed paste \x1b[?2004h issue HOT 3
- Memory Leak HOT 1
- Problem with calling function; too many outputs HOT 1
- When I use python multiprocessing to open multiple octave displays a timeou HOT 1
- Problem with matlab package folders?
- Thread pool executor leaves ghost-threads that fill up memory
- Calling function script takes 1.5 seconds HOT 1
- error: 'graphics_toolkit' undefined
- Error trying to import octave in Anaconda Spyder using "from oct2py import octave" HOT 8
- _exist function not removing special characters from response HOT 2
- Error on testing
- oc.exit() should kill octave-gui + --no-gui option HOT 11
- Any command on jupyter print `[?2004l` HOT 2
- Serialize in memory HOT 5
- Octave installed via flatpak is not found HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oct2py.