Created
April 3, 2015 03:10
-
-
Save joebo/80a776de72a509971dcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"nbformat": 4, "nbformat_minor": 0, "metadata": {"language_info": {"pygments_lexer": "ipython3", "name": "python", "mimetype": "text/x-python", "version": "3.3.5", "nbconvert_exporter": "python", "codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py"}, "kernelspec": {"language": "python", "name": "python3", "display_name": "Python 3"}}, "cells": [{"execution_count": 1, "source": "from IPython import parallel", "outputs": [], "metadata": {"collapsed": false, "trusted": true}, "cell_type": "code"}, {"execution_count": 2, "source": "rc = parallel.Client()\ndv = rc[:]", "outputs": [], "metadata": {"collapsed": false, "trusted": true}, "cell_type": "code"}, {"execution_count": 24, "source": "with rc[:].sync_imports():\n import time\n import functools\n from ctypes import WinDLL\n from ctypes import pointer\n from ctypes import c_int\n import operator", "outputs": [{"output_type": "stream", "text": "importing time on engine(s)\nimporting functools on engine(s)\nimporting WinDLL from ctypes on engine(s)\nimporting pointer from ctypes on engine(s)\nimporting c_int from ctypes on engine(s)\nimporting operator on engine(s)\n", "name": "stdout"}], "metadata": {"collapsed": false, "trusted": true}, "cell_type": "code"}, {"execution_count": 25, "source": "%%px \nJt=None\nJ=None\n\ndef xrange(x):\n return iter(range(x))\n\ndef mulall(arr):\n return functools.reduce(operator.mul,arr,1)\ndef get_result(jdll,variable):\n pi=[pointer(c_int()) for _ in xrange(4)]\n ret=J.JGetM(jdll,variable,*pi) #datatype,rank, *shape, *value\n type=pi[0].contents.value\n if type==0: #error\n return None,None,None,None\n rank=pi[1].contents.value\n shape=list((c_int*rank).from_address(pi[2].contents.value))\n flat_size=mulall(shape)\n data=list((c_int*flat_size).from_address(pi[3].contents.value))\n return type,rank,shape,resize(shape,data)\ndef resize(shap,dat):\n shap=shap[:]\n flat_size=mulall(shap)\n while len(shap)>1:\n shd=[]\n start=0\n last_size=shap.pop()\n while start<flat_size:\n shd.append(dat[start:start+last_size])\n start+=last_size\n flat_size=len(shd)\n dat=shd\n else:\n shd=dat\n return shd", "outputs": [], "metadata": {"collapsed": false, "trusted": true}, "cell_type": "code"}, {"execution_count": 15, "source": "@dv.remote(block=True)\ndef callJ(cmd, var):\n global Jt\n global J\n if Jt is None:\n J = WinDLL(\"c:/users/joe bogner/j64-802/bin/j.dll\")\n Jt = J.JInit() \n J.JDo(Jt, str.encode(cmd))\n return get_result(Jt, var) \n ", "outputs": [], "metadata": {"collapsed": false, "trusted": true}, "cell_type": "code"}, {"execution_count": 28, "source": "callJ(\"a=:i.3\", \"a\")", "outputs": [{"execution_count": 28, "data": {"text/plain": "[(4, 1, [3], [0, 0, 1]), (4, 1, [3], [0, 0, 1]), (4, 1, [3], [0, 0, 1])]"}, "output_type": "execute_result", "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}, "cell_type": "code"}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment