Map Reduce Advanced - Matrix Multiplication

  • + 1 comment
    def mapper(m1, m2):
        # Assuming that len(m1[0]) = len(m2).
        for i in range( len(m1) ) :
            for j in range( len(m2[0]) ) :
                for k in range( len(m1[0]) ) :
                    mapReducer.emitIntermediate( (i,j), (m1[i][k],m2[k][j]) )
    
    def reducer(key, list_of_values):
        mapReducer.emit( (key[0],key[1],sum(a*b for a,b in list_of_values)) )