Saint Louis University |
Computer Science 146
|
Dept. of Math & Computer Science |
Topic: Fixing a flaw
Due:
11:59pm Monday, 12 December 2011
Please make sure you adhere to the policies on academic integrity.
In class, we demonstrated the following three flaws in our current version of the software suite.
P = B(range(2,5), range(3,7));and then we attempt to assign to (non-existing) element
P(1,6) = -1000;
In this case, we find that the proxy appears unchanged, as is expected, but the contents of the underlying array have been corrupted.
The second flaw arises when evaluating the subsequent assignment statement
B(range(3,6), range(4,8)) = P;
After executing this command, if we look in the target region within B, the contents do not match the 3x4 pattern that P had represented.
The third flaw arises when evaluating the subsequent assignment statement
B = P;
This statement crashes the program when executed. Presumably, it should have reconfigured B to be a 3x4 matrix with the specified contents.
The goal is to modify the software suite in order to provide more reasonable semantics for all three of the above scenarios. Of course, we want to also do our best to retain the desired efficiency of our matrix proxy framework when possible.
The first bug is rather easy to remedy, once you understand the underlying cause. The second and third problems will take greater care to remedy. Both of those involve subtleties of the assignment statement (operator=) in a case where the right-hand side and left-hand side are interdependent. As part of your approach to fixing those bugs, we ask that you add the following pure virtual function to the public definition of the matrix_expression class, and then that you provide reasonable implementations of it for both the matrix and matrix_proxy classes:
const matrix_expression& underlyingStorage() const;It should return a reference to the object that is responsible for the underlying storage of the data (in our current framework, this result is always a matrix instance). Our approach to fixing the second and third bug will be to use the new function to explicitly check for cases when the right-hand and left-hand expressions of an assignment statement rely on the same underlying storage. In that case, we will take a safer but more expensive approach to the assignment, by explicitly creating a local copy of the right-hand side expression before assigning values to the left-hand side.
If working on turing, change directories into a desired subdirectory of your home folder if desired, and to execute the following command verbatim
cp -R /Public/goldwasser/146/asgn10 .This will cause a new folder named asgn10 to appear in your working directory including all files that you need for this assignment. Alternatively, these files can be downloaded individual from this website. The matrix definition is essentially the same one we have been using for past assignments. However, we have written a new driver for this assignment to make it easier for you to test your code. That driver is named test and can be built with the make command.
You are to submit an updated version of any files that you needed to modify (details on the submission process).