Skip to content

Commit

Permalink
updcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Feb 16, 2023
1 parent 8d69fee commit 929d066
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
35 changes: 35 additions & 0 deletions docs/python_cihouer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# How to cihou Zeno-Python

1. Uninstall Wendous!

2. Turn on python project and build:
```bash
cmake -B build -DZENO_WITH_Python:BOOL=ON
cmake --build build
```

3. Install numpy locally via pip:
```bash
build/bin/zenoedit -invoke python -m ensurepip
build/bin/zenoedit -invoke python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ numpy
```

4. Play with `PythonScript` node with `code` being multiline string:
```python
import ze
import numpy as np
prim = ze.ZenoPrimitiveObject.new()
prim.verts.resize(4)
pos_np = np.array([
[0, 0, 0],
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
])
prim.verts.pos.from_numpy(pos_np)
ze.rets.prim = prim
```

5. Use `ExtractDict` to get `rets` output key `prim`, use a `Route` to VIEW it.

See `misc/graphs/cihounumpytest.zsg` for full demo.
1 change: 1 addition & 0 deletions misc/graphs/cihounumpytest.zsg

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions projects/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,29 @@ if (BUILD_LIBPYTHON_SHARED)
else()
target_link_libraries(zeno PRIVATE libpython-static)
endif()

#### BEGIN cihou python dapigu ####
add_dependencies(zeno python)
get_property(fuckers GLOBAL PROPERTY FUCKING_PYTHON_EXTENSION_TARGETS)
foreach (fucker IN ITEMS ${fuckers})
if (TARGET ${fucker})
add_dependencies(zeno ${fucker})
message(STATUS "[+] ${fucker}")
else()
message(STATUS "[ ] ${fucker}")
endif()
endforeach()
get_property(fuckconfig GLOBAL PROPERTY FUCK_PYTHON_SYSCONFIG_NIMABI)
get_property(fuckconfig2 GLOBAL PROPERTY FUCK_PYTHON_SYSCONFIG_NIMABI2)
get_property(fuckconfig3 GLOBAL PROPERTY FUCK_PYTHON_SYSCONFIG_NIMABI3)
add_custom_target(fuckpythonnimabidesysconfig
WORKING_DIRECTORY ${fuckconfig3}
COMMENT "CIHOU PYTHON WDNMD DIAONIDAYE CONNIMAFIG"
DEPENDS python
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${fuckconfig}" "${fuckconfig2}"
)
add_dependencies(zeno fuckpythonnimabidesysconfig)
##### END cihou python dapigu #####

target_include_directories(zeno PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/Python-${PYTHON_VERSION}/Include # Python.h (unix)
Expand Down
2 changes: 1 addition & 1 deletion projects/Python/CPython
6 changes: 4 additions & 2 deletions projects/Python/Lib/ze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,11 @@ def to_numpy(self, np=None):
ctypes.c_int: np.int32,
}
dtype = _dtypeLut[self._type]
arr = np.ascontiguousarray(np.empty(myshape, dtype))
arr = np.empty(myshape, dtype)
arr = np.ascontiguousarray(arr)
assert sizeinbytes == arr.size * arr.dtype.itemsize
ctypes.memmove(arr.ctypes.data, self._ptr, sizeinbytes)
return arr

def from_numpy(self, arr, np=None):
if np is None:
Expand All @@ -419,7 +421,7 @@ def from_numpy(self, arr, np=None):
myshape = (self._len,)
sizeinbytes = self._dim * self._len * ctypes.sizeof(self._type)
if tuple(arr.shape) != myshape:
raise ValueError('arrar shape mismatch {} != {}', tuple(arr.shape), myshape)
raise ValueError('array shape mismatch {} != {}', tuple(arr.shape), myshape)
_dtypeLut = {
ctypes.c_float: np.float32,
ctypes.c_int: np.int32,
Expand Down

0 comments on commit 929d066

Please sign in to comment.