src/sparse_matrix.rb
# Returns a flipped version of the sparse matrix.
# 0 3 5 0       0 7 0
# 7 1 0 0  ==>  3 1 0
# 0 0 1 3       5 0 1
#               0 0 3
Returns a flipped version of the sparse matrix.
Returns a flipped version of the sparse matrix .
def transpose()
        array_outer = Array.new(@width)
        array_outer.each_with_index {|row, row_num|
            array_outer[row_num] = Array.new(@height, 0)
        }
        @sparse_hash.each { |key, value|
            array_outer[key.y][key.x] = value
        }
        transposed = SparseMatrix.new(array_outer)
        if !(self.row_count() == transposed.column_count()) or !(self.column_count() == transposed.row_count())
            raise ArgumentError, "The transpose failed."
        end
        return transposed
    end
def transpose ( ) array_outer = Array . new ( @width ) array_outer . each_with_index { | row , row_num | array_outer [ row_num ] = Array . new ( @height , 0 ) } @sparse_hash . each { | key , value | array_outer [ key . y ] [ key . x ] = value } transposed = SparseMatrix . new ( array_outer ) if ! ( self . row_count ( ) == transposed . column_count ( ) ) or ! ( self . column_count ( ) == transposed . row_count ( ) ) raise ArgumentError , "The transpose failed." end return transposed end
Returns a flipped version of the sparse matrix.
Returns a flipped version of the sparse matrix .
# Initialize the array based upon size of the hash # Iterate through, flipping all the spots x and y # Post conditions