You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-dev@lucene.apache.org by Alexey Ryabukhin <al...@gmail.com> on 2013/01/21 09:55:51 UTC
How to send double array[][] from Python to Java with JCC?
I have a function in java code that returns double array[][].
In python I have this:
JArray<object>[<Object: [D@11ba64d>, <Object: [D@14efcb0>, <Object:
[D@432685>, <Object: [D@9609cc>, <Object: [D@5d62a4>]
Works fine.
But when I put it back to java it shows error:
self.putArrayPixels(self.getArrayPixels())
ijresize.InvalidArgsError: (<class '__main__.ia'>, 'putArrayPixels',
JArray<object>[<Object: [D@1869971>, <Object: [D@1c3cd93>, <Object:
[D@1ed790e>, <Object: [D@1a6bc76>, <Object: [D@19f1b1d>])
Is it possible somehow to do this?
Re: How to send double array[][] from Python to Java with JCC?
Posted by Alexey Ryabukhin <al...@gmail.com>.
You were right, I forgot to recompile java module.
All works fine now. Thanks!
2013/1/24 Andi Vajda <va...@apache.org>:
>
> On Thu, 24 Jan 2013, Alexey Ryabukhin wrote:
>
>> Just installed new version, but it still not works.
>> Could you show me your java and python code example?
>> Thank you.
>
>
> Did you rebuild and resinstall JCC, then rebuild and resinstall your python
> extensions ?
>
> ------ foo.java ---------
>
> public class foo {
> public double[][] getArrayPixels(int nx, int ny)
>
> {
> double array[][] = new double[nx][ny];
> int k = 0;
> for(int j = 0; j < ny; j++)
> {
> for(int i = 0; i < nx; i++)
> array[i][j] = k++;
>
> }
> return array;
> }
>
>
> public void putArrayPixels(double array[][])
> {
> int bx = array.length;
> int by = array[0].length;
> int k = 0;
> for(int j = 0; j < by; j++)
> {
> for(int i = 0; i < bx; i++)
> System.out.println("j: " + j + ", i: " + i + ": " +
> array[i][j]);
> }
> } }
>
> ----- build ------
> $ javac foo.java
> $ python -m jcc --shared --arch x86_64 --classpath `pwd` foo --python foo
> --build
> $ python -m jcc --shared --arch x86_64 --classpath `pwd` foo --python foo
> --install
> ----- run ----------
> $ python
> >>> from foo import *
> >>> initVM()
> >>> a=foo()
> >>> a.putArrayPixels(a.getArrayPixels(5,5))
>
> Andi..
>
>
>>
>> 2013/1/23 Andi Vajda <va...@apache.org>:
>>>
>>>
>>> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>>>
>>>> Here is a Java part:
>>>>
>>>> public double[][] getArrayPixels()
>>>> {
>>>> double array[][] = new double[nx][ny];
>>>> int k = 0;
>>>> for(int j = 0; j < ny; j++)
>>>> {
>>>> for(int i = 0; i < nx; i++)
>>>> array[i][j] = pixels[k++];
>>>> }
>>>>
>>>> return array;
>>>> }
>>>>
>>>>
>>>> public void putArrayPixels(double array[][])
>>>> {
>>>> int bx = array.length;
>>>> int by = array[0].length;
>>>> int k = 0;
>>>> for(int j = 0; j < by; j++)
>>>> {
>>>> for(int i = 0; i < bx; i++)
>>>> pixels[k++] = array[i][j];
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> Python part:
>>>>
>>>> a = p.ImageAccess(5, 5).getArrayPixels()
>>>> print a
>>>> JArray<object>[<Object: [D@14efcb0>, <Object: [D@af8eaa>, <Object:
>>>> [D@1bf4061>, <Object: [D@11ba64d>, <Object: [D@432685>]
>>>> This part works fine, I can cast each object as JArray double
>>>>
>>>>
>>>>
>>>> ijresize.ImageAccess(5, 5).putArrayPixels(a)
>>>> Produces error:
>>>>
>>>> p.InvalidArgsError: (<type 'ImageAccess'>, 'putArrayPixels',
>>>> JArray<object>[<Object: [D@af8eaa>, <Object: [D@1bf4061>, <Object:
>>>> [D@11ba64d>, <Object: [D@432685>, <Object: [D@9609cc>])
>>>
>>>
>>>
>>> The code parsing python parameter tuples didn't allow for nested arrays.
>>> I added code to bypass array element checking when the array is in fact a
>>> nested array and treat it as an array of java.lang.Object.
>>>
>>> This is checked into rev 1437761 of pylucene trunk.
>>> I modified your code to actually build and was able to pass a nested
>>> array
>>> back and forth and examine its contents in both the Java and Python
>>> sides.
>>>
>>> Andi..
>>>
>>>
>>>>
>>>> 2013/1/21 Andi Vajda <va...@apache.org>:
>>>>>
>>>>>
>>>>>
>>>>> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>>>>>
>>>>>> I have a function in java code that returns double array[][].
>>>>>> In python I have this:
>>>>>> JArray<object>[<Object: [D@11ba64d>, <Object: [D@14efcb0>, <Object:
>>>>>> [D@432685>, <Object: [D@9609cc>, <Object: [D@5d62a4>]
>>>>>> Works fine.
>>>>>>
>>>>>> But when I put it back to java it shows error:
>>>>>> self.putArrayPixels(self.getArrayPixels())
>>>>>> ijresize.InvalidArgsError: (<class '__main__.ia'>, 'putArrayPixels',
>>>>>> JArray<object>[<Object: [D@1869971>, <Object: [D@1c3cd93>, <Object:
>>>>>> [D@1ed790e>, <Object: [D@1a6bc76>, <Object: [D@19f1b1d>])
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>>>
>>>>>> Is it possible somehow to do this?
>>>>>>
>>>>>
>>>>> I'm not sure I know what you mean. Could you please include a small
>>>>> Java
>>>>> class + Python program that reproduces the problem ?
>>>>>
>>>>> Thanks !
>>>>>
>>>>> Andi..
>>>>
>>>>
>>>>
>>>
>>
>
Re: How to send double array[][] from Python to Java with JCC?
Posted by Andi Vajda <va...@apache.org>.
On Thu, 24 Jan 2013, Alexey Ryabukhin wrote:
> Just installed new version, but it still not works.
> Could you show me your java and python code example?
> Thank you.
Did you rebuild and resinstall JCC, then rebuild and resinstall your python
extensions ?
------ foo.java ---------
public class foo {
public double[][] getArrayPixels(int nx, int ny)
{
double array[][] = new double[nx][ny];
int k = 0;
for(int j = 0; j < ny; j++)
{
for(int i = 0; i < nx; i++)
array[i][j] = k++;
}
return array;
}
public void putArrayPixels(double array[][])
{
int bx = array.length;
int by = array[0].length;
int k = 0;
for(int j = 0; j < by; j++)
{
for(int i = 0; i < bx; i++)
System.out.println("j: " + j + ", i: " + i + ": " + array[i][j]);
}
}
}
----- build ------
$ javac foo.java
$ python -m jcc --shared --arch x86_64 --classpath `pwd` foo --python foo --build
$ python -m jcc --shared --arch x86_64 --classpath `pwd` foo --python foo --install
----- run ----------
$ python
>>> from foo import *
>>> initVM()
>>> a=foo()
>>> a.putArrayPixels(a.getArrayPixels(5,5))
Andi..
>
> 2013/1/23 Andi Vajda <va...@apache.org>:
>>
>> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>>
>>> Here is a Java part:
>>>
>>> public double[][] getArrayPixels()
>>> {
>>> double array[][] = new double[nx][ny];
>>> int k = 0;
>>> for(int j = 0; j < ny; j++)
>>> {
>>> for(int i = 0; i < nx; i++)
>>> array[i][j] = pixels[k++];
>>> }
>>>
>>> return array;
>>> }
>>>
>>>
>>> public void putArrayPixels(double array[][])
>>> {
>>> int bx = array.length;
>>> int by = array[0].length;
>>> int k = 0;
>>> for(int j = 0; j < by; j++)
>>> {
>>> for(int i = 0; i < bx; i++)
>>> pixels[k++] = array[i][j];
>>> }
>>>
>>> }
>>>
>>>
>>>
>>> Python part:
>>>
>>> a = p.ImageAccess(5, 5).getArrayPixels()
>>> print a
>>> JArray<object>[<Object: [D@14efcb0>, <Object: [D@af8eaa>, <Object:
>>> [D@1bf4061>, <Object: [D@11ba64d>, <Object: [D@432685>]
>>> This part works fine, I can cast each object as JArray double
>>>
>>>
>>>
>>> ijresize.ImageAccess(5, 5).putArrayPixels(a)
>>> Produces error:
>>>
>>> p.InvalidArgsError: (<type 'ImageAccess'>, 'putArrayPixels',
>>> JArray<object>[<Object: [D@af8eaa>, <Object: [D@1bf4061>, <Object:
>>> [D@11ba64d>, <Object: [D@432685>, <Object: [D@9609cc>])
>>
>>
>> The code parsing python parameter tuples didn't allow for nested arrays.
>> I added code to bypass array element checking when the array is in fact a
>> nested array and treat it as an array of java.lang.Object.
>>
>> This is checked into rev 1437761 of pylucene trunk.
>> I modified your code to actually build and was able to pass a nested array
>> back and forth and examine its contents in both the Java and Python sides.
>>
>> Andi..
>>
>>
>>>
>>> 2013/1/21 Andi Vajda <va...@apache.org>:
>>>>
>>>>
>>>> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>>>>
>>>>> I have a function in java code that returns double array[][].
>>>>> In python I have this:
>>>>> JArray<object>[<Object: [D@11ba64d>, <Object: [D@14efcb0>, <Object:
>>>>> [D@432685>, <Object: [D@9609cc>, <Object: [D@5d62a4>]
>>>>> Works fine.
>>>>>
>>>>> But when I put it back to java it shows error:
>>>>> self.putArrayPixels(self.getArrayPixels())
>>>>> ijresize.InvalidArgsError: (<class '__main__.ia'>, 'putArrayPixels',
>>>>> JArray<object>[<Object: [D@1869971>, <Object: [D@1c3cd93>, <Object:
>>>>> [D@1ed790e>, <Object: [D@1a6bc76>, <Object: [D@19f1b1d>])
>>>>
>>>>
>>>>
>>>>>
>>>>>
>>>>> Is it possible somehow to do this?
>>>>>
>>>>
>>>> I'm not sure I know what you mean. Could you please include a small Java
>>>> class + Python program that reproduces the problem ?
>>>>
>>>> Thanks !
>>>>
>>>> Andi..
>>>
>>>
>>
>
Re: How to send double array[][] from Python to Java with JCC?
Posted by Alexey Ryabukhin <al...@gmail.com>.
Just installed new version, but it still not works.
Could you show me your java and python code example?
Thank you.
2013/1/23 Andi Vajda <va...@apache.org>:
>
> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>
>> Here is a Java part:
>>
>> public double[][] getArrayPixels()
>> {
>> double array[][] = new double[nx][ny];
>> int k = 0;
>> for(int j = 0; j < ny; j++)
>> {
>> for(int i = 0; i < nx; i++)
>> array[i][j] = pixels[k++];
>> }
>>
>> return array;
>> }
>>
>>
>> public void putArrayPixels(double array[][])
>> {
>> int bx = array.length;
>> int by = array[0].length;
>> int k = 0;
>> for(int j = 0; j < by; j++)
>> {
>> for(int i = 0; i < bx; i++)
>> pixels[k++] = array[i][j];
>> }
>>
>> }
>>
>>
>>
>> Python part:
>>
>> a = p.ImageAccess(5, 5).getArrayPixels()
>> print a
>> JArray<object>[<Object: [D@14efcb0>, <Object: [D@af8eaa>, <Object:
>> [D@1bf4061>, <Object: [D@11ba64d>, <Object: [D@432685>]
>> This part works fine, I can cast each object as JArray double
>>
>>
>>
>> ijresize.ImageAccess(5, 5).putArrayPixels(a)
>> Produces error:
>>
>> p.InvalidArgsError: (<type 'ImageAccess'>, 'putArrayPixels',
>> JArray<object>[<Object: [D@af8eaa>, <Object: [D@1bf4061>, <Object:
>> [D@11ba64d>, <Object: [D@432685>, <Object: [D@9609cc>])
>
>
> The code parsing python parameter tuples didn't allow for nested arrays.
> I added code to bypass array element checking when the array is in fact a
> nested array and treat it as an array of java.lang.Object.
>
> This is checked into rev 1437761 of pylucene trunk.
> I modified your code to actually build and was able to pass a nested array
> back and forth and examine its contents in both the Java and Python sides.
>
> Andi..
>
>
>>
>> 2013/1/21 Andi Vajda <va...@apache.org>:
>>>
>>>
>>> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>>>
>>>> I have a function in java code that returns double array[][].
>>>> In python I have this:
>>>> JArray<object>[<Object: [D@11ba64d>, <Object: [D@14efcb0>, <Object:
>>>> [D@432685>, <Object: [D@9609cc>, <Object: [D@5d62a4>]
>>>> Works fine.
>>>>
>>>> But when I put it back to java it shows error:
>>>> self.putArrayPixels(self.getArrayPixels())
>>>> ijresize.InvalidArgsError: (<class '__main__.ia'>, 'putArrayPixels',
>>>> JArray<object>[<Object: [D@1869971>, <Object: [D@1c3cd93>, <Object:
>>>> [D@1ed790e>, <Object: [D@1a6bc76>, <Object: [D@19f1b1d>])
>>>
>>>
>>>
>>>>
>>>>
>>>> Is it possible somehow to do this?
>>>>
>>>
>>> I'm not sure I know what you mean. Could you please include a small Java
>>> class + Python program that reproduces the problem ?
>>>
>>> Thanks !
>>>
>>> Andi..
>>
>>
>
Re: How to send double array[][] from Python to Java with JCC?
Posted by Andi Vajda <va...@apache.org>.
On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
> Here is a Java part:
>
> public double[][] getArrayPixels()
> {
> double array[][] = new double[nx][ny];
> int k = 0;
> for(int j = 0; j < ny; j++)
> {
> for(int i = 0; i < nx; i++)
> array[i][j] = pixels[k++];
> }
>
> return array;
> }
>
>
> public void putArrayPixels(double array[][])
> {
> int bx = array.length;
> int by = array[0].length;
> int k = 0;
> for(int j = 0; j < by; j++)
> {
> for(int i = 0; i < bx; i++)
> pixels[k++] = array[i][j];
> }
>
> }
>
>
>
> Python part:
>
> a = p.ImageAccess(5, 5).getArrayPixels()
> print a
> JArray<object>[<Object: [D@14efcb0>, <Object: [D@af8eaa>, <Object:
> [D@1bf4061>, <Object: [D@11ba64d>, <Object: [D@432685>]
> This part works fine, I can cast each object as JArray double
>
>
>
> ijresize.ImageAccess(5, 5).putArrayPixels(a)
> Produces error:
>
> p.InvalidArgsError: (<type 'ImageAccess'>, 'putArrayPixels',
> JArray<object>[<Object: [D@af8eaa>, <Object: [D@1bf4061>, <Object:
> [D@11ba64d>, <Object: [D@432685>, <Object: [D@9609cc>])
The code parsing python parameter tuples didn't allow for nested arrays.
I added code to bypass array element checking when the array is in fact a
nested array and treat it as an array of java.lang.Object.
This is checked into rev 1437761 of pylucene trunk.
I modified your code to actually build and was able to pass a nested array
back and forth and examine its contents in both the Java and Python sides.
Andi..
>
> 2013/1/21 Andi Vajda <va...@apache.org>:
>>
>> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>>
>>> I have a function in java code that returns double array[][].
>>> In python I have this:
>>> JArray<object>[<Object: [D@11ba64d>, <Object: [D@14efcb0>, <Object:
>>> [D@432685>, <Object: [D@9609cc>, <Object: [D@5d62a4>]
>>> Works fine.
>>>
>>> But when I put it back to java it shows error:
>>> self.putArrayPixels(self.getArrayPixels())
>>> ijresize.InvalidArgsError: (<class '__main__.ia'>, 'putArrayPixels',
>>> JArray<object>[<Object: [D@1869971>, <Object: [D@1c3cd93>, <Object:
>>> [D@1ed790e>, <Object: [D@1a6bc76>, <Object: [D@19f1b1d>])
>>
>>
>>>
>>>
>>> Is it possible somehow to do this?
>>>
>>
>> I'm not sure I know what you mean. Could you please include a small Java
>> class + Python program that reproduces the problem ?
>>
>> Thanks !
>>
>> Andi..
>
Re: How to send double array[][] from Python to Java with JCC?
Posted by Alexey Ryabukhin <al...@gmail.com>.
Here is a Java part:
public double[][] getArrayPixels()
{
double array[][] = new double[nx][ny];
int k = 0;
for(int j = 0; j < ny; j++)
{
for(int i = 0; i < nx; i++)
array[i][j] = pixels[k++];
}
return array;
}
public void putArrayPixels(double array[][])
{
int bx = array.length;
int by = array[0].length;
int k = 0;
for(int j = 0; j < by; j++)
{
for(int i = 0; i < bx; i++)
pixels[k++] = array[i][j];
}
}
Python part:
a = p.ImageAccess(5, 5).getArrayPixels()
print a
JArray<object>[<Object: [D@14efcb0>, <Object: [D@af8eaa>, <Object:
[D@1bf4061>, <Object: [D@11ba64d>, <Object: [D@432685>]
This part works fine, I can cast each object as JArray double
ijresize.ImageAccess(5, 5).putArrayPixels(a)
Produces error:
p.InvalidArgsError: (<type 'ImageAccess'>, 'putArrayPixels',
JArray<object>[<Object: [D@af8eaa>, <Object: [D@1bf4061>, <Object:
[D@11ba64d>, <Object: [D@432685>, <Object: [D@9609cc>])
2013/1/21 Andi Vajda <va...@apache.org>:
>
> On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
>
>> I have a function in java code that returns double array[][].
>> In python I have this:
>> JArray<object>[<Object: [D@11ba64d>, <Object: [D@14efcb0>, <Object:
>> [D@432685>, <Object: [D@9609cc>, <Object: [D@5d62a4>]
>> Works fine.
>>
>> But when I put it back to java it shows error:
>> self.putArrayPixels(self.getArrayPixels())
>> ijresize.InvalidArgsError: (<class '__main__.ia'>, 'putArrayPixels',
>> JArray<object>[<Object: [D@1869971>, <Object: [D@1c3cd93>, <Object:
>> [D@1ed790e>, <Object: [D@1a6bc76>, <Object: [D@19f1b1d>])
>
>
>>
>>
>> Is it possible somehow to do this?
>>
>
> I'm not sure I know what you mean. Could you please include a small Java
> class + Python program that reproduces the problem ?
>
> Thanks !
>
> Andi..
Re: How to send double array[][] from Python to Java with JCC?
Posted by Andi Vajda <va...@apache.org>.
On Mon, 21 Jan 2013, Alexey Ryabukhin wrote:
> I have a function in java code that returns double array[][].
> In python I have this:
> JArray<object>[<Object: [D@11ba64d>, <Object: [D@14efcb0>, <Object:
> [D@432685>, <Object: [D@9609cc>, <Object: [D@5d62a4>]
> Works fine.
>
> But when I put it back to java it shows error:
> self.putArrayPixels(self.getArrayPixels())
> ijresize.InvalidArgsError: (<class '__main__.ia'>, 'putArrayPixels',
> JArray<object>[<Object: [D@1869971>, <Object: [D@1c3cd93>, <Object:
> [D@1ed790e>, <Object: [D@1a6bc76>, <Object: [D@19f1b1d>])
>
>
> Is it possible somehow to do this?
>
I'm not sure I know what you mean. Could you please include a small
Java class + Python program that reproduces the problem ?
Thanks !
Andi..