Tuesday, 17 April 2012

Give reason why the interface of the MyMatrix class should not look similar to array-of-array. | C++

TheMyMatrix class with operator[] always returns an array object's reference and an element of the MyMatrix, such as a double's reference is returned by the object of an array with an operator[]. Therefore, accessing of elements of the matrix is done by using the syntaxt[j][k] instead of t(j,k).
The operator() method is more flexible than array-of-array[][]. This method is easy in its implementation. On the contrary, the operator[][] method is specific in its use, which means it is used only in the case of the dense matrix.
Let's take an example. In case of bigger rows and columns (logical layout) which are almost of the size of the cache (block of Random Access Memory, used to store data), the retrieval of values from each rows and columns takes a long time and degrades the performance. On the other hand, using the physical layout (column , row) helps in retrieving the source codes files of columns by the rows, swap the ordering of the row/column using the operator() and improves the performance. Therefore, it is better to use physical iayout(column, row).

No comments: