SRWMRBD@windy.dsir.govt.nz (ROBERT) (07/24/89)
Vector/Matrix package I have put together the beginnings of a vector and matrix package. This package supports five classes of matrices: Rectangular matrix; Upper triangular matrix; Lower triangular matrix; Symmetric matrix; Diagonal matrix; and two classes of vector (derived from the rectangular matrix type) Row vector; Column vector. The package supports matrix addition, subtraction, multiplication, solve, transpose and inverse and also addition, subtraction, multiplication and division by a scalar. Operations are expressed by the usual binary operators, for example A * (B + C). Unnecessary copying of matrices is avoided. Objects generated while evaluating an expression are "destructed" as soon as they are no longer required. The package recognises expressions such as A.i() * B as not requiring the complete evaluation of the inverse A.i(). The package operates as follows. Operators such as + and * produce a object with pointers to their operands. A complete expression is evaluated by the = operator or the initialization operation. This allows the package to use a certain amount of "intelligence" when evaluating an expression. The package works under Zortech C++ (1.07). It was too hard for my rather elderly version of Glockenspiel C++. The package is at a test state; it isn't complete yet, but is probably complete enough to see whether my particular approach is a good idea. I do not know how it compares with Doug Lea's package which I haven't seen yet. I don't think there will be one matrix package that satisfies everyone's needs; at least not in C++. And for any given set of needs it often still won't be obvious which approach one should use. Hence it seems a good idea to develop several independent approaches to the problem. As an example I wouldn't recommend my package for 2x2 matrices where the overheads of my package would be significant. Likewise if you are not interested in triangular matrices, you are wasting space in using my package. One of the problems with present package is that all the functions must be linked in to the final code whether or not you need them (unless your linker can delay linking till a routine is actually called). One of the problems with writing the package is the large number of versions you need of each of the binary operations. With 5 distinct classes there could be up to 25 distinct algorithms for each binary operation. I have economised a bit; nevertheless the thought of adding another class (eg sparse matrices) is daunting. Likewise I allow only one type of element, allowing both double and complex, for example, is even more daunting. I don't know a "nice" way of programming the binary operations in C++. For unary operations I use virtual functions to select the correct algorithm for each matrix class; I don't see how to do this in a workable way for the binary operations. The present package is 2500 lines long, too long to put on this news category. If anyone is interested and has an Internet address, I think I can send them a copy. The present copyright status is that I claim copyright but grant permission to use but not to sell. Of course, I take no legal responsibilities for errors or any misfortunes that may result from your use of the package. Please reply to SRWMRBD@WINDY.DSIR.GOVT.NZ
jima@hplsla.HP.COM (Jim Adcock) (07/27/89)
>As an example I wouldn't recommend my package for 2x2 matrices where the >overheads of my package would be significant. Again, people interested in tiny matrices and vectors: 2x2, 1x2, 2x1, 3x3, 1x3 3x1, etc; to use for example in graphics work, may like to try my xvec2, xmat2, xvec3, xmat3 classes. These classes in turn come in the flavours short, int, long, float, double, and complex. The methods are typically in-line, and inline-coded [IE without loops] so as to be about as fast as possible.