I don't know python, but I guess you are using oleautomation
instead of calling j.dll thru C interface.

Вс, 10 ноя 2013, June Kim (김창준) писал(а):
> It's been more than 3 years and I don't know if anyone has followed the
> path since.
> 
> Today I had to retrieve J integer arrays from Python and I quickly wrote a
> python script for doing that. It changes the J array into python lists(of
> lists) with its shape. For example, i.3 3 is  [[0, 1, 2], [3, 4, 5], [6, 7,
> 8]] in Python.
> 
> import operator
> from ctypes import *
> 
> IDEN="jcmd_python"
> 
> def mulall(arr):
>     return reduce(operator.mul,arr,1)
> def run_jcmd(js):
>     oledll.j.JDo(p,IDEN+'=:'+js)
> def get_result(jdll,variable=IDEN):
>     pi=[pointer(c_int()) for _ in xrange(4)]
>     oledll.j.JGetM(jdll,variable,*pi) #datatype,rank, *shape, *value
>     type=pi[0].contents.value
>     if type==0: #error
>         return None,None,None,None
>     rank=pi[1].contents.value
>     shape=list((c_int*rank).from_address(pi[2].contents.value))
>     flat_size=mulall(shape)
>     data=list((c_int*flat_size).from_address(pi[3].contents.value))
>     return type,rank,shape,resize(shape,data)
> def resize(shap,dat):
>     shap=shap[:]
>     flat_size=mulall(shap)
>     while len(shap)>1:
>         shd=[]
>         start=0
>         last_size=shap.pop()
>         while start<flat_size:
>             shd.append(dat[start:start+last_size])
>             start+=last_size
>         flat_size=len(shd)
>         dat=shd
>     else:
>         shd=dat
>     return shd
> 
> p=oledll.j.JInit()
> run_jcmd("i. 3 3")
> type,rank,shape,data=get_result(p) #returns the last result
> print shape,data
> run_jcmd("abc=: i: 5")
> print get_result(p,"abc")
> 
> 
> 
> On Thu, Apr 29, 2010 at 12:43 AM, Richard Kubina <[email protected]> wrote:
> 
> > Thanks a lot, June!  I will try to make some helper functions now and see
> > if
> > the python community takes any notice.  It may be exciting for some folks
> > to
> > mesh Python lists and such with J (:
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to