Search code examples
booleanjuliamatrix-multiplication

Boolean matrix multiplication in Julia


I need to multiply two boolean matrices in Julia.

Doing simply A*A or A^2 returns an Int64 Matrix.

Is there a way how to multiply efficiently boolean matrices?


Solution

  • One very simple solution is

    function bool_mul(A,B)
        return A*B .!= 0
    end
    

    This won't be the most efficient since it will allocate a matrix for A*B, but might end up being one of the fastest solutions available.