-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnumerical_differentiation.py
More file actions
32 lines (25 loc) · 1.09 KB
/
numerical_differentiation.py
File metadata and controls
32 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import ctypes
from arrayfire_wrapper.defines import AFArray
from arrayfire_wrapper.lib._utility import call_from_clib
def diff1(arr: AFArray, dim: int, /) -> AFArray:
"""
source: https://arrayfire.org/docs/group__calc__func__diff1.htm#gad3be33ce8114f65c188645e958fce171
"""
out = AFArray.create_null_pointer()
call_from_clib(diff1.__name__, ctypes.pointer(out), arr, ctypes.c_int(dim))
return out
def diff2(arr: AFArray, dim: int, /) -> AFArray:
"""
source: https://arrayfire.org/docs/group__calc__func__diff2.htm#gafc7b2d05e4e85aeb3e8b3239f598f70c
"""
out = AFArray.create_null_pointer()
call_from_clib(diff2.__name__, ctypes.pointer(out), arr, ctypes.c_int(dim))
return out
def gradient(arr: AFArray, /) -> tuple[AFArray, AFArray]:
"""
source: https://arrayfire.org/docs/group__calc__func__grad.htm#gadb342e6765c1536125261b035f7eee59
"""
out_dx = AFArray.create_null_pointer()
out_dy = AFArray.create_null_pointer()
call_from_clib(gradient.__name__, ctypes.pointer(out_dx), ctypes.pointer(out_dy), arr)
return (out_dx, out_dy)