1

Closed

Matrix<T>.ToRowWiseArray

description

Matrix<T>.ToRowWiseArray,provide a better eiffciency code
    public virtual T[] ToRowWiseArray()
    {
        var ret = new T[RowCount * ColumnCount];

        //foreach (var row in RowEnumerator())
        //{
        //    var rowIndex = row.Item1 * ColumnCount;
        //    foreach (var element in row.Item2.GetIndexedEnumerator())
        //    {
        //        ret[rowIndex &#43; element.Item1] = element.Item2;
        //    }
        //}
        for (int i = 0; i < RowCount; i&#43;&#43;)
        {
            for (int j = 0; j < ColumnCount; j&#43;&#43;)
            {
                ret[i * ColumnCount &#43; j] = At(i, j);
            }
        }
        return ret;
    }

and
    public virtual T[] ToColumnWiseArray()
    {
        var ret = new T[RowCount * ColumnCount];
        //foreach (var column in ColumnEnumerator())
        //{
        //    var columnIndex = column.Item1 * RowCount;
        //    foreach (var element in column.Item2.GetIndexedEnumerator())
        //    {
        //        ret[columnIndex &#43; element.Item1] = element.Item2;
        //    }
        //}
        for (int i = 0; i < RowCount; i&#43;&#43;)
        {
            for (int j = 0; j < ColumnCount; j&#43;&#43;)
            {
                ret[j*RowCount&#43;i] = At(i, j);
            }
        }
        return ret;
    }
Closed Feb 2, 2013 at 8:35 PM by cdrnet
Fixed in mainline

comments