Hi,
Thank you for your kindness.
But still, there is one problem.
I don’t know how to make the backward part.
The backward part consisted of the gradient of the function is made with the eigenvalue problem.
So, I can’t exactly describe what the gradient is.
In the end, how can I make the gradient of the black box in terms of autograd
Here is the code
class sc3d(torch.autograd.Function):
@staticmethod
def forward(ctx, input, param):

	ctx.save_for_backward(input, param)

	param_c = param.to(torch.device('cpu'))
	param_c = param_c.detach().numpy()
	
	input_c = torch.stack([input[:, 0] * input[:, 0], input[:, 0], torch.FloatTensor([1, 1, 1, 1, 1, 1]).to(device), input[:, 1]])
	input_c = input_c.to(torch.device('cpu'))
	input_c = input_c.detach().numpy()
	
	libname = os.path.abspath(os.path.join(os.path.dirname(__file__), "sc3d.so"))
	LIBC = ctypes.CDLL(libname)

	_double_pp = np.ctypeslib.ndpointer(dtype=np.uintp, ndim=1)
	# _pp = np.ctypeslib.ndpointer(dtype=ctypes.c_float, ndim=1)
	
	LIBC.polyno.argtypes = [ctypes.c_int, ctypes.c_int, _double_pp, _double_pp, _double_pp] 
	LIBC.polyno.restype = None
	
	param_pp = (param_c.__array_interface__['data'][0] + np.arange(param_c.shape[0])*param_c.strides[0]).astype(np.uintp) 
	input_pp = (input_c.__array_interface__['data'][0] + np.arange(input_c.shape[0])*input_c.strides[0]).astype(np.uintp) 
	
	m = ctypes.c_int(param_pp.shape[0])
	n = ctypes.c_int(input_pp.shape[0]) 
	
	# outputs = np.zeros_like(m, m) # param(6*4) * input(4*6)
	output = np.zeros((6, 1)) # param(6*4) * input(4*6)
	output_pp = (output.__array_interface__['data'][0] + np.arange(output.shape[0])*output.strides[0]).astype(np.uintp)
	
	LIBC.polyno(m, n, param_pp, input_pp, output_pp)
	output = torch.FloatTensor(output).to(device)
	# outputs.requires_grad_(True)

	return output

@staticmethod
def backward(ctx, grad_output):

	input, param = ctx.saved_tensors
	grad_input = grad_param = None

	# calculate gradient part
	# grad_param = grad_output.clone()
	
	return grad_input, grad_param

Best regards,
Choi