-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathlibpython-clj2.java-api.html
More file actions
18 lines (14 loc) · 15 KB
/
Copy pathlibpython-clj2.java-api.html
File metadata and controls
18 lines (14 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html PUBLIC ""
"">
<html><head><meta charset="UTF-8" /><title>libpython-clj2.java-api documentation</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="highlight/solarized-light.css" /><script type="text/javascript" src="highlight/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a> with <a href="https://github.com/xsc/codox-theme-rdash">RDash UI</a> theme</h2><h1><a href="index.html"><span class="project-title"><span class="project-name"></span> <span class="project-version">2.006</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Topics</span></h3><ul><li class="depth-1 "><a href="Usage.html"><div class="inner"><span>Usage</span></div></a></li><li class="depth-1 "><a href="design.html"><div class="inner"><span>LibPython-CLJ Design Notes</span></div></a></li><li class="depth-1 "><a href="embedded.html"><div class="inner"><span>Embedding Clojure In Python</span></div></a></li><li class="depth-1 "><a href="environments.html"><div class="inner"><span>Python Environments</span></div></a></li><li class="depth-1 "><a href="new-to-clojure.html"><div class="inner"><span>So Many Parenthesis!</span></div></a></li><li class="depth-1 "><a href="scopes-and-gc.html"><div class="inner"><span>Scopes And Garbage Collection</span></div></a></li><li class="depth-1 "><a href="slicing.html"><div class="inner"><span>Slicing And Slices</span></div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>libpython-clj2</span></div></div></li><li class="depth-2 branch"><a href="libpython-clj2.codegen.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>codegen</span></div></a></li><li class="depth-2 branch"><a href="libpython-clj2.embedded.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>embedded</span></div></a></li><li class="depth-2 branch current"><a href="libpython-clj2.java-api.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>java-api</span></div></a></li><li class="depth-2"><a href="libpython-clj2.python.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>python</span></div></a></li><li class="depth-3"><a href="libpython-clj2.python.np-array.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>np-array</span></div></a></li><li class="depth-2"><a href="libpython-clj2.require.html"><div class="inner"><span class="tree" style="top: -52px;"><span class="top" style="height: 61px;"></span><span class="bottom"></span></span><span>require</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="libpython-clj2.java-api.html#var--arrayToJVM"><div class="inner"><span>-arrayToJVM</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--callKw"><div class="inner"><span>-callKw</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--copyToJVM"><div class="inner"><span>-copyToJVM</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--copyToPy"><div class="inner"><span>-copyToPy</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--createArray"><div class="inner"><span>-createArray</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--getAttr"><div class="inner"><span>-getAttr</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--getItem"><div class="inner"><span>-getItem</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--hasAttr"><div class="inner"><span>-hasAttr</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--hasItem"><div class="inner"><span>-hasItem</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--importModule"><div class="inner"><span>-importModule</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--initialize"><div class="inner"><span>-initialize</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--inPyContext"><div class="inner"><span>-inPyContext</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--lockGIL"><div class="inner"><span>-lockGIL</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--runString"><div class="inner"><span>-runString</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--setAttr"><div class="inner"><span>-setAttr</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--setItem"><div class="inner"><span>-setItem</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var--unlockGIL"><div class="inner"><span>-unlockGIL</span></div></a></li><li class="depth-1"><a href="libpython-clj2.java-api.html#var-requires*"><div class="inner"><span>requires*</span></div></a></li></ul></div><div class="namespace-docs" id="content"><h1 class="anchor" id="top">libpython-clj2.java-api</h1><div class="doc"><div class="markdown"><p>A java api is exposed for libpython-clj2. The methods below are statically callable without the leading ‘-’. Note that returned python objects implement the respective java interfaces so a python dict will implement java.util.Map, etc. There is some startup time as Clojure dynamically compiles the source code but this binding should have great runtime characteristics in comparison to any other java python engine.</p>
<pre><code class="java">import libpython_clj2.java_api;
java_api.initialize(null);
np = java_api.importModule("numpy");
clojure.lang.IFn ones = (clojure.lang.IFn)java_api.getAttr(np, "ones");
ArrayList dims = new ArrayList();
dims.add(2);
dims.add(3);
Object npArray = ones.invoke(dims);
</code></pre></div></div><div class="public anchor" id="var--arrayToJVM"><h3>-arrayToJVM</h3><div class="usage"><code>(-arrayToJVM pyobj)</code></div><div class="doc"><div class="markdown"><p>Copy (efficiently) a numeric numpy array into a jvm map containing keys “datatype”, “shape”, and “data”.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L200">view source</a></div></div><div class="public anchor" id="var--callKw"><h3>-callKw</h3><div class="usage"><code>(-callKw pyobj pos-args kw-args)</code></div><div class="doc"><div class="markdown"><p>Call a python callable with keyword arguments. Note that you don’t need this pathway to call python methods if you do not need keyword arguments; if the python object is callable then it will implement <code>clojure.lang.IFn</code> and you can use <code>invoke</code>.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L159">view source</a></div></div><div class="public anchor" id="var--copyToJVM"><h3>-copyToJVM</h3><div class="usage"><code>(-copyToJVM object)</code></div><div class="doc"><div class="markdown"><p>Copy a python object such as a dict or a list into a comparable JVM object.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L183">view source</a></div></div><div class="public anchor" id="var--copyToPy"><h3>-copyToPy</h3><div class="usage"><code>(-copyToPy object)</code></div><div class="doc"><div class="markdown"><p>Copy a basic jvm object, such as an implementation of java.util.Map or java.util.List to a python object.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L176">view source</a></div></div><div class="public anchor" id="var--createArray"><h3>-createArray</h3><div class="usage"><code>(-createArray datatype shape data)</code></div><div class="doc"><div class="markdown"><p>Create a numpy array from a tuple of string datatype, shape and data. * <code>datatype</code> - One of “int8” “uint8” </p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L189">view source</a></div></div><div class="public anchor" id="var--getAttr"><h3>-getAttr</h3><div class="usage"><code>(-getAttr pyobj attname)</code></div><div class="doc"><div class="markdown"><p>Get a python attribute. This corresponds to the python ‘.’ operator.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L125">view source</a></div></div><div class="public anchor" id="var--getItem"><h3>-getItem</h3><div class="usage"><code>(-getItem pyobj itemName)</code></div><div class="doc"><div class="markdown"></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L143">view source</a></div></div><div class="public anchor" id="var--hasAttr"><h3>-hasAttr</h3><div class="usage"><code>(-hasAttr pyobj attname)</code></div><div class="doc"><div class="markdown"><p>Returns true if this python object has this attribute.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L119">view source</a></div></div><div class="public anchor" id="var--hasItem"><h3>-hasItem</h3><div class="usage"><code>(-hasItem pyobj itemName)</code></div><div class="doc"><div class="markdown"><p>Return true if this pyobj has this item</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L137">view source</a></div></div><div class="public anchor" id="var--importModule"><h3>-importModule</h3><div class="usage"><code>(-importModule modname)</code></div><div class="doc"><div class="markdown"><p>Import a python module. Module entries can be accessed via <code>getAttr</code>.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L153">view source</a></div></div><div class="public anchor" id="var--initialize"><h3>-initialize</h3><div class="usage"><code>(-initialize options)</code></div><div class="doc"><div class="markdown"><p>See options for <a href="libpython-clj2.python.html#var-initialize.21">libpython-clj2.python/initialize!</a>. Note that the keyword option arguments can be provided by using strings so <code>:library-path</code> becomes the key “library-path”. Also note that there is still a GIL underlying all of the further operations so java should access python via single-threaded pathways.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L61">view source</a></div></div><div class="public anchor" id="var--inPyContext"><h3>-inPyContext</h3><div class="usage"><code>(-inPyContext fn)</code></div><div class="doc"><div class="markdown"><p>Run some code in a python context where all python objects allocated within the context will be deallocated once the context is released. The code must not return references to live python objects.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L111">view source</a></div></div><div class="public anchor" id="var--lockGIL"><h3>-lockGIL</h3><div class="usage"><code>(-lockGIL)</code></div><div class="doc"><div class="markdown"><p>Attempt to lock the gil. This is safe to call in a reentrant manner. Returns an integer representing the gil state that must be passed into unlockGIL.</p>
<p>See documentation for <a href="https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure">pyGILState_Ensure</a>.</p>
<p>Note that the API will do this for you but locking the GIL before doing a string of operations is faster than having each operation lock the GIL individually.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L75">view source</a></div></div><div class="public anchor" id="var--runString"><h3>-runString</h3><div class="usage"><code>(-runString code)</code></div><div class="doc"><div class="markdown"><p>Run a string returning a map of two keys -“globals” and “locals” which each point to a java.util.Map of the respective contexts. See documentation under <a href="libpython-clj2.python.html#var-run-simple-string">libpython-clj2.python/run-simple-string</a> - specifically this will never return the result of the last statement ran - you need to set a value in the global or local context.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L98">view source</a></div></div><div class="public anchor" id="var--setAttr"><h3>-setAttr</h3><div class="usage"><code>(-setAttr pyobj attname objval)</code></div><div class="doc"><div class="markdown"><p>Set an attribute on a python object. This corresponds to the <code>__setattr</code> python call.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L131">view source</a></div></div><div class="public anchor" id="var--setItem"><h3>-setItem</h3><div class="usage"><code>(-setItem pyobj itemName itemVal)</code></div><div class="doc"><div class="markdown"></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L148">view source</a></div></div><div class="public anchor" id="var--unlockGIL"><h3>-unlockGIL</h3><div class="usage"><code>(-unlockGIL gilstate)</code></div><div class="doc"><div class="markdown"><p>Unlock the gil passing in the gilstate returned from lockGIL. Each call to lockGIL must be paired to a call to unlockGIL.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L88">view source</a></div></div><div class="public anchor" id="var-requires*"><h3>requires*</h3><div class="usage"></div><div class="doc"><div class="markdown"></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/java_api.clj#L49">view source</a></div></div></div></body></html>