Changeset 10

Show
Ignore:
Timestamp:
03/31/08 05:16:58 (4 years ago)
Author:
sclytrack
Message:

Declared a lot of methods final.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dsss.conf

    r9 r10  
    77[mathematics/imaging/algorithms] 
    88[mathematics/examples/main.d] 
     9noinstall 
  • trunk/mathematics/numerical/Matrix.d

    r9 r10  
    9292        ***********************************************************************/ 
    9393 
    94     uint getRowCount() 
     94    final uint rowCount() 
    9595    { 
    9696        return _rowCount; 
     
    103103        ***********************************************************************/ 
    104104     
    105     uint getColumnCount() 
     105    final uint columnCount() 
    106106    { 
    107107        return _columnCount; 
     
    118118    { 
    119119        T result = 0; 
    120         for (uint r = 0; r < getRowCount; r++) 
    121             for (uint c = 0; c < getColumnCount; c++) 
     120        for (uint r = 0; r < rowCount; r++) 
     121            for (uint c = 0; c < columnCount; c++) 
    122122                result += this[r,c] * this[r,c]; 
    123123        return result; 
     
    133133    { 
    134134        T result = 0; 
    135         for (uint r = 0; r < getRowCount; r++) 
    136             for (uint c = 0; c < getColumnCount; c++) 
     135        for (uint r = 0; r < rowCount(); r++) 
     136            for (uint c = 0; c < columnCount(); c++) 
    137137                result += this[r,c]; 
    138138        return result; 
     
    148148    { 
    149149        char [] result = "\n"; 
    150         for (uint r = 0; r < getRowCount(); r++) 
     150        for (uint r = 0; r < rowCount(); r++) 
    151151        { 
    152152            result ~= "("; 
    153             for (uint c = 0; c < getColumnCount(); c++) 
     153            for (uint c = 0; c < columnCount(); c++) 
    154154                version (Tango) 
    155155                { 
     
    172172    bool opEquals(MatrixBase!(T) right) 
    173173    { 
    174         bool result = this.getRowCount() == right.getRowCount() && this.getColumnCount() == right.getColumnCount(); 
     174        bool result = this.rowCount() == right.rowCount() && this.columnCount() == right.columnCount(); 
    175175        if (!result) return result; 
    176         for (uint r = 0; r < getRowCount(); r++) 
    177             for (uint c = 0; c < getColumnCount(); c++) 
     176        for (uint r = 0; r < rowCount(); r++) 
     177            for (uint c = 0; c < columnCount(); c++) 
    178178                if (this[r,c] != right[r,c]) return false; 
    179179        return result; 
     
    191191    Matrix!(T) newTransposeMatrix() 
    192192    { 
    193         Matrix!(T) result = new Matrix!(T)(getColumnCount(), getRowCount()); 
    194         for (uint r = 0; r < this.getRowCount; r++) 
    195             for (uint c = 0; c < getColumnCount; c++) 
     193        Matrix!(T) result = new Matrix!(T)(columnCount(), rowCount()); 
     194        for (uint r = 0; r < this.rowCount; r++) 
     195            for (uint c = 0; c < columnCount; c++) 
    196196                result[c,r] = this[r,c]; 
    197197        return result; 
     
    210210    { 
    211211 
    212         assert( this.getRowCount() == right.getRowCount() , " RowCount error"); 
    213         assert( this.getColumnCount() == right.getColumnCount() , "ColumnCount doesn't match"); 
    214         Matrix!(T) result = new Matrix!(T)(this.getRowCount(), this.getColumnCount); 
    215             for (uint r = 0; r < getRowCount(); r++) 
    216                 for (uint c = 0; c < getColumnCount(); c++) 
     212        assert( this.rowCount() == right.rowCount() , " RowCount error"); 
     213        assert( this.columnCount() == right.columnCount() , "ColumnCount doesn't match"); 
     214        Matrix!(T) result = new Matrix!(T)(this.rowCount(), this.columnCount); 
     215            for (uint r = 0; r < rowCount(); r++) 
     216                for (uint c = 0; c < columnCount(); c++) 
    217217                    result[r,c] = this[r,c] + right[r,c]; 
    218218        return result; 
     
    235235    Matrix!(T) opSub(MatrixBase!(T) right) 
    236236    { 
    237         assert( this.getRowCount() == right.getRowCount() , " RowCount doesn't match"); 
    238         assert( this.getColumnCount() == right.getColumnCount() , "ColumnCount doesn't match"); 
    239         Matrix!(T) result = new Matrix!(T)(this.getRowCount(), this.getColumnCount); 
    240             for (uint r = 0; r < getRowCount(); r++) 
    241                 for (uint c = 0; c < getColumnCount(); c++) 
     237        assert( this.rowCount() == right.rowCount() , " RowCount doesn't match"); 
     238        assert( this.columnCount() == right.columnCount() , "ColumnCount doesn't match"); 
     239        Matrix!(T) result = new Matrix!(T)(this.rowCount(), this.columnCount); 
     240            for (uint r = 0; r < rowCount(); r++) 
     241                for (uint c = 0; c < columnCount(); c++) 
    242242                    result[r,c] = this[r,c] - right[r,c]; 
    243243        return result; 
     
    260260    Matrix!(T) opMul(MatrixBase!(T) right) 
    261261    { 
    262         assert( this.getColumnCount() == right.getRowCount(), "Incorrect matrix dimensions for multiplication"); 
    263         Matrix!(T) result = new Matrix!(T)(getRowCount(), getColumnCount()); 
     262        assert( this.columnCount() == right.rowCount(), "Incorrect matrix dimensions for multiplication"); 
     263        Matrix!(T) result = new Matrix!(T)(rowCount(), columnCount()); 
    264264        T intermediate; 
    265         for (uint r = 0; r < this.getRowCount(); r++) 
    266             for (uint c = 0; c < right.getColumnCount; c++) 
     265        for (uint r = 0; r < this.rowCount(); r++) 
     266            for (uint c = 0; c < right.columnCount; c++) 
    267267            { 
    268268                intermediate = 0; 
    269                 for (uint i = 0; i < this.getColumnCount(); i++) 
     269                for (uint i = 0; i < this.columnCount(); i++) 
    270270                    intermediate += this.opIndex(r,i) * right[i,c]; 
    271271                result[r,c] = intermediate; 
     
    289289    Matrix!(T) opMul(real scalar) 
    290290    { 
    291         Matrix!(T) result = new Matrix!(T)(this.getRowCount(), this.getColumnCount()); 
    292         for (uint r = 0; r < getRowCount(); r++) 
    293             for (uint c = 0; c < getColumnCount(); c++) 
     291        Matrix!(T) result = new Matrix!(T)(this.rowCount(), this.columnCount()); 
     292        for (uint r = 0; r < rowCount(); r++) 
     293            for (uint c = 0; c < columnCount(); c++) 
    294294                result[r,c] = this.opIndex(r, c) * scalar; 
    295295        return result; 
     
    311311    Matrix!(T) opMul_r(real scalar) 
    312312    { 
    313         Matrix!(T) result = new Matrix!(T)(this.getRowCount(), this.getColumnCount()); 
    314         for (uint r = 0; r < getRowCount(); r++) 
    315             for (uint c = 0; c < getColumnCount(); c++) 
     313        Matrix!(T) result = new Matrix!(T)(this.rowCount(), this.columnCount()); 
     314        for (uint r = 0; r < rowCount(); r++) 
     315            for (uint c = 0; c < columnCount(); c++) 
    316316                result[r,c] = this.opIndex(r, c) * scalar; 
    317317        return result; 
     
    327327    Matrix!(T) opNeg() 
    328328    { 
    329         Matrix!(T) result = new Matrix!(T) ( getRowCount(), getColumnCount()); 
    330         for (uint r = 0; r < getRowCount(); r++) 
    331             for (uint c = 0; c < getColumnCount; c++) 
     329        Matrix!(T) result = new Matrix!(T) ( rowCount(), columnCount()); 
     330        for (uint r = 0; r < rowCount(); r++) 
     331            for (uint c = 0; c < columnCount; c++) 
    332332                result[r,c] = -this[r,c]; 
    333333        return result; 
     
    344344    T [] getColumn(uint column) 
    345345    { 
    346         assert( column >= 0 && column < getColumnCount(), "column index out of bound"); 
    347         T[] result = new T[getRowCount()]; 
    348         for (uint r = 0; r < getRowCount; r++) 
     346        assert( column >= 0 && column < columnCount(), "column index out of bound"); 
     347        T[] result = new T[rowCount()]; 
     348        for (uint r = 0; r < rowCount; r++) 
    349349            result[r] = this[r, column]; 
    350350        return result; 
     
    360360    T [] getRow(uint row) 
    361361    { 
    362         T [] result = new T[getColumnCount()]; 
     362        T [] result = new T[columnCount()]; 
    363363        for (uint c = 0; c < _columnCount; c++) 
    364364            result[c] = this.opIndex(row, c); 
     
    374374    Matrix!(T) newClone() 
    375375    { 
    376         Matrix!(T) result = new Matrix!(T)(getRowCount(), getColumnCount()); 
    377         for (uint r = 0; r < getRowCount(); r++) 
    378             for (uint c = 0; c < getColumnCount(); c++) 
     376        Matrix!(T) result = new Matrix!(T)(rowCount(), columnCount()); 
     377        for (uint r = 0; r < rowCount(); r++) 
     378            for (uint c = 0; c < columnCount(); c++) 
    379379                result[r,c] = this[r,c]; 
    380380        return result; 
     
    393393    { 
    394394 
    395         assert(this.getRowCount() == 2 && this.getColumnCount() == 2, "not a 2x2 matrix"); 
     395        assert(this.rowCount() == 2 && this.columnCount() == 2, "not a 2x2 matrix"); 
    396396        VectorFixed!(T, cast(uint) 2) result; 
    397397        T intermediate; 
    398         for (uint r = 0; r < this.getRowCount(); r++) 
     398        for (uint r = 0; r < this.rowCount(); r++) 
    399399        { 
    400400            intermediate = 0; 
    401             for (uint i =  0; i < this.getColumnCount(); i++) 
     401            for (uint i =  0; i < this.columnCount(); i++) 
    402402                intermediate += this.opIndex(r,i) * right[i]; 
    403403            result[r] = intermediate; 
     
    414414    VectorFixed!(T, cast(uint) 3) mul3x3(ref VectorFixed!(T, cast(uint) 3) right) 
    415415    { 
    416         assert(this.getRowCount() == 3 && this.getColumnCount() == 3, "not a 3x3 matrix"); 
     416        assert(this.rowCount() == 3 && this.columnCount() == 3, "not a 3x3 matrix"); 
    417417        VectorFixed!(T, cast(uint) 3) result; 
    418418        T intermediate; 
    419         for (uint r = 0; r < this.getRowCount(); r++) 
     419        for (uint r = 0; r < this.rowCount(); r++) 
    420420        { 
    421421            intermediate = 0; 
    422             for (uint i =  0; i < this.getColumnCount(); i++) 
     422            for (uint i =  0; i < this.columnCount(); i++) 
    423423                intermediate += this.opIndex(r,i) * right[i]; 
    424424            result[r] = intermediate; 
     
    436436    VectorFixed!(T, cast(uint) 4) mul4x4(ref VectorFixed!(T, cast(uint) 4) right) 
    437437    { 
    438         assert(this.getRowCount() == 4 && this.getColumnCount() == 4, "not a 4x4 matrix"); 
     438        assert(this.rowCount() == 4 && this.columnCount() == 4, "not a 4x4 matrix"); 
    439439        VectorFixed!(T, cast(uint) 4) result; 
    440440        T intermediate; 
    441         for (uint r = 0; r < this.getRowCount(); r++) 
     441        for (uint r = 0; r < this.rowCount(); r++) 
    442442        { 
    443443            intermediate = 0; 
    444             for (uint i =  0; i < this.getColumnCount(); i++) 
     444            for (uint i =  0; i < this.columnCount(); i++) 
    445445                intermediate += this.opIndex(r,i) * right[i]; 
    446446            result[r] = intermediate; 
     
    457457    VectorFixed!(T, cast(uint) 3) mul3x4(ref VectorFixed!(T, cast(uint) 4) right) 
    458458    { 
    459         assert(this.getRowCount() == 3 && this.getColumnCount() == 4, "not a 4x4 matrix"); 
     459        assert(this.rowCount() == 3 && this.columnCount() == 4, "not a 4x4 matrix"); 
    460460        VectorFixed!(T, cast(uint) 3) result; 
    461461        T intermediate; 
    462         for (uint r = 0; r < this.getRowCount(); r++) 
     462        for (uint r = 0; r < this.rowCount(); r++) 
    463463        { 
    464464            intermediate = 0; 
    465             for (uint i =  0; i < this.getColumnCount(); i++) 
     465            for (uint i =  0; i < this.columnCount(); i++) 
    466466                intermediate += this.opIndex(r,i) * right[i]; 
    467467            result[r] = intermediate; 
     
    511511 
    512512 
    513 class MatrixView(T):MatrixBase!(T) 
     513class Matrix(T):MatrixBase!(T) 
    514514{ 
     515private: 
     516    static Matrix freelist; 
     517    Matrix freelistNext; 
     518    static uint freelistCount = 0; 
    515519protected: 
    516520    T [] _data; 
     
    520524    uint _columnStep; 
    521525    uint _indexOffset; 
    522     bool _isLapackMode;   //Column-Major 
     526    bool _isColumnMajor;  //Column-Major 
    523527public: 
    524         /*********************************************************************** 
    525  
    526     Constructor for the MatrixView 
     528 
     529 
     530        /*********************************************************************** 
     531 
     532    Returns a view to an existing matrix, this is part of the freelist 
     533    algorithm. 
     534         
     535        ***********************************************************************/ 
     536     
     537    static  Matrix allocateView(uint row, uint column, uint rowCount, uint columnCount, Matrix matrix) 
     538    { 
     539        Matrix!(T) result; 
     540        if (freelist) 
     541        { 
     542            result = freelist; 
     543            freelist = result.freelistNext; 
     544            result.setView( row, column, rowCount, columnCount, matrix); 
     545            freelistCount--; 
     546        } else 
     547            result = new Matrix!(T) (row, column, rowCount, columnCount, matrix); 
     548        return result; 
     549    } 
     550 
     551        /*********************************************************************** 
     552     
     553    Puts the matrix onto a freelist for reuse. 
     554         
     555        ***********************************************************************/ 
     556 
     557    static void deallocate(Matrix m) 
     558    { 
     559        if (freelistCount < 1000)   //Freelist Buffer size. 
     560        { 
     561            m.freelistNext = freelist; 
     562            freelist = m; 
     563            freelistCount++; 
     564        } 
     565    } 
     566 
     567        /*********************************************************************** 
     568 
     569    Constructor for the Matrix 
    527570 
    528571    For normal use the array should have the dimensions 
     
    557600        _allocatedColumnCount = allocatedColumnCount; 
    558601        _indexOffset = indexOffset; 
    559  
    560         _isLapackMode = columnMajor;        //Just discovered that lapackMode == column-major. 
    561  
     602        _isColumnMajor = columnMajor;       //Just discovered that lapackMode == column-major. 
    562603        _data = data; 
    563  
    564         if (columnMajor) 
     604        if (_isColumnMajor) 
    565605        { 
    566606            _columnStep = _allocatedRowCount; 
     
    571611            _columnStep = 1; 
    572612            _rowStep = _allocatedColumnCount; 
    573         } 
    574          
     613        }        
    575614        assert(  data.length > (rowCount-1) * _rowStep + (columnCount-1) * _columnStep + _indexOffset );  
    576615    } 
     
    579618        /*********************************************************************** 
    580619 
    581         Creates a MatrixView that is a view of another MatrixView 
     620        Creates a Matrix that is a view of another Matrix 
    582621 
    583622        Params: 
     
    586625        rowCount=   Amount of rows of the view 
    587626        columnCount=    Amount of columns of the view 
    588         matrix  =   The other MatrixView 
     627        matrix  =   The other Matrix 
    589628         
    590629        Example: 
     
    596635            4,8,12,16]); 
    597636 
    598         auto view1 = new MatrixView!(float) (1,1, 3,3, matrix); 
     637        auto view1 = new Matrix!(float) (1,1, 3,3, matrix); 
    599638        Stdout( view1 ).newline; 
    600639 
    601         auto view2 = new MatrixView!(float) (0,0,2,2, view1); 
     640        auto view2 = new Matrix!(float) (0,0,2,2, view1); 
    602641        Stdout( view2 ).newline; 
    603642        --- 
     
    621660 
    622661 
    623     this (uint row, uint column, uint rowCount, uint columnCount, MatrixView matrix) 
    624     { 
    625         assert( row >= 0 && row < matrix.getRowCount() && column >= 0 && column < matrix.getColumnCount(), "index out of bound"); 
     662    this (uint row, uint column, uint rowCount, uint columnCount, Matrix matrix) 
     663    { 
     664        assert( row >= 0 && row < matrix.rowCount() && column >= 0 && column < matrix.columnCount(), "index out of bound"); 
    626665        uint offset = row * matrix._rowStep + column * matrix._columnStep + matrix._indexOffset; 
    627         this( rowCount, columnCount, matrix.getAllocatedRowCount, matrix.getAllocatedColumnCount, matrix.isColumnMajor, matrix.getData, offset); 
    628     } 
     666        this( rowCount, columnCount, matrix.allocatedRowCount, matrix.allocatedColumnCount, matrix.isColumnMajor, matrix.getData, offset); 
     667    } 
     668             
     669 
    629670 
    630671 
     
    639680        Example: 
    640681        --- 
    641         auto matrix = new MatrixView!(double) (2,2,[1,2,3,4]); 
     682        auto matrix = new Matrix!(double) (2,2,[1,2,3,4]); 
    642683        --- 
    643684 
     
    654695 
    655696 
    656     bool isColumnMajor() 
    657     { 
    658         return _isLapackMode; 
    659     } 
    660  
    661     uint indexOffset() 
     697        /*********************************************************************** 
     698 
     699    Returns whether or not the matrix is in column major format. 
     700     
     701        ***********************************************************************/ 
     702 
     703 
     704 
     705    final bool isColumnMajor() 
     706    { 
     707        return _isColumnMajor; 
     708    } 
     709 
     710 
     711        /*********************************************************************** 
     712     
     713    You can set the matrix to be in column major format or not.  
     714     
     715        ***********************************************************************/ 
     716 
     717    final void isColumnMajor(bool columnMajor) 
     718    { 
     719        _isColumnMajor = columnMajor; 
     720        if (_isColumnMajor) 
     721        { 
     722            _columnStep = _allocatedRowCount; 
     723            _rowStep = 1;            
     724        } 
     725        else 
     726        { 
     727            _columnStep = 1; 
     728            _rowStep = _allocatedColumnCount; 
     729        }        
     730        assert(  _data.length > (rowCount-1) * _rowStep + (columnCount-1) * _columnStep + _indexOffset );  
     731    } 
     732     
     733 
     734        /*********************************************************************** 
     735     
     736    Returns the offset of the first index (upper left element of the matrix) 
     737    in the data array. 
     738     
     739        ***********************************************************************/ 
     740 
     741 
     742    final uint indexOffset() 
    662743    { 
    663744        return _indexOffset; 
     
    682763 
    683764 
    684     /** 
    685      * Returns the allocated amount of rows. 
    686      */ 
    687  
    688     uint getAllocatedRowCount() 
     765 
     766        /*********************************************************************** 
     767     
     768    Sets a view of Matrix!(T). 
     769 
     770    Params: 
     771        row     =   top left corner 
     772        column      =   top left corner 
     773        rowCount    =   rowCount of the view 
     774        columnCount =   columnCount of the view 
     775        matrix      =   another matrix to view. 
     776     
     777        ***********************************************************************/ 
     778 
     779 
     780 
     781    final void setView( uint row, uint column, uint rowCount, uint columnCount, Matrix matrix) 
     782    { 
     783        assert( row >= 0 && row < matrix.rowCount() && column >= 0 && column < matrix.columnCount(), "index out of bound"); 
     784        _rowCount = rowCount; 
     785        _columnCount = columnCount; 
     786        _allocatedRowCount = matrix.allocatedRowCount; 
     787        _allocatedColumnCount = matrix.allocatedColumnCount; 
     788        _indexOffset = row * matrix._rowStep + column * matrix._columnStep + matrix._indexOffset; 
     789        _isColumnMajor = matrix.isColumnMajor; 
     790        _data = matrix.getData; 
     791        if (_isColumnMajor) 
     792        { 
     793            _columnStep = _allocatedRowCount; 
     794            _rowStep = 1;            
     795        } 
     796        else 
     797        { 
     798            _columnStep = 1; 
     799            _rowStep = _allocatedColumnCount; 
     800        } 
     801        assert(  _data.length > (rowCount-1) * _rowStep + (columnCount-1) * _columnStep + _indexOffset ); 
     802    } 
     803 
     804 
     805        /*********************************************************************** 
     806     
     807    Returns the allocated amount of rows. 
     808     
     809        ***********************************************************************/ 
     810 
     811    final uint allocatedRowCount() 
    689812    { 
    690813        return _allocatedRowCount; 
    691814    } 
    692815 
    693     /** 
    694      * Returns the allocated amount of columns. 
    695      */ 
    696  
    697     uint getAllocatedColumnCount() 
     816        /*********************************************************************** 
     817     
     818    Returns the allocated amount of columns. 
     819     
     820        ***********************************************************************/ 
     821 
     822 
     823    final uint allocatedColumnCount() 
    698824    { 
    699825        return _allocatedColumnCount; 
    700826    } 
    701  
    702  
    703     /** 
    704      * Allows you to set the rowCount. It must always be smaller or equal than the allocatdRowCount. 
    705      */ 
    706  
    707  
    708     /* 
    709     void setRowCount( int rowCount ) 
    710     { 
    711         assert( 0 <= rowCount && rowCount <= _allocateRowCount); 
    712         _rowCount = rowCount; 
    713     } 
    714     */ 
    715  
    716  
    717  
    718  
    719     /** 
    720      * Allows you to set the columnCount. It must always be smaller or equal than the allocatedColumnCount. 
    721      */ 
    722  
    723     /* 
    724  
    725     //Need to check with constructor if data length fit model. 
    726  
    727     void setColumnCount( int columnCount) 
    728     { 
    729         assert(0 <= columnCount && columnCount <= _allocateColumnCount); 
    730         _columnCount = columnCount; 
    731     } 
    732     */ 
    733827 
    734828 
     
    739833 
    740834 
    741     T [] getData() 
     835    final T [] getData() 
    742836    { 
    743837        return _data; 
     
    754848 
    755849 
    756     MatrixView opAddAssign( MatrixBase!(T) right) 
    757     { 
    758         assert( this.getRowCount()==right.getRowCount() , "RowCount doesn't match"); 
    759         assert( this.getColumnCount() == right.getColumnCount() , "ColumnCount doesn't match"); 
    760         for (uint r = 0; r < getRowCount(); r++) 
    761             for (uint c = 0; c < getColumnCount(); c++) 
     850    final Matrix opAddAssign( MatrixBase!(T) right) 
     851    { 
     852        assert( this.rowCount()==right.rowCount() , "RowCount doesn't match"); 
     853        assert( this.columnCount() == right.columnCount() , "ColumnCount doesn't match"); 
     854        for (uint r = 0; r < rowCount(); r++) 
     855            for (uint c = 0; c < columnCount(); c++) 
    762856                this[r,c] = this[r,c] + right[r,c]; 
    763857        return this; 
     
    776870 
    777871 
    778     MatrixView opSubAssign(MatrixBase!(T) right) 
    779     { 
    780         assert( this.getRowCount() == right.getRowCount() , " RowCount doesn't match"); 
    781         assert( this.getColumnCount() == right.getColumnCount() , "ColumnCount doesn't match"); 
    782         for (uint r = 0; r < getRowCount(); r++) 
    783             for (uint c = 0; c < getColumnCount(); c++) 
     872    final Matrix opSubAssign(MatrixBase!(T) right) 
     873    { 
     874        assert( this.rowCount() == right.rowCount() , " RowCount doesn't match"); 
     875        assert( this.columnCount() == right.columnCount() , "ColumnCount doesn't match"); 
     876        for (uint r = 0; r < rowCount(); r++) 
     877            for (uint c = 0; c < columnCount(); c++) 
    784878                this[r,c] =  this[r,c] - right[r,c]; 
    785879        return this; 
     
    792886 
    793887 
    794     MatrixView opMulAssign(real scalar) 
    795     { 
    796         for (uint r = 0; r < getRowCount(); r++) 
    797             for (uint c = 0; c < getColumnCount; c++) 
     888    final Matrix opMulAssign(real scalar) 
     889    { 
     890        for (uint r = 0; r < rowCount(); r++) 
     891            for (uint c = 0; c < columnCount; c++) 
    798892                this[r,c] = this[r,c] * scalar; 
    799893        return this; 
     
    804898    /* 
    805899    *   Provides access to an element of the matrix. 
     900    * 
    806901    *   Example: 
    807902    *   float test = matrix[row, column]; 
    808903    */ 
    809904     
    810     override T opIndex(uint row, uint column) 
    811     { 
    812         assert( row >= 0 && row < this.getRowCount() && column >= 0 && column < this.getColumnCount(), "index out of bound"); 
     905    final T opIndex(uint row, uint column) 
     906    { 
     907        assert( row >= 0 && row < this.rowCount() && column >= 0 && column < this.columnCount(), "index out of bound"); 
    813908        return this._data[row*_rowStep + column*_columnStep + _indexOffset]; 
    814909    } 
    815910     
    816911    /** 
    817     *   Assign a value to row and column 
     912    *   Assign a value to row and column. 
     913    * 
    818914    *   Example: 
    819915    *   matrix[row, column] = 10; 
    820916    */ 
    821917 
    822     override T opIndexAssign( T value, uint row, uint column) 
    823     { 
    824         assert( row >= 0 && row < this.getRowCount() && column >= 0 && column < this.getColumnCount(), "index out of bound"); 
     918    final T opIndexAssign( T value, uint row, uint column) 
     919    { 
     920        assert( row >= 0 && row < this.rowCount() && column >= 0 && column < this.columnCount(), "index out of bound"); 
    825921        this._data[row*_rowStep + column*_columnStep+ _indexOffset] = value; 
    826922        return value; 
     
    833929    */ 
    834930 
    835     void copyFrom(MatrixBase!(T) right) 
    836     { 
    837         assert( right.getRowCount() >= this.getRowCount(),  "The size of the current matrix is not large enough"); 
    838         assert( right.getColumnCount() >= this.getColumnCount(), "The size of the current matrix is not large enough"); 
    839  
    840         for (uint r = 0; r < this.getRowCount(); r++) 
    841         { 
    842             for (uint c = 0; c < this.getColumnCount(); c++) 
     931    final void copyFrom(MatrixBase!(T) right) 
     932    { 
     933        assert( right.rowCount() >= this.rowCount(),  "The size of the current matrix is not large enough"); 
     934        assert( right.columnCount() >= this.columnCount(), "The size of the current matrix is not large enough"); 
     935 
     936        for (uint r = 0; r < this.rowCount(); r++) 
     937        { 
     938            for (uint c = 0; c < this.columnCount(); c++) 
    843939                this[r,c] = right[r,c]; 
    844940        } 
     
    846942 
    847943 
    848     void setIdentity() 
    849     { 
    850         for (uint r=0; r < getRowCount; r++) 
    851             for (uint c= 0; c < getColumnCount; c++) 
     944    final void setIdentity() 
     945    { 
     946        for (uint r=0; r < rowCount; r++) 
     947            for (uint c= 0; c < columnCount; c++) 
    852948                this[r,c] = (r==c?1:0);  
    853949    } 
     
    858954    */ 
    859955     
    860     void setScalingMatrix2x2(T xScale, T yScale) 
    861     { 
    862         assert( getColumnCount >= 2, "Your matrix is not big enough"); 
    863         assert( getRowCount >= 2,"Your matrix is not big enough"); 
     956    final void setScalingMatrix2x2(T xScale, T yScale) 
     957    { 
     958        assert( columnCount >= 2, "Your matrix is not big enough"); 
     959        assert( rowCount >= 2,"Your matrix is not big enough"); 
    864960         
    865961        this[0,0] = xScale; this[0,1]=0; 
     
    873969    */ 
    874970     
    875     void setRotationMatrix2x2(T angle) 
    876     { 
    877         assert( getColumnCount >= 2, "Your matrix is not big enough"); 
    878         assert( getRowCount >= 2,"Your matrix is not big enough"); 
     971    final void setRotationMatrix2x2(T angle) 
     972    { 
     973        assert( columnCount >= 2, "Your matrix is not big enough"); 
     974        assert( rowCount >= 2,"Your matrix is not big enough"); 
    879975         
    880976        version (Tango) 
     
    892988 
    893989 
    894     void setLookAtMatrix4x4( ref VectorFixed!(T, cast(uint) 3) center, ref VectorFixed!(T, cast(uint) 3) z,ref VectorFixed!(T, cast(uint) 3) y ) 
     990    final void setLookAtMatrix4x4( ref VectorFixed!(T, cast(uint) 3) center, ref VectorFixed!(T, cast(uint) 3) z,ref VectorFixed!(T, cast(uint) 3) y ) 
    895991    { 
    896992        z = z.normal();  
     
    900996        y = y.normal(); 
    901997 
    902         assert( getRowCount >= 4); 
    903         assert( getColumnCount >= 4); 
     998        assert( rowCount >= 4); 
     999        assert( columnCount >= 4); 
    9041000 
    9051001        auto matrix = new Matrix!(T)(4,4); 
     
    9471043    */ 
    9481044     
    949     void setRotationMatrix3x3( T angle, VectorFixed!(T, 3) normal) 
    950     { 
    951         assert( getColumnCount >= 3, "Your matrix is not big enough columnwise"); 
    952         assert( getRowCount >= 3,"Your matrix is not big enough rowwise"); 
     1045    final void setRotationMatrix3x3( T angle, VectorFixed!(T, 3) normal) 
     1046    { 
     1047        assert( columnCount >= 3, "Your matrix is not big enough columnwise"); 
     1048        assert( rowCount >= 3,"Your matrix is not big enough rowwise"); 
    9531049        version (Tango) 
    9541050        { 
     
    9781074    } 
    9791075     
    980     void setRotationMatrix4x4( T angle, VectorFixed!(T, 3) normal) 
    981     { 
    982         assert( getColumnCount >= 4, "Your matrix is not big enough columnwise"); 
    983         assert( getRowCount >= 4,"Your matrix is not big enough rowwise"); 
     1076    final void setRotationMatrix4x4( T angle, VectorFixed!(T, 3) normal) 
     1077    { 
     1078        assert( columnCount >= 4, "Your matrix is not big enough columnwise"); 
     1079        assert( rowCount >= 4,"Your matrix is not big enough rowwise"); 
    9841080        setRotationMatrix3x3(angle, normal); 
    9851081                                              this[0,3] = 0;    //translation X 
     
    10281124    */  
    10291125     
    1030     void setFrustumMatrix4x4( T left, T right, T bottom, T top, T near, T far) 
     1126    final void setFrustumMatrix4x4( T left, T right, T bottom, T top, T near, T far) 
    10311127    {        
    1032         assert( getColumnCount >= 4, "Your matrix is not big enough columnwise"); 
    1033         assert( getRowCount >= 4,"Your matrix is not big enough rowwise"); 
     1128        assert( columnCount >= 4, "Your matrix is not big enough columnwise"); 
     1129        assert( rowCount >= 4,"Your matrix is not big enough rowwise"); 
    10341130             
    10351131        this[0,0] =1.0/(right-left);this[0,1] =0;this[0,2] = 1.0/(right-left);this[0,3] =0; 
     
    10821178    */  
    10831179     
    1084     void setOrthoMatrix4x4(T left, T right, T bottom, T top, T near, T far) 
    1085     { 
    1086         assert( getColumnCount >= 4, "Your matrix is not big enough columnwise"); 
    1087         assert( getRowCount >= 4,"Your matrix is not big enough rowwise"); 
     1180    final void setOrthoMatrix4x4(T left, T right, T bottom, T top, T near, T far) 
     1181    { 
     1182        assert( columnCount >= 4, "Your matrix is not big enough columnwise"); 
     1183        assert( rowCount >= 4,"Your matrix is not big enough rowwise"); 
    10881184         
    10891185        T width = right - left; 
     
    11031199    */ 
    11041200     
    1105     void setRotationXMatrix3x3(T angle) 
    1106     { 
    1107         assert( getColumnCount >= 3, "Your matrix is not big enough columnwise"); 
    1108         assert( getRowCount >= 3,"Your matrix is not big enough rowwise"); 
     1201    final void setRotationXMatrix3x3(T angle) 
     1202    { 
     1203        assert( columnCount >= 3, "Your matrix is not big enough columnwise"); 
     1204        assert( rowCount >= 3,"Your matrix is not big enough rowwise"); 
    11091205        T s = sin(angle); 
    11101206        T c = cos(angle); 
     
    11201216    */ 
    11211217     
    1122     void setRotationYMatrix3x3(T angle) 
    1123     { 
    1124         assert( getColumnCount >= 3, "Your matrix is not big enough columnwise"); 
    1125         assert( getRowCount >= 3,"Your matrix is not big enough rowwise"); 
     1218    final void setRotationYMatrix3x3(T angle) 
     1219    { 
     1220        assert( columnCount >= 3, "Your matrix is not big enough columnwise"); 
     1221        assert( rowCount >= 3,"Your matrix is not big enough rowwise"); 
    11261222        T s = sin(angle); 
    11271223        T c = cos(angle); 
     
    11371233    */ 
    11381234 
    1139     void setRotationZMatrix3x3(T angle) 
    1140     { 
    1141         assert( getColumnCount >= 3, "Your matrix is not big enough columnwise"); 
    1142         assert( getRowCount >= 3,"Your matrix is not big enough rowwise"); 
     1235    final void setRotationZMatrix3x3(T angle) 
     1236    { 
     1237        assert( columnCount >= 3, "Your matrix is not big enough columnwise"); 
     1238        assert( rowCount >= 3,"Your matrix is not big enough rowwise"); 
    11431239        T s = sin(angle); 
    11441240        T c = cos(angle);    
     
    11551251    */ 
    11561252     
    1157     void setTranslationMatrix3x3(T x, T y) 
    1158     { 
    1159         assert( getColumnCount >= 3, "Your matrix is not big enough columnwise"); 
    1160         assert( getRowCount >= 3,"Your matrix is not big enough rowwise"); 
     1253    final void setTranslationMatrix3x3(T x, T y) 
     1254    { 
     1255        assert( columnCount >= 3, "Your matrix is not big enough columnwise"); 
     1256        assert( rowCount >= 3,"Your matrix is not big enough rowwise"); 
    11611257        this[0,0]=1;        this[0,1]=0;        this[0,2]=x; 
    11621258        this[1,0]=0;        this[1,1]=1;        this[1,2]=y; 
     
    11651261     
    11661262 
    1167     void setTranslationMatrix4x4(T x, T y, T z) 
    1168     { 
    1169         assert( getColumnCount >= 4); 
    1170         assert( getRowCount >= 4); 
     1263    final void setTranslationMatrix4x4(T x, T y, T z) 
     1264    { 
     1265        assert( columnCount >= 4); 
     1266        assert( rowCount >= 4); 
    11711267        this[0,0]=1;    this[0,1]=0;        this[0,2]=0;    this[0,3]= x; 
    11721268        this[1,0]=0;    this[1,1]=1;        this[1,2]=0;    this[1,3]= y; 
     
    11801276    */ 
    11811277     
    1182     void setScalingMatrix3x3(T xScale, T yScale, T zScale) 
    1183     { 
    1184         assert( getColumnCount >= 3, "Your matrix is not big enough columnwise"); 
    1185         assert( getRowCount >= 3,"Your matrix is not big enough rowwise"); 
     1278    final void setScalingMatrix3x3(T xScale, T yScale, T zScale) 
     1279    { 
     1280        assert( columnCount >= 3, "Your matrix is not big enough columnwise"); 
     1281        assert( rowCount >= 3,"Your matrix is not big enough rowwise"); 
    11861282        this[0,0]=xScale;       this[0,1]=0;        this[0,2]=0; 
    11871283        this[1,0]=0;        this[1,1]=yScale;       this[1,2]=0; 
     
    11991295*******************************************************************************/ 
    12001296 
    1201 class Matrix(T):MatrixView!(T) 
     1297 
     1298/* 
     1299 
     1300class Matrix(T):Matrix!(T) 
    12021301{ 
    12031302public: 
    1204  
    1205         /*********************************************************************** 
    1206          
    1207         Constructor for the column-major rectangular matrix. 
    1208  
    1209         Example: 
    1210         --- 
    1211         auto mat1 = new Matrix!(float)(2,2, [1,2,3,4]); 
    1212         --- 
    1213  
    1214         ***********************************************************************/     
    1215  
    12161303    this(uint rowCount, uint columnCount, T [] data) 
    12171304    { 
     
    12251312    } 
    12261313} 
     1314 
     1315*/ 
    12271316 
    12281317 
     
    12461335        super(ROWCOUNT, COLUMNCOUNT); 
    12471336    } 
    1248  
    1249     override Matrix!(T) opMul(MatrixBase!(T) right) 
    1250     { 
    1251         return super.opMul(right); 
    1252     } 
    1253      
    1254     /** 
    1255     * Multiplication of a matrix and a vector. 
    1256     */ 
    1257  
    1258     VectorFixed!(T, ROWCOUNT) opMul( VectorFixed!(T, COLUMNCOUNT) right) 
     1337     
     1338        /*********************************************************************** 
     1339 
     1340    Multiplication of a matrix with a vector, returns a vector. 
     1341     
     1342        ***********************************************************************/ 
     1343 
     1344    final VectorFixed!(T, ROWCOUNT) opMul( VectorFixed!(T, COLUMNCOUNT) right) 
    12591345    { 
    12601346        VectorFixed!(T, ROWCOUNT) result; 
    12611347        T intermediate; 
    1262         for (uint r = 0; r < this.getRowCount(); r++) 
     1348        for (uint r = 0; r < this.rowCount(); r++) 
    12631349        { 
    12641350            intermediate = 0; 
    1265             for (uint i = 0; i < this.getColumnCount(); i++) 
    1266                 intermediate +=  _data[i * ROWCOUNT+r] * right[i]; 
     1351            for (uint c = 0; c < this.columnCount(); c++) 
     1352                intermediate +=  this[r,c] * right[c]; 
    12671353            result[r] = intermediate; 
    12681354        } 
    12691355        return result; 
    1270     } 
    1271      
    1272     /** 
    1273     * Returns the transpose matrix. 
    1274     */ 
    1275      
    1276     MatrixSized!(T, COLUMNCOUNT, ROWCOUNT) newTransposeMatrix() 
     1356         
     1357    } 
     1358 
     1359        /*********************************************************************** 
     1360 
     1361    Returns a new Transposed Matrix. 
     1362     
     1363        ***********************************************************************/ 
     1364 
     1365    final MatrixSized!(T, COLUMNCOUNT, ROWCOUNT) newTransposeMatrix() 
    12771366    { 
    12781367        MatrixSized!(T, COLUMNCOUNT, ROWCOUNT) result = new MatrixSized!(T, COLUMNCOUNT, ROWCOUNT); 
    1279         for (uint r = 0; r < this.getRowCount; r++) 
    1280             for (uint c = 0; c < getColumnCount; c++) 
     1368        for (uint r = 0; r < this.rowCount; r++) 
     1369            for (uint c = 0; c < columnCount; c++) 
    12811370                result[c,r] = this[r,c]; 
    12821371        return result; 
    12831372    } 
    12841373     
    1285     override T opIndex(uint row, uint column) 
    1286     { 
    1287         assert( row >= 0 && row < this.getRowCount() && column >= 0 && column < this.getColumnCount(), "index out of bound"); 
    1288         //return this._data[row*_rowStep + column*_columnStep]; 
    1289         assert(_rowStep == 1); 
    1290         return this._data[row+column*_columnStep]; 
    1291     }    
    1292      
    1293     override T opIndexAssign( T value, uint row, uint column) 
    1294     { 
    1295         assert( row >= 0 && row < this.getRowCount() && column >= 0 && column < this.getColumnCount(), "index out of bound"); 
    1296         assert(_rowStep == 1); 
    1297         this._data[row + column*_columnStep] = value; 
    1298         return value; 
    1299     } 
    13001374 
    13011375    static if (ROWCOUNT == COLUMNCOUNT) 
    13021376    { 
    1303         MatrixSized opMul(MatrixSized right) 
    1304         { 
    1305             assert( this.getColumnCount() == right.getRowCount(), "Incorrect matrix dimensions for multiplication"); 
     1377 
     1378 
     1379        /*********************************************************************** 
     1380 
     1381    Multiplication of two squared matrices of the same dimensions, where 
     1382    rowCount == columnCount.  
     1383     
     1384        ***********************************************************************/ 
     1385 
     1386        final MatrixSized opMul(MatrixSized right) 
     1387        { 
     1388            assert( this.columnCount() == right.rowCount(), "Incorrect matrix dimensions for multiplication"); 
    13061389            MatrixSized result = new MatrixSized; 
    13071390            T intermediate; 
    1308             for (uint r = 0; r < this.getRowCount(); r++) 
    1309                 for (uint c = 0; c < right.getColumnCount; c++) 
     1391            for (uint r = 0; r < this.rowCount(); r++) 
     1392                for (uint c = 0; c < right.columnCount; c++) 
    13101393                { 
    13111394                    intermediate = 0; 
    1312                     for (uint i = 0; i < this.getColumnCount(); i++) 
     1395                    for (uint i = 0; i < this.columnCount(); i++) 
    13131396                        intermediate += this.opIndex(r,i) * right[i,c]; 
    13141397                    result[r,c] = intermediate; 
     
    13741457    { 
    13751458 
    1376         assert(this.getRowCount == right.getRowCount() && this.getColumnCount() == right.getColumnCount(), 
     1459        assert(this.rowCount == right.rowCount() && this.columnCount() == right.columnCount(), 
    13771460             "dimensions do not match"); 
    1378         MatrixDiagonal result = new MatrixDiagonal(getRowCount, getColumnCount()); 
     1461        MatrixDiagonal result = new MatrixDiagonal(rowCount, columnCount()); 
    13791462         
    13801463        for (int i = 0; i < this.getData().length; i++) 
     
    13851468    override T opIndex(uint row, uint column) 
    13861469    { 
    1387         assert( row >= 0 && row < getRowCount() && column >= 0 && column < getColumnCount() , "index out of bound"); 
     1470        assert( row >= 0 && row < rowCount() && column >= 0 && column < columnCount() , "index out of bound"); 
    13881471        if (row == column) return _data[row]; 
    13891472        return 0; 
     
    13921475    override T opIndexAssign( T value, uint row, uint column) 
    13931476    { 
    1394         assert( row >= 0 && row < getRowCount() && column >= 0 && column < getColumnCount() , "index out of bound"); 
     1477        assert( row >= 0 && row < rowCount() && column >= 0 && column < columnCount() , "index out of bound"); 
    13951478        _data[row] = value; 
    13961479        return value; 
     
    14041487    uint getMinimumDimension() 
    14051488    { 
    1406         return getRowCount() < getColumnCount()? getRowCount(): getColumnCount(); 
     1489        return rowCount() < columnCount()? rowCount(): columnCount(); 
    14071490    } 
    14081491 
     
    14731556        assert(row >= 0, "row"); 
    14741557        assert(column >= 0, "column"); 
    1475         assert(row < getRowCount, "row"); 
    1476         assert(column < getColumnCount, "column"); 
     1558        assert(row < rowCount, "row"); 
     1559        assert(column < columnCount, "column"); 
    14771560        if (row <= column) 
    14781561            return _data[row + column*(column+cast(uint)1)/cast(uint)2]; 
     
    14931576        assert(row >= 0, "row"); 
    14941577        assert(column >= 0, "column"); 
    1495         assert(row < getRowCount, "row"); 
    1496         assert(column < getColumnCount, "column"); 
     1578        assert(row < rowCount, "row"); 
     1579        assert(column < columnCount, "column"); 
    14971580 
    14981581        assert(row <= column, "row > column"); 
     
    15681651        assert(row >= 0, "row"); 
    15691652        assert(column >= 0, "column"); 
    1570         assert(row < getRowCount, "row"); 
    1571         assert(column < getColumnCount, "column"); 
     1653        assert(row < rowCount, "row"); 
     1654        assert(column < columnCount, "column"); 
    15721655        if (row >= column) 
    1573             return _data[row + getRowCount * column - column * (column + 1) / 2]; 
     1656            return _data[row + rowCount * column - column * (column + 1) / 2]; 
    15741657        else 
    15751658            return 0; 
     
    15881671        assert(row >= 0, "row"); 
    15891672        assert(column >= 0, "column"); 
    1590         assert(row < getRowCount, "row"); 
    1591         assert(column < getColumnCount, "column"); 
     1673        assert(row < rowCount, "row"); 
     1674        assert(column < columnCount, "column"); 
    15921675 
    15931676        assert(row >= column, "column > row"); 
    15941677        //return _data[row + (2*size-column)*(column -1) /2 ] = value; 
    1595         _data[ row + getRowCount  * column - column*(column + 1) / 2] = value; 
     1678        _data[ row + rowCount  * column - column*(column + 1) / 2] = value; 
    15961679        return value; 
    15971680    } 
     
    16741757    assert( trianglMul1 == new Matrix!(float) (2,2,[1,2,0,3]) * new Matrix!(float) (2,2,[1,2,0,3])); 
    16751758 
    1676     auto matView1 = new MatrixView!(float)(2,2); 
     1759    auto matView1 = new Matrix!(float)(2,2); 
    16771760    matView1.copyFrom( mat1 ); 
    16781761    assert( matView1 == mat1 ); 
  • trunk/mathematics/numerical/Vector.d

    r8 r10  
    4242//Integer values check out Point(T) or PointFixed(T) 
    4343 
    44  
    4544/** 
    4645*   A class for representing a vector. This provides a means to inherit from the class. 
     
    5352private: 
    5453    T [] _data; 
    55     uint _stepSize; 
    56     uint _startIndex; 
    57     uint _count; 
     54    uint _stepSize;        //The step to the next element 
     55    uint _startIndex;  //The index this vector starts with.    //startindex can be removed. 
     56    uint _count;       //Number of elements in this vector. 
    5857public: 
     58 
    5959 
    6060    /** 
     
    106106    } 
    107107 
    108     Vector opAdd(Vector right) 
     108    /** 
     109        Returns the pointer to the first element of the vector. 
     110    */ 
     111 
     112    final T * iterStart() 
     113    { 
     114        return &_data[_startIndex]; 
     115    } 
     116 
     117    /** 
     118        Returns the pointer to the last element of the vector. 
     119    */ 
     120 
     121    final T * iterStop() 
     122    { 
     123        return &_data[_startIndex + _count - 1]; 
     124    } 
     125 
     126    final Vector opAdd(Vector right) 
    109127    { 
    110128        assert(_count == right._count); 
    111129        Vector result = new Vector(_count); 
     130        T * resultStop = result.iterStop; 
     131        for (T * resultIter = result.iterStart, dataIter = this.iterStart, rightIter = right.iterStart; resultIter <= resultStop; resultIter++,  dataIter++, rightIter++) 
     132            *resultIter = *dataIter + *rightIter; 
     133        return result; 
     134    } 
     135 
     136    /* 
     137    final Vector opAdd(Vector right) 
     138    { 
     139        assert(_count == right._count); 
     140        Vector result = new Vector(_count); 
    112141        for (int x = 0; x < _count; x++) 
    113142            result[x] = this[x] + right[x]; 
    114143        return result; 
    115144    } 
    116  
    117  
    118     Vector opAddAssign(Vector right) 
     145    */ 
     146 
     147 
     148    final Vector opAddAssign(Vector right) 
    119149    { 
    120150        assert(_count == right._count ); 
     
    125155 
    126156 
    127     Vector opSub(Vector right) 
     157    final Vector opSub(Vector right) 
    128158    { 
    129159        assert(_count == right._count); 
     
    135165 
    136166     
    137     Vector opSubAssign(Vector right) 
     167    final Vector opSubAssign(Vector right) 
    138168    { 
    139169        assert(_count == right._count); 
     
    150180     
    151181     
    152     Vector opMul( Vector right ) 
     182    final Vector opMul( Vector right ) 
    153183    { 
    154184        assert(getCount == right.getCount ); 
     
    170200     
    171201     
    172     Vector opMulAssign( Vector right) 
     202    final Vector opMulAssign( Vector right) 
    173203    { 
    174204        assert( getCount == right.getCount ); 
     
    180210    } 
    181211 
    182     Vector opMul(real scale) 
     212    final Vector opMul(real scale) 
    183213    { 
    184214        Vector result = this.clone(); 
     
    187217    } 
    188218 
    189     Vector opMulAssign( real scale ) 
     219    final  Vector opMulAssign( real scale ) 
    190220    { 
    191221        for (int x = 0; x < _count; x++) 
     
    194224    } 
    195225 
    196     Vector opMul_r(real scale) 
     226    final Vector opMul_r(real scale) 
    197227    { 
    198228        Vector result = this.clone(); 
     
    205235    */ 
    206236 
    207     real norm() 
     237    final real norm() 
    208238    { 
    209239        real result = 0; 
     
    218248    */ 
    219249 
    220     Vector normal() 
     250    final Vector normal() 
    221251    { 
    222252        Vector result = this.clone(); 
     
    230260    */ 
    231261     
    232     void normalize() 
     262    final void normalize() 
    233263    { 
    234264        real normValue = cast(real)1.0/norm; 
     
    237267    } 
    238268 
    239     Vector opNeg() 
     269    final Vector opNeg() 
    240270    { 
    241271        Vector result = this.clone(); 
     
    246276    } 
    247277 
    248     T opIndex(int i) 
     278    final T opIndex(int i) 
    249279    { 
    250280        assert(0 <= i && i < _count, "class Vector: Index out of bound"); 
     
    253283    } 
    254284 
    255     T opIndexAssign( T value, int i) 
     285    final T opIndexAssign( T value, int i) 
    256286    { 
    257287        assert(0 <= i && i < _count, "class Vector: Index out of bound"); 
     
    261291    } 
    262292 
    263     int opEquals(Vector right) 
     293    final int opEquals(Vector right) 
    264294    { 
    265295        assert(_count == right._count); 
     
    271301    }    
    272302 
    273     int opCmp(Vector right ) 
     303    final int opCmp(Vector right ) 
    274304    { 
    275305        assert(_count == right._count, "class Vector: _count are not the same"); 
     
    287317    */ 
    288318 
    289     int getCount() 
     319    final int getCount() 
    290320    { 
    291321        return _count; 
    292322    } 
    293323 
    294     char [] toString() 
     324    final char [] toString() 
    295325    { 
    296326        char[] result = ""; 
     
    311341    */ 
    312342 
    313     T scalarMul( Vector right ) 
     343    final T scalarMul( Vector right ) 
    314344    { 
    315345        assert( _count == right._count); 
     
    324354    */ 
    325355     
    326     Vector vectorMul( Vector right) 
     356    final Vector vectorMul( Vector right) 
    327357    { 
    328358        assert(this._count == 3 && right._count == 3); 
     
    341371     
    342372 
    343     Vector clone()        //not an exact clone no more 
     373    final Vector clone()      //not an exact clone no more 
    344374    {    
    345375        Vector result = new Vector(_count); 
     
    362392 
    363393 
    364     void mulAssign( MatrixBase!(T) matrix, Vector vec) 
     394    final void mulAssign( MatrixBase!(T) matrix, Vector vec) 
    365395    { 
    366396        //  MxN Nx1 = Mx1 
    367         assert( matrix.getColumnCount() == vec.getCount(), "matrix size and right vector size do not match"); 
    368         assert(_data.length >= matrix.getRowCount(), "length of the vector data is not high enough"); 
    369         _count = matrix.getRowCount(); 
     397        assert( matrix.columnCount() == vec.getCount(), "matrix size and right vector size do not match"); 
     398        assert(_data.length >= matrix.rowCount(), "length of the vector data is not high enough"); 
     399        _count = matrix.rowCount(); 
    370400        T intermediate; 
    371         for (int r = 0; r < matrix.getRowCount(); r++) 
     401        for (int r = 0; r < matrix.rowCount(); r++) 
    372402        { 
    373403            intermediate = 0; 
    374             for (int c = 0; c < matrix.getColumnCount(); c++) 
     404            for (int c = 0; c < matrix.columnCount(); c++) 
    375405                intermediate += matrix[r,c] * vec[c]; 
    376406            this[r] = intermediate; 
    377407        } 
     408    } 
     409 
     410    //TODO:  
     411 
     412    final void mulAssign(Matrix!(T) matrix, Vector vec) 
     413    { 
     414         
    378415    } 
    379416} 
  • trunk/mathematics/numerical/VectorFixed.d

    r8 r10  
    3434 
    3535 
     36char [] assertIterRange(char [] iterator, char [] list) 
     37{ 
     38    return "assert(" ~ iterator ~ ">=&" ~ list ~ "[0] && " 
     39     ~ iterator ~ "<=&" ~ list ~ "[$-1], \"Iterator out of range\");"; 
     40} 
     41 
     42 
     43 
     44 
     45 
    3646 
    3747/** 
     
    4757        Adds two homogeneous vectors together. 
    4858    */ 
    49  
    5059    VectorFixed homAdd(ref VectorFixed right) 
    5160    { 
     
    196205 
    197206    //Start normal routines 
     207 
     208 
     209 
     210    //TODO: VectorFixed opAdd( ref const VectorFixed right ) 
     211     
     212    VectorFixed opAdd( ref VectorFixed right ) 
     213    { 
     214        VectorFixed result;      
     215        T * resultStop = &result.data[$-1]; 
     216        for (T * resultIter = &result.data[0], rightIter = &right.data[0], dataIter =  &data[0]; resultIter <= resultStop; resultIter++, rightIter++, dataIter++) 
     217        { 
     218            mixin(assertIterRange("resultIter", "result.data")); 
     219            mixin(assertIterRange("rightIter", "right.data")); 
     220            mixin(assertIterRange("dataIter", "data")); 
     221            *resultIter =  *dataIter + *rightIter; 
     222        } 
     223        return result; 
     224    } 
     225 
     226 
    198227     
    199228    /** 
     
    201230    */ 
    202231 
     232 
     233    /* 
    203234    VectorFixed opAdd(ref VectorFixed right) 
    204235    { 
     
    208239        return result; 
    209240    } 
     241    */ 
    210242     
    211243    /** 
  • trunk/mathematics/numerical/algorithms/LuDecomposition.d

    r9 r10  
    5353    int luDecomposition(T)(Matrix!(T) aMatrix, Matrix!(T) bMatrix, out int [] ipivot ) 
    5454    { 
    55         assert( aMatrix.getRowCount() == aMatrix.getColumnCount(), "not a square matrix"); 
    56         assert( aMatrix.getRowCount() == bMatrix.getRowCount(), "first matrix must be nxn second nxnhrs"); 
     55        assert( aMatrix.rowCount() == aMatrix.columnCount(), "not a square matrix"); 
     56        assert( aMatrix.rowCount() == bMatrix.rowCount(), "first matrix must be nxn second nxnhrs"); 
    5757        //Check if matrix is symmetric. 
    5858 
    59         int n = aMatrix.getRowCount(); 
    60         int nrhs = bMatrix.getColumnCount(); 
     59        int n = aMatrix.rowCount(); 
     60        int nrhs = bMatrix.columnCount(); 
    6161        T [] a = aMatrix.getData();         //NxN matrix 
    6262        int lda = aMatrix.getAllocatedRowCount(); 
     
    9292 
    9393unittest { 
     94    Stdout("LU Decomposition").newline; 
    9495    Matrix!(double) aMatrix = new Matrix!(double)(2,2,[1,2,3,4]); 
    9596    Matrix!(double) bMatrix = new Matrix!(double)(2,2,[1,0,0,1]); 
     97    Stdout("Input:").newline; 
     98    Stdout( aMatrix ).newline; 
     99    Stdout( bMatrix ).newline; 
     100    Stdout("Output:").newline; 
    96101    int [] rowPivot;     
    97     luDecomposition!(double) (aMatrix, bMatrix, rowPivot); 
     102    int result = luDecomposition!(double) (aMatrix, bMatrix, rowPivot); 
     103    if (result != 0) Stdout("An error has occured").newline; 
     104    Stdout("resultCode:")(result).newline; 
    98105    Stdout( aMatrix ).newline; 
    99106    Stdout( bMatrix ).newline;   
  • trunk/mathematics/numerical/algorithms/SingularValueDecomposition.d

    r8 r10  
    6363void singularValueDecomposition(T)(Matrix!(T) matrix,out Matrix!(T) uMatrix,out MatrixDiagonal!(T) sMatrix, out Matrix!(T) vTMatrix) 
    6464{ 
    65         uMatrix = new Matrix!(T) (matrix.getRowCount(), matrix.getRowCount()); 
    66         sMatrix = new MatrixDiagonal!(T) (matrix.getRowCount(), matrix.getColumnCount()); 
    67         vTMatrix = new Matrix!(T) (matrix.getColumnCount(), matrix.getColumnCount()); 
     65        uMatrix = new Matrix!(T) (matrix.rowCount(), matrix.rowCount()); 
     66        sMatrix = new MatrixDiagonal!(T) (matrix.rowCount(), matrix.columnCount()); 
     67        vTMatrix = new Matrix!(T) (matrix.columnCount(), matrix.columnCount()); 
    6868 
    6969        T bestLWork; 
    7070        char jobu='A'; 
    7171        char jobvt='A'; 
    72         int m = matrix.getRowCount(); 
    73         int n = matrix.getColumnCount(); 
     72        int m = matrix.rowCount(); 
     73        int n = matrix.columnCount(); 
    7474        T [] a = matrix.getData();          //is this the correct address? 
    7575        int lda = matrix.getAllocatedRowCount();    //LDA needs to figure out more about this. 
    7676        T [] s= sMatrix.getData();          //min(m,n) 
    7777        T [] u = uMatrix.getData();         //LDU, M for 'A' 
    78         int ldu = uMatrix.getRowCount();      //leading dimensions of u 
     78        int ldu = uMatrix.rowCount();     //leading dimensions of u 
    7979        T [] vt = vTMatrix.getData();           //N x N for 'A' 
    80         int ldvt = vTMatrix.getRowCount();        //N for 'A' 
     80        int ldvt = vTMatrix.rowCount();       //N for 'A' 
    8181        int lwork = -1; //dimensions of array work  //Two Calls Find Optimal LWORK 
    8282        int info;  //0 success, <0 -i argument had illegal value