-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename pyopencl.ipython to pyopencl.ipython_ext to convince 2to3 that…
… 'from IPython import' is not package-local
- Loading branch information
Showing
4 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import division | ||
|
||
from IPython.core.magic import (magics_class, Magics, cell_magic) | ||
|
||
import pyopencl as cl | ||
|
||
|
||
@magics_class | ||
class PyOpenCLMagics(Magics): | ||
@cell_magic | ||
def cl_kernel(self, line, cell): | ||
try: | ||
ctx = self.shell.user_ns["cl_ctx"] | ||
except KeyError: | ||
ctx = None | ||
|
||
if not isinstance(ctx, cl.Context): | ||
ctx = None | ||
|
||
if ctx is None: | ||
try: | ||
ctx = self.shell.user_ns["ctx"] | ||
except KeyError: | ||
ctx = None | ||
|
||
if ctx is None: | ||
raise RuntimeError("unable to locate cl context, which must be " | ||
"present in namespace as 'cl_ctx' or 'ctx'") | ||
|
||
prg = cl.Program(ctx, cell.encode("utf8")).build() | ||
|
||
for knl in prg.all_kernels(): | ||
self.shell.user_ns[knl.function_name] = knl | ||
|
||
|
||
def load_ipython_extension(ip): | ||
ip.register_magics(PyOpenCLMagics) |