Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snlite templates #4548

Merged
merged 5 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions node_scripts/SNLite_templates/templates/numba_VF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
>in verts v #
>in faces s # no computation until both input sockets are connected
out _verts v
out _faces s
"""

from sverchok.utils.decorators_compilation import njit, numba_uncache

# if other numba features are needed
# from sverchok.dependencies import numba

# there are two ways to clear sverchok's njit cache
# 1. numba_uncache(your_function_name)
# 2. rename the function, into something that does not yet exist in the cache

# this will compile, the first time it's run, then subsequent
# calls to your_function are from the cached compilation.

#@njit(cache=True)
def your_function(vlist, flist):
return nvlist, nflist


for vlist, flist in zip(verts, faces):
v, f = your_function(vlist, flist)
_verts.append(v)
_faces.append(f)
2 changes: 1 addition & 1 deletion nodes/script/script1_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

defaults = [0] * 32

template_categories = ['demo', 'bpy_stuff', 'bmesh', 'utils']
template_categories = ['demo', 'bpy_stuff', 'bmesh', 'utils', 'templates']



Expand Down
9 changes: 9 additions & 0 deletions utils/decorators_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def wrapper(function_to_compile):
if function_name not in local_numba_storage:
jitted_func = numba.njit(**kwargs)(function_to_compile)
local_numba_storage[function_name] = jitted_func

#elif function_name in local_numba_storage and function_str_hash doesn't match:
# # recache
# the dowside to this would be that it becomes whitespace/comment changes sensitive
# unless whitespace and comments are removed from functionstring before compilation..

return local_numba_storage[function_name]

else:
Expand All @@ -47,3 +53,6 @@ def wrapper(function_to_compile):
return function_to_compile

return wrapper

def numba_uncache(function_name):
del local_numba_storage[function_name]
16 changes: 14 additions & 2 deletions utils/snlite_importhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,31 @@ def parse_socket_line(node, line):
nested = processed(lsp[4])
return socket_type, socket_name, default, nested

def trim_comment(line):
idx = line.find("#")
if idx < 0:
return line
return line[:idx]

def parse_required_socket_line(node, line):
# receives a line like
# required input sockets do not accept defaults or nested info, what would be the point?
# receives a line like
# >in socketname sockettype

line = trim_comment(line)

lsp = line.strip().split()
if len(lsp) > 3:
lsp = lsp[:3]

if len(lsp) == 3:
socket_type = sock_dict.get(lsp[2])
socket_name = lsp[1]
if not socket_type:
return UNPARSABLE
return socket_type, socket_name, None, None

node.error(f'directive: (socket line) "{line}" -> is malformed, missing socket type?')
node.error(f'directive: (socket line) "{line}" -> is malformed, missing socket type? {lsp}')
return UNPARSABLE


Expand Down
1 change: 1 addition & 0 deletions utils/snlite_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def ddir(content, filter_str=None):
vals = [n for n in dir(content) if not n.startswith('__') and filter_str in n]
return vals

# deprecated, use decorators_compilation.njit instead

def sv_njit(function_to_njit, parameters):
fn_name = function_to_njit.__name__
Expand Down