I am trying to create a struct for a neural network layer with memory-only list of neurons:
struct Neuron: '''Implementation of a neuron.''' var weights: Tensor[DType.float64] var bias: Float64 var nin: Int fn __init__(inout self, nin: Int): self.weights = rand[DType.float64](nin) self.bias = random_float64(-1.0, 1.0) self.nin = nin fn __call__(self, x: Tensor[DType.float64]) raises -> Float64: if x.num_elements() != self.nin: raise Error('Input values do not match number of weights') var sum: Float64 = self.bias for i in range(self.nin): sum += x[i] * self.weights[i] return math.tanh(sum)
struct Neuron: '''Implementation of a neuron.''' var weights: Tensor[DType.float64] var bias: Float64 var nin: Int fn __init__(inout self, nin: Int): self.weights = rand[DType.float64](nin) self.bias = random_float64(-1.0, 1.0) self.nin = nin fn __call__(self, x: Tensor[DType.float64]) raises -> Float64: if x.num_elements() != self.nin: raise Error('Input values do not match number of weights') var sum: Float64 = self.bias for i in range(self.nin): sum += x[i] * self.weights[i] return math.tanh(sum)
But I'm struggling to compose these into a list of any sort, whether with a heap array, vector, or variadic list, getting this error:
candidate not viable: method argument #1 cannot bind generic !mlirtype to memory-only type 'Neuron'
candidate not viable: method argument #1 cannot bind generic !mlirtype to memory-only type 'Neuron'