# Dot matrix of parameters of a neural network?

**URL:** https://discourse.julialang.org/t/dot-matrix-of-parameters-of-a-neural-network/84072
**Category:** New to Julia
**Created:** [July 11, 2022, 8:40pm UTC](https://discourse.julialang.org/t/dot-matrix-of-parameters-of-a-neural-network/84072 "2022-07-11T20:40:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MysteriousStranger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mysteriousstranger/32/37280_2.png) [@MysteriousStranger](https://discourse.julialang.org/u/MysteriousStranger)
#### Post date: [July 11, 2022, 8:40pm UTC](https://discourse.julialang.org/t/dot-matrix-of-parameters-of-a-neural-network/84072/1 "2022-07-11T20:40:35Z")

</div>

Hello, I am trying to do the dot product of the parameters of a Zygote neural network times some big matrix:

> params = best\_model |\> Flux.params  
> dot( params[1], big\_matrix)

but I am getting this error message:

> Scalar indexing is disallowed.  
> Invocation of getindex resulted in scalar indexing of a GPU array.  
> This is typically caused by calling an iterating implementation of a method.  
> Such implementations _do not_ execute on the GPU, but very slowly on the CPU,  
> and therefore are only permitted from the REPL for prototyping purposes.  
> If you did intend to index this array, annotate the caller with @allowscalar.
> 
> Stacktrace:  
> [1] error(s::String)  
> @ Base ./error.jl:33  
> [2] assertscalar(op::String)  
> @ GPUArraysCore ~/.julia/packages/GPUArraysCore/rSIl2/src/GPUArraysCore.jl:78  
> [3] getindex(xs::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, I::Int64)  
> @ GPUArrays ~/.julia/packages/GPUArrays/EVTem/src/host/indexing.jl:9  
> [4] first  
> @ ./abstractarray.jl:398 [inlined]  
> [5] dot(x::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, y::Matrix{Int64})  
> @ LinearAlgebra /opt/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/generic.jl:915  
> [6] top-level scope  
> @ In[388]:1  
> [7] eval  
> @ ./boot.jl:373 [inlined]  
> [8] include\_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)  
> @ Base ./loading.jl:1196

What can I do to work around this issue?  
I didn’t really wanted to use the index, it seems that dot() is using it internally and it is causing issues

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [July 11, 2022, 10:51pm UTC](https://discourse.julialang.org/t/dot-matrix-of-parameters-of-a-neural-network/84072/2 "2022-07-11T22:51:44Z")

</div>

It looks like your params are on the GPU and `big_matrix` is not. Try moving them to be the same device:

```julia
gpu_big_matrix = gpu(matrix)
dot( params[1], gpu_big_matrix)

```

or

```julia
cpu_params = cpu(params[1])
dot(cpu_params, big_matrix)

```
