Multiple Dispatch Across Seperate Files

Hi, thanks for your reply. I’m still having a bit of an issue doing it this way. I tried following this and reading this documentation, yet I’m still unsure as to where I’m going wrong.

New file NNFS.jl

module NNFS

export forward

forward(layer, data) = begin
    throw("You need to overload base forward for $(typeof(layer)) and $(typeof(data))")
end

end

Modified Layers.jl

module Layers

using Random; Random.seed!(0)
include("NNFS.jl")
import .NNFS.forward

struct Dense
    n_inputs
    n_neurons
    weights
    biases
    function Dense(n_inputs, n_neurons)
        ### Initialize weights and biases
        ...
        new(n_inputs, n_neurons, weights, biases)
    end
end

NNFS.forward(layer::Dense, inputs::Array{Float64,2}) = begin
    if layer.n_inputs != size(inputs, 2)
        throw(DimensionMismatch("Input size does not match layer input size"))
    end

    return (inputs * layer.weights) .+ layer.biases
end

export Dense

end

Main file:

include("NNFS.jl")
include("Layers.jl")
using .NNFS: forward
using .Layers

dense1 = Dense(2, 4)

inputs = [[1. 2.]; [3. 4.]; [3. 5.]]

out = forward(dense1, inputs)

The last line gets the error (which I defined)

ERROR: "You need to overload base forward for Dense and Array{Float64,2}"
Stacktrace:
 [1] forward(::Dense, ::Array{Float64,2}) at /Users/user/test/NNFS.jl:6
 [2] top-level scope at REPL[7]:1

And calling methods on forward gives the following

julia> methods(forward)
# 1 method for generic function "forward":
[1] forward(layer, data) in Main.NNFS at /Users/user/test/NNFS.jl:5

What is the correct way to set up function overloading from multiple different files?