Using @inbounds

@inbounds for j = 1:networks_hidden_layer_size[1]
            hidden_sums[j, 1, s, y, n] = 0
            for i = 1:networks_input_count[1]
                hidden_sums[j, 1, s, y, n] +=
                        networks_input_weights[i, j, n] *
                        observation_tensor_variables[i, s, y]
            end
end

Is the above use of @inbounds enough if I meant for @inbounds to cover everything inside the loop?? Or do I need to add @inbounds to every lines as in below.

@inbounds for j = 1:networks_hidden_layer_size[1]
            @inbounds hidden_sums[j, 1, s, y, n] = 0
            @inbounds for i = 1:networks_input_count[1]
                @inbounds hidden_sums[j, 1, s, y, n] +=
                        networks_input_weights[i, j, n] *
                        observation_tensor_variables[i, s, y]
            end
end

Does the same logic also follow for @simd ?

1 Like

Yes, everything inside the for will benefit.
I am not sure about @simd. But @simd should be used only in very specific cases .