Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_array for ReshapedArray not defined #18

Open
benedict-96 opened this issue Dec 6, 2024 · 1 comment · May be fixed by #20
Open

create_array for ReshapedArray not defined #18

benedict-96 opened this issue Dec 6, 2024 · 1 comment · May be fixed by #20
Labels
bug Something isn't working

Comments

@benedict-96
Copy link
Collaborator

benedict-96 commented Dec 6, 2024

For

c = Chain(Dense(2, 3))
nn = SymbolicNeuralNetwork(c)
soutput = nn.model(nn.input, nn.params)
nn_cpu = NeuralNetwork(c)
input = rand(2, 5)
input2 = reshape((@view input[:, 1:2]), 2, 1, 2)
build_nn_function(soutput, nn.params, nn.input)(input2, nn_cpu.params)

we get:

julia> build_nn_function(soutput, nn.params, nn.input)(input2, nn_cpu.params)
ERROR: MethodError: no method matching create_array(::Type{Base.ReshapedArray{…}}, ::Nothing, ::Val{1}, ::Val{(3,)}, ::Float64, ::Float64, ::Float64)
The function `create_array` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  create_array(::Type{<:SubArray{T, N, P, I, L}}, ::Any, ::Val, ::Val, ::Any...) where {T, N, P, I, L}
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/jf8aQ/src/code.jl:546
  create_array(::Type{<:Array}, ::Any, ::Val, ::Val, ::Any...)
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/jf8aQ/src/code.jl:498
  create_array(::Type{<:Array}, ::Nothing, ::Val, ::Val{dims}, ::Any...) where dims
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/jf8aQ/src/code.jl:502
  ...

This is related to JuliaSymbolics/SymbolicUtils.jl#644.

@benedict-96 benedict-96 added the bug Something isn't working label Dec 6, 2024
@benedict-96
Copy link
Collaborator Author

If we extend SymbolicUtils.Code.create_array to:

function create_array(::Type{<:Base.ReshapedArray{T, N, P}}, S, nd::Val, d::Val, elems...) where {T, N, P}
    create_array(P, S, nd, d, elems...)
end

we get:

julia> build_nn_function(soutput, nn.params, nn.input)(input2, nn_cpu.params)
ERROR: DimensionMismatch: new dimensions (2, 1, 2) must be consistent with array size 6

This was referenced Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant