@turbo Segfault with empty rows in SparseMatrix

I’m trying to use the @turbo macro from LoopVectorization iterating over values from a sparse array. The way I’m doing it is the following:

I have a variable state::Vector{Float32} and a square sparse matrix holding Float32 values, with both dimensions equal to the length state. Then I pick a random index in a loop and evaluate the following function:

function getEFactor(state, sparse::SparseMatrixCSC, idx)
    efac = 0f0 
    @turbo for idx in nzrange(sparse, idx)
        efac += -state[sparse.rowval[idx]] * sparse.nzval[idx]
    end
    return efac
end

It seems to SIMD correctly, but I get segfaults when idx corresponds to an empty row of the matrix.

@turbo check_empty=true

1 Like