File indexing completed on 2026-04-10 07:49:31
0001 """
0002 check.py
0003 =========
0004
0005 Huh this works, but doing very simular from FastAPI does not work
0006
0007 """
0008 import functools, operator, numpy as np
0009 import opticks_CSGOptiX as cx
0010
0011
0012
0013 def read_arr_from_rawfile(path="$HOME/Downloads/arr", dtype_="uint8", shape_="512,512,3" ):
0014 """
0015 this suceeded to recover the numpy array from octet-stream of bytes download from /arr endpoint,
0016 but it is cheating regards the metadata
0017 """
0018 x = None
0019
0020 dtype = getattr(np, dtype_, None)
0021 shape = tuple(map(int,shape_.split(",")))
0022
0023 with open(os.path.expandvars(path), "rb") as fp:
0024 xb = fp.read()
0025 x = np.frombuffer(xb, dtype=dtype ).reshape(*shape)
0026 pass
0027 return x
0028
0029
0030 def array_create_():
0031 a = np.zeros((512, 512, 3), dtype=np.uint8)
0032 a[0:256, 0:256] = [255, 0, 0]
0033 return a
0034
0035
0036
0037 def arange_check():
0038 print("cx\n", cx)
0039 _svc = cx._CSGOptiXService()
0040
0041 print("repr(_svc)\n", repr(_svc))
0042 print("_svc\n", _svc)
0043
0044
0045 shape = (10,6,4)
0046 sz = functools.reduce(operator.mul,shape)
0047 gs = np.arange(sz, dtype=np.float32).reshape(*shape)
0048 print("gs\n", gs)
0049
0050 hit = _svc.simulate(gs)
0051
0052 print("hit\n", hit)
0053
0054
0055 def check_with_non_owned_array():
0056 """
0057 --------------------------------------------------------------------------
0058 TypeError Traceback (most recent call last)
0059 File ~/opticks/CSGOptiX/tests/CSGOptiXService_FastAPI_test/check.py:64
0060 61 buffer = data.tobytes()
0061 62 a0 = np.frombuffer(buffer, dtype=np.float32).reshape(2, 2)
0062 ---> 64 hit = cx._CSGOptiXService_Simulate(a0)
0063
0064 TypeError: _CSGOptiXService_Simulate(): incompatible function arguments. The following argument types are supported:
0065 1. _CSGOptiXService_Simulate(input: numpy.ndarray) -> numpy.ndarray
0066
0067 Invoked with types: ndarray
0068 """
0069 data = np.array([[1, 2], [3, 4]], dtype=np.float32)
0070 buffer = data.tobytes()
0071 a0 = np.frombuffer(buffer, dtype=np.float32).reshape(2, 2)
0072 a = a0
0073
0074 hit = cx._CSGOptiXService_Simulate(a)
0075
0076
0077
0078
0079 if __name__ == '__main__':
0080
0081
0082 data = np.array([[1, 2], [3, 4]], dtype=np.float32)
0083 buffer = data.tobytes()
0084 a0 = np.frombuffer(buffer, dtype=np.float32).reshape(2, 2)
0085 a = a0.copy()
0086
0087 hit = cx._CSGOptiXService_Simulate(a)
0088
0089
0090
0091
0092
0093
0094