如何取代python的使用';朱莉娅的性格特征

如何取代python的使用';朱莉娅的性格特征,python,deep-learning,attributes,julia,Python,Deep Learning,Attributes,Julia,我有一些Python形式的函数fast.ai课程: def mse_grad(inp, targ): # grad of loss with respect to output of previous layer inp.g = 2. * (inp.squeeze() - targ).unsqueeze(-1) / inp.shape[0] def lin_grad(inp, out, w, b): # grad of matmul with respect to i

我有一些Python形式的函数fast.ai课程:

def mse_grad(inp, targ): 
    # grad of loss with respect to output of previous layer
    inp.g = 2. * (inp.squeeze() - targ).unsqueeze(-1) / inp.shape[0]

def lin_grad(inp, out, w, b):
    # grad of matmul with respect to input
    inp.g = out.g @ w.t()
    w.g = (inp.unsqueeze(-1) * out.g.unsqueeze(1)).sum(0)
    b.g = out.g.sum(0)

def forward_and_backward(inp, targ):
    # backward pass:
    mse_grad(out, targ)
    lin_grad(l2, out, w2, b2)

它使用python的属性。如何替换Julia中的inp.g和out.g,以便在
forward\u和
函数中使用这些函数,以便它们可以访问彼此的渐变?

只需使用“g”作为字段定义自己的结构即可。看