1\par 2\section{Prototypes and descriptions of {\tt A2} methods} 3\label{section:A2:proto} 4\par 5This section contains brief descriptions including prototypes 6of all methods that belong to the {\tt A2} object. 7\par 8\subsection{Basic methods} 9\label{subsection:A2:proto:basics} 10\par 11As usual, there are four basic methods to support object creation, 12setting default fields, clearing any allocated data, and free'ing 13the object. 14\par 15%======================================================================= 16\begin{enumerate} 17%----------------------------------------------------------------------- 18\item 19\begin{verbatim} 20A2 * A2_new ( void ) ; 21\end{verbatim} 22\index{A2_new@{\tt A2\_new()}} 23This method simply allocates storage for the {\tt A2} structure 24and then sets the default fields by a call to 25{\tt A2\_setDefaultFields()}. 26%----------------------------------------------------------------------- 27\item 28\begin{verbatim} 29void A2_setDefaultFields ( A2 *mtx ) ; 30\end{verbatim} 31\index{A2_setDefaultFields@{\tt A2\_setDefaultFields()}} 32The structure's fields are set to default values: 33{\tt type} = {\tt SPOOLES\_REAL}, 34{\tt n1} = {\tt inc1} = {\tt n2} = {\tt inc2} = {\tt nowned} = 0 and 35{\tt entries} = {\tt NULL} . 36\par \noindent {\it Error checking:} 37If {\tt mtx} is {\tt NULL}, 38an error message is printed and the program exits. 39%----------------------------------------------------------------------- 40\item 41\begin{verbatim} 42void A2_clearData ( A2 *mtx ) ; 43\end{verbatim} 44\index{A2_clearData@{\tt A2\_clearData()}} 45This method clears the object and free's any owned data. 46If {\tt nowned > 0} and {\tt entries} is not {\tt NULL}, 47then {\tt DVfree(entries)} is called to free the storage. 48It calls {\tt A2\_setDefaultFields()}. 49\par \noindent {\it Error checking:} 50If {\tt mtx} is {\tt NULL}, 51an error message is printed and the program exits. 52%----------------------------------------------------------------------- 53\item 54\begin{verbatim} 55void A2_free ( A2 *mtx ) ; 56\end{verbatim} 57\index{A2_free@{\tt A2\_free()}} 58This method releases any storage by a call to 59{\tt A2\_clearData()} and then free the space for {\tt mtx}. 60\par \noindent {\it Error checking:} 61If {\tt mtx} is {\tt NULL}, 62an error message is printed and the program exits. 63%----------------------------------------------------------------------- 64\end{enumerate} 65\par 66\subsection{Instance methods} 67\label{subsection:A2:proto:instance} 68\par 69%======================================================================= 70\begin{enumerate} 71%----------------------------------------------------------------------- 72\item 73\begin{verbatim} 74int A2_nrow ( A2 *mtx ) ; 75\end{verbatim} 76\index{A2_nrow@{\tt A2\_nrow()}} 77This method returns the number of rows in the matrix. 78\par \noindent {\it Error checking:} 79If {\tt mtx} is {\tt NULL}, 80an error message is printed and the program exits. 81%----------------------------------------------------------------------- 82\item 83\begin{verbatim} 84int A2_ncol ( A2 *mtx ) ; 85\end{verbatim} 86\index{A2_ncol@{\tt A2\_ncol()}} 87This method returns the number of columns in the matrix. 88\par \noindent {\it Error checking:} 89If {\tt mtx} is {\tt NULL}, 90an error message is printed and the program exits. 91%----------------------------------------------------------------------- 92\item 93\begin{verbatim} 94int A2_inc1 ( A2 *mtx ) ; 95\end{verbatim} 96\index{A2_inc1@{\tt A2\_inc1()}} 97This method returns the primary increment, the stride in memory 98(with respect to real or complex entries) 99between adjacent entries in the same column. 100\par \noindent {\it Error checking:} 101If {\tt mtx} is {\tt NULL}, 102an error message is printed and the program exits. 103%----------------------------------------------------------------------- 104\item 105\begin{verbatim} 106int A2_inc2 ( A2 *mtx ) ; 107\end{verbatim} 108\index{A2_inc2@{\tt A2\_inc2()}} 109This method returns the secondary increment, the stride in memory 110(with respect to real or complex entries) 111between adjacent entries in the same row. 112\par \noindent {\it Error checking:} 113If {\tt mtx} is {\tt NULL}, 114an error message is printed and the program exits. 115%----------------------------------------------------------------------- 116\item 117\begin{verbatim} 118double * A2_entries ( A2 *mtx ) ; 119\end{verbatim} 120\index{A2_entries@{\tt A2\_entries()}} 121This method returns a pointer to the base address of the entries. 122\par \noindent {\it Error checking:} 123If {\tt mtx} is {\tt NULL}, 124an error message is printed and the program exits. 125%----------------------------------------------------------------------- 126\item 127\begin{verbatim} 128double * A2_row ( A2 *mtx, int irow ) ; 129\end{verbatim} 130\index{A2_row@{\tt A2\_row()}} 131This method returns a pointer to the leading element of row {\tt irow}. 132\par \noindent {\it Error checking:} 133If {\tt mtx} or {\tt entries} is {\tt NULL}, 134or if {\tt irow} is not in {\tt [0,n1-1]}, 135an error message is printed and the program exits. 136%----------------------------------------------------------------------- 137\item 138\begin{verbatim} 139double * A2_column ( A2 *mtx, int jcol ) ; 140\end{verbatim} 141\index{A2_column@{\tt A2\_column()}} 142This method returns a pointer to the leading element 143of column {\tt jcol}. 144\par \noindent {\it Error checking:} 145If {\tt mtx} or {\tt entries} is {\tt NULL}, 146or if {\tt jcol} is not in {\tt [0,n2-1]}, 147an error message is printed and the program exits. 148%----------------------------------------------------------------------- 149\item 150\begin{verbatim} 151void A2_realEntry ( A2 *mtx, int irow, int jcol, double *pValue ) ; 152\end{verbatim} 153\index{A2_realEntry@{\tt A2\_realEntry()}} 154This method fills {\tt *pValue} with the entry in 155location {\tt (irow, jcol)}. 156\par \noindent {\it Error checking:} 157If {\tt mtx} or {\tt pValue} is {\tt NULL}, 158or if the matrix is not real, 159or {\tt irow} is not in {\tt [0,n1-1]}, 160or if {\tt jcol} is not in {\tt [0,n2-1]}, 161an error message is printed and the program exits. 162%----------------------------------------------------------------------- 163\item 164\begin{verbatim} 165void A2_complexEntry ( A2 *mtx, int irow, int jcol, 166 double *pReal, double *pImag ) ; 167\end{verbatim} 168\index{A2_complexEntry@{\tt A2\_complexEntry()}} 169This method fills {\tt (*pReal,*pImag)} with the entry in 170location {\tt (irow, jcol)}. 171\par \noindent {\it Error checking:} 172If {\tt mtx}, {\tt pReal} or {\tt pImag} is {\tt NULL}, 173or if the matrix is not complex, 174or {\tt irow} is not in {\tt [0,n1-1]}, 175or if {\tt jcol} is not in {\tt [0,n2-1]}, 176an error message is printed and the program exits. 177%----------------------------------------------------------------------- 178\item 179\begin{verbatim} 180void A2_setRealEntry ( A2 *mtx, int irow, int jcol, double value ) ; 181\end{verbatim} 182\index{A2_setRealEntry@{\tt A2\_setRealEntry()}} 183This method sets entry {\tt (irow,jcol)} to {\tt value}. 184\par \noindent {\it Error checking:} 185If {\tt mtx} is {\tt NULL}, 186or if the matrix is not real, 187or {\tt irow} is not in {\tt [0,n1-1]} 188or if {\tt jcol} is not in {\tt [0,n2-1]}, 189an error message is printed and the program exits. 190%----------------------------------------------------------------------- 191\item 192\begin{verbatim} 193void A2_setComplexEntry ( A2 *mtx, int irow, int jcol, 194 double real, double imag ) ; 195\end{verbatim} 196\index{A2_setComplexEntry@{\tt A2\_setComplexEntry()}} 197This method sets entry {\tt (irow,jcol)} to {\tt (real,imag)}. 198\par \noindent {\it Error checking:} 199If {\tt mtx} is {\tt NULL}, 200or if the matrix is not complex, 201or {\tt irow} is not in {\tt [0,n1-1]} 202or if {\tt jcol} is not in {\tt [0,n2-1]}, 203an error message is printed and the program exits. 204%----------------------------------------------------------------------- 205\item 206\begin{verbatim} 207void A2_pointerToRealEntry ( A2 *mtx, int irow, int jcol, double **ppValue ) ; 208\end{verbatim} 209\index{A2_pointerToRealEntry@{\tt A2\_pointerToRealEntry()}} 210This method sets {\tt *ppValue} to the pointer 211of the {\tt (irow,jcol)} entry. 212\par \noindent {\it Error checking:} 213If {\tt mtx} or {\tt ppValue} is {\tt NULL}, 214or if the matrix is not real, 215or if {\tt irow} is not in {\tt [0,n1-1]}, 216or if {\tt jcol} is not in {\tt [0,n2-1]}, 217an error message is printed and the program exits. 218%----------------------------------------------------------------------- 219\item 220\begin{verbatim} 221void A2_pointerToComplexEntry ( A2 *mtx, int irow, int jcol, 222 double **ppReal, double **ppImag ) ; 223\end{verbatim} 224\index{A2_pointerToComplexEntry@{\tt A2\_pointerToComplexEntry()}} 225This method sets {\tt *ppReal} to the pointer to the real part 226of the {\tt (irow,jcol)} entry, 227and sets {\tt *ppImag} to the pointer to the imaginary part 228of the {\tt (irow,jcol)} entry. 229\par \noindent {\it Error checking:} 230If {\tt mtx}, {\tt ppReal} or {\tt ppImag} is {\tt NULL}, 231or if the matrix is not complex, 232or if {\tt irow} is not in {\tt [0,n1-1]}, 233or if {\tt jcol} is not in {\tt [0,n2-1]}, 234an error message is printed and the program exits. 235%----------------------------------------------------------------------- 236\end{enumerate} 237\par 238\subsection{Initialize methods} 239\label{subsection:A2:proto:initial} 240\par 241%======================================================================= 242\begin{enumerate} 243%----------------------------------------------------------------------- 244\item 245\begin{verbatim} 246void A2_init ( A2 *mtx, int type, int n1, int n2, int inc1, int inc2, 247 double *entries ) ; 248\end{verbatim} 249\index{A2_init@{\tt A2\_init()}} 250This is the basic initializer method. 251We require that {\tt mtx} not be {\tt NULL}, 252{\tt type} be either {\tt SPOOLES\_REAL} or {\tt SPOOLES\_COMPLEX}, 253{\tt n1} and {\tt n2} both be positive, 254and both {\tt inc1} and {\tt inc2} both be 255positive and that one of them be equal to one. 256Also, we only initialize a full matrix, i.e., 257one of 258{\tt inc1 = 1} and {\tt inc2 = nrow} 259or 260{\tt inc1 = ncol} and {\tt inc2 = 1} 261must hold. 262\par 263The object is first cleared with a call to {\tt A2\_clearData()}. 264If {\tt entries} is {\tt NULL} then {\tt n1*n2} new entries 265are found, {\tt mtx->entries} is set to this address and {\tt nowned} 266is set to {\tt n1*n2}. 267If {\tt entries} is not {\tt NULL}, then {\tt mtx->entries} is set 268to {\tt entries} and {\tt nowned} is set to zero. 269\par \noindent {\it Error checking:} 270If {\tt mtx} is {\tt NULL}, 271or if {\tt n1}, {\tt n2}, {\tt inc1} or {\tt inc2} are 272less than or equal to zero, 273or if the matrix is not full matrix 274(i.e., {\tt inc1} must be {\tt 1} and {\tt inc2} must be {\tt n1}, 275{\it or} 276{\tt inc1} must be {\tt n2} and {\tt inc2} must be {\tt 1}), 277an error message is printed and zero is returned. 278%----------------------------------------------------------------------- 279\item 280\begin{verbatim} 281void A2_subA2 ( A2 *mtxA, A2 *mtxB, 282 int firstrow, int lastrow, int firstcol, int lastcol ) ; 283\end{verbatim} 284\index{A2_subA2@{\tt A2\_subA2()}} 285This initializer method makes the object {\tt mtxA} point into a 286submatrix of object {\tt mtxB}, as 287\begin{verbatim} 288A(0:lastrow-firstrow,0:lastcol-firstcol) = B(firstrow:lastrow, firstcol:lastcol) 289\end{verbatim} 290Note, {\tt firstrow}, {\tt lastrow}, {\tt firstcol} and {\tt lastcol} 291must satisfy {\tt 0 <= firstrow <= lastrow < mtxB->n1} 292and {\tt 0 <= firstcol <= lastcol < mtxB->n2}. 293Object {\tt mtxA} does not own its entries, but points into the 294entries of {\tt mtxB}. 295\par \noindent {\it Error checking:} 296If {\tt mtxA} or {\tt mtxB} are {\tt NULL}, 297or if {\tt firstrow} or {\tt lastrow} are out of range, 298or if {\tt firstcol} or {\tt lastcol} are out of range, 299an error message is printed and zero is returned. 300%----------------------------------------------------------------------- 301\end{enumerate} 302\par 303\subsection{Methods used in the $QR$ factorization} 304\label{subsection:A2:proto:QR} 305\par 306%======================================================================= 307\begin{enumerate} 308%----------------------------------------------------------------------- 309\item 310\begin{verbatim} 311void A2_makeStaircase ( A2 *A ) ; 312\end{verbatim} 313\index{A2_makeStaircase@{\tt A2\_makeStaircase()}} 314This method permutes the rows of {\tt A} by the location of the 315leading nonzero of each row. 316Upon return, the matrix is in {\it staircase} form. 317\par \noindent {\it Error checking:} 318If {\tt A} is {\tt NULL}, 319an error message is printed and the program exits. 320%----------------------------------------------------------------------- 321\item 322\begin{verbatim} 323double A2_QRreduce ( A2 *A, DV *workDV, int msglvl, FILE *msgFile ) ; 324\end{verbatim} 325\index{A2_QRreduce@{\tt A2\_QRreduce()}} 326This method computes $A = QR$ factorization. 327On return, the matrix $Q$ is not available, and $R$ is found in the 328upper triangle or upper trapezoid of {\tt A}. 329The Householder vectors are stored in the lower triangle of {\tt 330mtxA}, with $v_j(j) = 1.0$. 331The return value is the number of floating point operations that 332were executed. 333\par \noindent {\it Error checking:} 334If {\tt A} or {\tt workDV} is {\tt NULL}, 335or if {\tt msglvl > 0} and {\tt msgFile} if {\tt NULL}, 336an error message is printed and the program exits. 337%----------------------------------------------------------------------- 338\item 339\begin{verbatim} 340void A2_computeQ ( A2 *Q, A2 *A, DV *workDV, int msglvl, FILE *msgFile ) ; 341\end{verbatim} 342\index{A2_computeQ@{\tt A2\_computeQ()}} 343This method computes $Q$ from the $A = QR$ factorization computed 344in {\tt A2\_QRreduce()}. 345Note: {\tt A} and {\tt Q} must be column major. 346\par \noindent {\it Error checking:} 347If {\tt Q}, {\tt A} or {\tt workDV} is {\tt NULL}, 348or if {\tt msglvl > 0} and {\tt msgFile} if {\tt NULL}, 349an error message is printed and the program exits. 350%----------------------------------------------------------------------- 351\item 352\begin{verbatim} 353void A2_applyQT ( A2 *Y, A2 *A, A2 *X, DV *workDV, int msglvl, FILE *msgFile ) ; 354\end{verbatim} 355\index{A2_applyQT@{\tt A2\_applyQT()}} 356This method computes $Y = Q^T X$ (if real) or $Y = Q^H X$ (if 357complex), where $Q$ is stored in Householder vectors inside $A$. 358We assume that $A2\_reduce()$ has been previously called with $A$ 359as an argument. 360Since $Y$ is computed column-by-column, $X$ and $Y$ can be the same 361{\tt A2} object. 362The {\tt workDV} object is resized as necessary. 363Note: {\tt Y}, {\tt A} and {\tt X} must be column major. 364\par \noindent {\it Error checking:} 365If {\tt Y}, {\tt A}, {\tt X} or {\tt workDV} is {\tt NULL}, 366or if {\tt msglvl > 0} and {\tt msgFile} if {\tt NULL}, 367or if {\tt Y}, {\tt A} or {\tt X} is not column major, 368or if the types of {\tt Y}, {\tt A} and {\tt X} are not the same, 369an error message is printed and the program exits. 370%----------------------------------------------------------------------- 371\end{enumerate} 372\par 373\subsection{Norm methods} 374\label{subsection:A2:proto:norms} 375\par 376These methods return a norm of a row or a column, or the easily 377computable norms of the matrix. 378%======================================================================= 379\begin{enumerate} 380%----------------------------------------------------------------------- 381\item 382\begin{verbatim} 383double A2_maxabs ( A2 *mtx ) ; 384\end{verbatim} 385\index{A2_maxabs@{\tt A2\_maxabs()}} 386This method returns magnitude of the entry with largest magnitude. 387\par \noindent {\it Error checking:} 388If {\tt mtx} is {\tt NULL}, 389an error message is printed and the program exits. 390%----------------------------------------------------------------------- 391\item 392\begin{verbatim} 393double A2_frobNorm ( A2 *mtx ) ; 394\end{verbatim} 395\index{A2_frobNorm@{\tt A2\_frobNorm()}} 396This method returns the Frobenius norm of the matrix. 397\par \noindent {\it Error checking:} 398If {\tt mtx} is {\tt NULL}, 399an error message is printed and the program exits. 400%----------------------------------------------------------------------- 401\item 402\begin{verbatim} 403double A2_oneNorm ( A2 *mtx ) ; 404\end{verbatim} 405\index{A2_oneNorm@{\tt A2\_oneNorm()}} 406This method returns the one norm of the matrix. 407\par \noindent {\it Error checking:} 408If {\tt mtx} is {\tt NULL}, 409an error message is printed and the program exits. 410%----------------------------------------------------------------------- 411\item 412\begin{verbatim} 413double A2_infinityNorm ( A2 *mtx ) ; 414\end{verbatim} 415\index{A2_infinityNorm@{\tt A2\_infinityNorm()}} 416This method returns the infinity norm of the matrix. 417\par \noindent {\it Error checking:} 418If {\tt mtx} is {\tt NULL}, 419an error message is printed and the program exits. 420%----------------------------------------------------------------------- 421\item 422\begin{verbatim} 423double A2_oneNormOfColumn ( A2 *mtx, int jcol ) ; 424\end{verbatim} 425\index{A2_oneNormOfColumn@{\tt A2\_oneNormOfColumn()}} 426This method returns the one-norm of column {\tt jcol} of the matrix. 427\par \noindent {\it Error checking:} 428If {\tt mtx} is {\tt NULL}, or {\tt jcol} is not in {\tt [0,n2-1]}, 429an error message is printed and the program exits. 430%----------------------------------------------------------------------- 431\item 432\begin{verbatim} 433double A2_twoNormOfColumn ( A2 *mtx, int jcol ) ; 434\end{verbatim} 435\index{A2_twoNormOfColumn@{\tt A2\_twoNormOfColumn()}} 436This method returns the two-norm of column {\tt jcol} of the matrix. 437\par \noindent {\it Error checking:} 438If {\tt mtx} is {\tt NULL}, or {\tt jcol} is not in {\tt [0,n2-1]}, 439an error message is printed and the program exits. 440%----------------------------------------------------------------------- 441\item 442\begin{verbatim} 443double A2_infinityNormOfColumn ( A2 *mtx, int jcol ) ; 444\end{verbatim} 445\index{A2_infinityNormOfColumn@{\tt A2\_infinityNormOfColumn()}} 446This method returns the infinity-norm of column {\tt jcol} 447of the matrix. 448\par \noindent {\it Error checking:} 449If {\tt mtx} is {\tt NULL}, or {\tt jcol} is not in {\tt [0,n2-1]}, 450an error message is printed and the program exits. 451%----------------------------------------------------------------------- 452\item 453\begin{verbatim} 454double A2_oneNormOfRow ( A2 *mtx, int irow ) ; 455\end{verbatim} 456\index{A2_oneNormOfRow@{\tt A2\_oneNormOfRow()}} 457This method returns the one-norm of row {\tt irow} of the matrix. 458\par \noindent {\it Error checking:} 459If {\tt mtx} is {\tt NULL}, or {\tt irow} is not in {\tt [0,n1-1]}, 460an error message is printed and the program exits. 461%----------------------------------------------------------------------- 462\item 463\begin{verbatim} 464double A2_twoNormOfRow ( A2 *mtx, int irow ) ; 465\end{verbatim} 466\index{A2_twoNormOfRow@{\tt A2\_twoNormOfRow()}} 467This method returns the two-norm of row {\tt irow} of the matrix. 468\par \noindent {\it Error checking:} 469If {\tt mtx} is {\tt NULL}, or {\tt irow} is not in {\tt [0,n1-1]}, 470an error message is printed and the program exits. 471%----------------------------------------------------------------------- 472\item 473\begin{verbatim} 474double A2_infinityNormOfRow ( A2 *mtx, int irow ) ; 475\end{verbatim} 476\index{A2_infinityNormOfRow@{\tt A2\_infinityNormOfRow()}} 477This method returns the infinity-norm of row {\tt irow} 478of the matrix. 479\par \noindent {\it Error checking:} 480If {\tt mtx} is {\tt NULL}, or {\tt irow} is not in {\tt [0,n1-1]}, 481an error message is printed and the program exits. 482%----------------------------------------------------------------------- 483\end{enumerate} 484\par 485\subsection{Sort methods} 486\label{subsection:A2:proto:sort} 487\par 488%======================================================================= 489\begin{enumerate} 490%----------------------------------------------------------------------- 491\item 492\begin{verbatim} 493void A2_permuteRows ( A2 *mtx, int nrow, int index[] ) ; 494\end{verbatim} 495\index{A2_permuteRows@{\tt A2\_permuteRows()}} 496The {\tt index[]} vector contains the {\it row ids} of the leading 497{\tt nrow} rows. 498This method permutes the leading {\tt nrow} rows of the matrix 499so that the {\tt index[]} vector is in ascending order. 500This method calls {\tt A2\_permuteRows()} but does not overwrite 501the {\tt index[]} vector. 502\par 503\par \noindent {\it Error checking:} 504If {\tt mtx} or {\tt index[]} is {\tt NULL}, 505or if {\tt nrow < 0} or {\tt nrow > n1}, 506an error message is printed and the program exits. 507%----------------------------------------------------------------------- 508\item 509\begin{verbatim} 510void A2_permuteColumns ( A2 *mtx, int nrow, int index[] ) ; 511\end{verbatim} 512\index{A2_permuteColumns@{\tt A2\_permuteColumns()}} 513The {\tt index[]} vector contains the {\it column ids} of the leading 514{\tt ncol} rows. 515This method permutes the leading {\tt ncol} columns of the matrix 516so that the {\tt index[]} vector is in ascending order. 517This method calls {\tt A2\_permuteColumns()} but does not overwrite 518the {\tt index[]} vector. 519\par 520\par \noindent {\it Error checking:} 521If {\tt mtx} or {\tt index[]} is {\tt NULL}, 522or if {\tt ncol < 0} or {\tt ncol > n2}, 523an error message is printed and the program exits. 524%----------------------------------------------------------------------- 525\item 526\begin{verbatim} 527int A2_sortRowsUp ( A2 *mtx, int nrow, int rowids[] ) ; 528\end{verbatim} 529\index{A2_sortRowsUp@{\tt A2\_sortRowsUp()}} 530This method sorts the leading {\tt nrow} rows of the matrix 531into ascending order with respect to the {\tt rowids[]} vector. 532The return value is the number of row swaps made. 533\par 534\par \noindent {\it Error checking:} 535If {\tt mtx} or {\tt rowids} is {\tt NULL}, 536or if {\tt nrow < 0} or {\tt nrow > n1}, 537an error message is printed and the program exits. 538%----------------------------------------------------------------------- 539\item 540\begin{verbatim} 541int A2_sortColumnsUp ( A2 *mtx, int ncol, int colids[] ) ; 542\end{verbatim} 543\index{A2_sortColumnsUp@{\tt A2\_sortColumnsUp()}} 544This method sorts the leading {\tt ncol} columnss of the matrix 545into ascending order with respect to the {\tt colids[]} vector. 546The return value is the number of column swaps made. 547\par 548\par \noindent {\it Error checking:} 549If {\tt mtx} or {\tt colids} is {\tt NULL}, 550or if {\tt ncol < 0} or {\tt ncol > n2}, 551an error message is printed and the program exits. 552%----------------------------------------------------------------------- 553\end{enumerate} 554\par 555\subsection{Utility methods} 556\label{subsection:A2:proto:utilities} 557\par 558%======================================================================= 559\begin{enumerate} 560%----------------------------------------------------------------------- 561\item 562\begin{verbatim} 563int A2_sizeOf ( A2 *mtx ) ; 564\end{verbatim} 565\index{A2_sizeOf@{\tt A2\_sizeOf()}} 566This method returns the number of bytes owned by this object. 567\par \noindent {\it Error checking:} 568If {\tt mtx} is {\tt NULL} 569an error message is printed and the program exits. 570%----------------------------------------------------------------------- 571\item 572\begin{verbatim} 573void A2_shiftBase ( A2 *mtx, int rowoff, int coloff ) ; 574\end{verbatim} 575\index{A2_shiftbase@{\tt A2\_shiftBase()}} 576This method is used to shift the base of the entries and adjust 577dimensions of the {\tt A2} object. 578\begin{verbatim} 579mtx(0:n1-rowoff-1,0:n2-coloff-1) := mtx(rowoff:n1-1,coloff:n2-1) 580\end{verbatim} 581\par \noindent {\it Error checking:} 582If {\tt mtx} is {\tt NULL} 583an error message is printed and the program exits. 584%----------------------------------------------------------------------- 585\item 586\begin{verbatim} 587int A2_rowMajor ( A2 *mtx ) ; 588\end{verbatim} 589\index{A2_rowMajor@{\tt A2\_rowMajor()}} 590This method returns 1 if the storage is row major, 591otherwise it returns zero. 592\par \noindent {\it Error checking:} 593If {\tt mtx} is {\tt NULL}, 594an error message is printed and the program exits. 595%----------------------------------------------------------------------- 596\item 597\begin{verbatim} 598int A2_columnMajor ( A2 *mtx ) ; 599\end{verbatim} 600\index{A2_columnMajor@{\tt A2\_columnMajor()}} 601This method returns 1 if the storage is column major, 602otherwise it returns zero. 603\par \noindent {\it Error checking:} 604If {\tt mtx} is {\tt NULL}, 605an error message is printed and the program exits. 606%----------------------------------------------------------------------- 607\item 608\begin{verbatim} 609void A2_transpose ( A2 *mtx ) ; 610\end{verbatim} 611\index{A2_transpose@{\tt A2\_transpose()}} 612This method replaces {\tt mtx} with its transpose. 613Note, this takes $O(1)$ operations since we just swap dimensions and 614increments. 615\par \noindent {\it Error checking:} 616If {\tt mtx} is {\tt NULL}, 617an error message is printed and the program exits. 618%----------------------------------------------------------------------- 619\item 620\begin{verbatim} 621void A2_extractRow ( A2 *mtx, double row[], int irow ) ; 622\end{verbatim} 623\index{A2_extractRow@{\tt A2\_extractRow()}} 624This method fills the {\tt row[]} vector with row {\tt irow} of the 625matrix. 626\par \noindent {\it Error checking:} 627If {\tt mtx}, {\tt entries} or {\tt row} are {\tt NULL}, 628or if {\tt irow} is not in {\tt [0,n1-1]}, 629an error message is printed and the program exits. 630%----------------------------------------------------------------------- 631\item 632\begin{verbatim} 633void A2_extractRowDV ( A2 *mtx, DV *rowDV, int irow ) ; 634\end{verbatim} 635\index{A2_extractRowDV@{\tt A2\_extractRowDV()}} 636This method fills the {\tt rowDV} object with row {\tt irow} of the 637matrix. 638\par \noindent {\it Error checking:} 639If {\tt mtx} or {\tt rowDV} are {\tt NULL}, 640or if the matrix is not real, 641or if {\tt irow} is not in {\tt [0,n1-1]}, 642an error message is printed and the program exits. 643%----------------------------------------------------------------------- 644\item 645\begin{verbatim} 646void A2_extractRowZV ( A2 *mtx, ZV *rowZV, int irow ) ; 647\end{verbatim} 648\index{A2_extractRowZV@{\tt A2\_extractRowZV()}} 649This method fills the {\tt rowZV} object with row {\tt irow} of the 650matrix. 651\par \noindent {\it Error checking:} 652If {\tt mtx} or {\tt rowZV} are {\tt NULL}, 653or if the matrix is not complex, 654or if {\tt irow} is not in {\tt [0,n1-1]}, 655an error message is printed and the program exits. 656%----------------------------------------------------------------------- 657\item 658\begin{verbatim} 659void A2_extractColumn ( A2 *mtx, double col[], int jcol ) ; 660\end{verbatim} 661\index{A2_extractColumn@{\tt A2\_extractColumn()}} 662This method fills the {\tt col[]} vector 663with column {\tt jcol} of the matrix. 664\par \noindent {\it Error checking:} 665If {\tt mtx}, {\tt entries} or {\tt col} are {\tt NULL}, 666or if {\tt jcol} is not in {\tt [0,n2-1]}, 667an error message is printed and the program exits. 668%----------------------------------------------------------------------- 669\item 670\begin{verbatim} 671void A2_extractColumnDV ( A2 *mtx, DV *colDV, int jcol ) ; 672\end{verbatim} 673\index{A2_extractColumnDV@{\tt A2\_extractColumnDV()}} 674This method fills the {\tt colDV} object 675with column {\tt jcol} of the matrix. 676\par \noindent {\it Error checking:} 677If {\tt mtx} or {\tt colDV} are {\tt NULL}, 678or if the matrix is not complex, 679or if {\tt jcol} is not in {\tt [0,n2-1]}, 680an error message is printed and the program exits. 681%----------------------------------------------------------------------- 682\item 683\begin{verbatim} 684void A2_extractColumnZV ( A2 *mtx, ZV *colZV, int jcol ) ; 685\end{verbatim} 686\index{A2_extractColumnZV@{\tt A2\_extractColumnZV()}} 687This method fills the {\tt colZV} object 688with column {\tt jcol} of the matrix. 689\par \noindent {\it Error checking:} 690If {\tt mtx} or {\tt colZV} are {\tt NULL}, 691or if the matrix is not complex, 692or if {\tt jcol} is not in {\tt [0,n2-1]}, 693an error message is printed and the program exits. 694%----------------------------------------------------------------------- 695\item 696\begin{verbatim} 697void A2_setRow ( A2 *mtx, double row[], int irow ) ; 698\end{verbatim} 699\index{A2_setRow@{\tt A2\_setRow()}} 700This method fills row {\tt irow} of the matrix 701with the entries in the {\tt row[]} vector. 702\par \noindent {\it Error checking:} 703If {\tt mtx}, {\tt entries} or {\tt row[]} are {\tt NULL}, 704or if {\tt irow} is not in {\tt [0,n1-1]}, 705an error message is printed and the program exits. 706%----------------------------------------------------------------------- 707\item 708\begin{verbatim} 709void A2_setRowDV ( A2 *mtx, DV rowDV, int irow ) ; 710\end{verbatim} 711\index{A2_setRowDV@{\tt A2\_setRowDV()}} 712This method fills row {\tt irow} of the matrix 713with the entries in the {\tt rowDV} object. 714\par \noindent {\it Error checking:} 715If {\tt mtx} or {\tt rowDV} are {\tt NULL}, 716or if the matrix is not real, 717or if {\tt irow} is not in {\tt [0,n1-1]}, 718an error message is printed and the program exits. 719%----------------------------------------------------------------------- 720\item 721\begin{verbatim} 722void A2_setRowZV ( A2 *mtx, ZV rowZV, int irow ) ; 723\end{verbatim} 724\index{A2_setRowZV@{\tt A2\_setRowZV()}} 725This method fills row {\tt irow} of the matrix 726with the entries in the {\tt rowZV} object. 727\par \noindent {\it Error checking:} 728If {\tt mtx} or {\tt rowZV} are {\tt NULL}, 729or if the matrix is not complex, 730or if {\tt irow} is not in {\tt [0,n1-1]}, 731an error message is printed and the program exits. 732%----------------------------------------------------------------------- 733\item 734\begin{verbatim} 735void A2_setColumn ( A2 *mtx, double col[], int jcol ) ; 736\end{verbatim} 737\index{A2_setColumn@{\tt A2\_setColumn()}} 738This method fills column {\tt jcol} of the matrix with 739the entries in the {\tt col[]} vector. 740\par \noindent {\it Error checking:} 741If {\tt mtx} or {\tt colZV} are {\tt NULL}, 742or if {\tt jcol} is not in {\tt [0,n2-1]}, 743an error message is printed and the program exits. 744%----------------------------------------------------------------------- 745\item 746\begin{verbatim} 747void A2_setColumnDV ( A2 *mtx, DV colDV, int jcol ) ; 748\end{verbatim} 749\index{A2_setColumnDV@{\tt A2\_setColumnDV()}} 750This method fills column {\tt jcol} of the matrix with 751the entries in the {\tt colDV} object. 752\par \noindent {\it Error checking:} 753If {\tt mtx} or {\tt colDV} are {\tt NULL}, 754or if the matrix is not complex, 755or if {\tt jcol} is not in {\tt [0,n2-1]}, 756an error message is printed and the program exits. 757%----------------------------------------------------------------------- 758\item 759\begin{verbatim} 760void A2_setColumnZV ( A2 *mtx, ZV colZV, int jcol ) ; 761\end{verbatim} 762\index{A2_setColumnZV@{\tt A2\_setColumnZV()}} 763This method fills column {\tt jcol} of the matrix with 764the entries in the {\tt colZV} object. 765\par \noindent {\it Error checking:} 766If {\tt mtx} or {\tt colZV} are {\tt NULL}, 767or if the matrix is not complex, 768or if {\tt jcol} is not in {\tt [0,n2-1]}, 769an error message is printed and the program exits. 770%----------------------------------------------------------------------- 771\item 772\begin{verbatim} 773void A2_fillRandomUniform ( A2 *mtx, double lower, double upper, int seed ) ; 774\end{verbatim} 775\index{A2_fillRandomUniform@{\tt A2\_fillRandomUniform()}} 776This method fills the matrix with random numbers taken from a 777uniform distribution on {\tt [lower,upper]} using the {\tt Drand} 778object. 779\par \noindent {\it Error checking:} 780If {\tt mtx} is {\tt NULL}, 781an error message is printed and the program exits. 782%----------------------------------------------------------------------- 783\item 784\begin{verbatim} 785void A2_fillRandomNormal ( A2 *mtx, double mean, double variance, int seed ) ; 786\end{verbatim} 787\index{A2_fillRandomNormal@{\tt A2\_fillRandomNormal()}} 788This method fills the matrix with random numbers taken from a 789normal distribution with mean {\tt mean} and variance {\tt 790variance} using the {\tt Drand} object. 791\par \noindent {\it Error checking:} 792If {\tt mtx} is {\tt NULL}, 793an error message is printed and the program exits. 794%----------------------------------------------------------------------- 795\item 796\begin{verbatim} 797void A2_fillWithIdentity ( A2 *mtx ) ; 798\end{verbatim} 799\index{A2_fillWithIdentity@{\tt A2\_fillWithIdentity()}} 800This method fills the matrix with the identity matrix. 801\par \noindent {\it Error checking:} 802If {\tt mtx} is {\tt NULL} or if {\tt n1 != n2}, 803an error message is printed and the program exits. 804%----------------------------------------------------------------------- 805\item 806\begin{verbatim} 807void A2_zero ( A2 *mtx ) ; 808\end{verbatim} 809\index{A2_zero@{\tt A2\_zero()}} 810This method fills the matrix with zeros. 811\par \noindent {\it Error checking:} 812If {\tt mtx} is {\tt NULL}, 813an error message is printed and the program exits. 814%----------------------------------------------------------------------- 815\item 816\begin{verbatim} 817void A2_copy ( A2 *mtxA, A2 *mtxB ) ; 818\end{verbatim} 819\index{A2_copy@{\tt A2\_copy()}} 820This method copies entries from matrix {\tt mtxB} 821into matrix {\tt mtxA}. 822Note, {\tt mtxA} and {\tt mtxB} need not be of the same size, 823the leading {\tt min(mtxA->n1,mtxB->n1)} rows 824and {\tt min(mtxA->n2,mtxB->n2)} columns are copied. 825\par \noindent {\it Error checking:} 826If {\tt mtxA} or {\tt mtxB} is {\tt NULL}, 827or if the matrices are not of the same type, 828an error message is printed and the program exits. 829%----------------------------------------------------------------------- 830\item 831\begin{verbatim} 832void A2_sub ( A2 *mtxA, A2 *mtxB ) ; 833\end{verbatim} 834\index{A2_sub@{\tt A2\_sub()}} 835This method subtracts entries in matrix {\tt mtxB} 836from entries in matrix {\tt mtxA}. 837Note, {\tt mtxA} and {\tt mtxB} need not be of the same size, 838the leading {\tt min(mtxA->n1,mtxB->n1)} rows 839and {\tt min(mtxA->n2,mtxB->n2)} columns are subtracted. 840\par \noindent {\it Error checking:} 841If {\tt mtxA} or {\tt mtxB} is {\tt NULL}, 842or if the matrices are not of the same type, 843an error message is printed and the program exits. 844%----------------------------------------------------------------------- 845\item 846\begin{verbatim} 847void A2_swapRows ( A2 *mtx, int irow1, int irow2 ) ; 848\end{verbatim} 849\index{A2_swapRows@{\tt A2\_swapRows()}} 850This method swaps rows {\tt irow1} and {\tt irow2} of the matrix. 851\par \noindent {\it Error checking:} 852If {\tt mtxA} or {\tt mtxB} is {\tt NULL}, 853or if {\tt irow1} or {\tt irow2} are out of range, 854an error message is printed and the program exits. 855%----------------------------------------------------------------------- 856\item 857\begin{verbatim} 858void A2_swapColumns ( A2 *mtx, int irow1, int irow2 ) ; 859\end{verbatim} 860\index{A2_swapColumns@{\tt A2\_swapColumns()}} 861This method swaps columns {\tt jcol1} and {\tt jcol2} of the matrix. 862\par \noindent {\it Error checking:} 863If {\tt mtxA} or {\tt mtxB} is {\tt NULL}, 864or if {\tt jcol1} or {\tt jcol1} are out of range, 865an error message is printed and the program exits. 866%----------------------------------------------------------------------- 867\item 868\begin{verbatim} 869int A2_copyEntriesToVector ( A2 *mtx, int length, double dvec[], 870 int copyflag, int storeflag ) ; 871\end{verbatim} 872\index{A2_copyEntriesToVector@{\tt A2\_copyEntriesToVector()}} 873This method copies selected entries from {\tt mtx} into the vector 874{\tt dvec[]} with length {\tt length}. 875The return value is the number of entries copied. 876This method is used during the $QR$ factorization to extract factor 877entries and update matrix entries from a front. 878All entries may be copied, or 879only the diagonal, lower or upper entries, 880and the entries may be copied to {\tt dvec[]} by rows or by 881columns. 882\par \noindent {\it Error checking:} 883If {\tt mtx} or {\tt dvec} is {\tt NULL}, 884or if {\tt length} is not as large as the number of entries to be 885copied, 886or if {\tt copyflag} is not one of {\tt A2\_STRICT\_LOWER}, 887{\tt A2\_LOWER}, {\tt A2\_DIAGONAL}, {\tt A2\_UPPER}, 888{\tt A2\_STRICT\_UPPER} or {\tt A2\_ALL\_ENTRIES}, 889or if {\tt storeflag} is not one of {\tt A2\_BY\_ROWS} 890or {\tt A2\_BY\_COLUMNS}, 891an error message is printed and the program exits. 892%----------------------------------------------------------------------- 893\end{enumerate} 894\par 895\subsection{IO methods} 896\label{subsection:A2:proto:IO} 897\par 898There are the usual eight IO routines plus a method to write the 899object to a Matlab file. 900\par 901%======================================================================= 902\begin{enumerate} 903%----------------------------------------------------------------------- 904\item 905\begin{verbatim} 906int A2_readFromFile ( A2 *mtx, char *fn ) ; 907\end{verbatim} 908\index{A2_readFromFile@{\tt A2\_readFromFile()}} 909\par 910This method reads a {\tt A2} object from a file. 911It tries to open the file and if it is successful, 912it then calls {\tt A2\_readFromFormattedFile()} or 913{\tt A2\_readFromBinaryFile()}, 914closes the file 915and returns the value returned from the called routine. 916\par \noindent {\it Error checking:} 917If {\tt mtx} or {\tt fn} are {\tt NULL}, 918or if {\tt fn} is not of the form 919{\tt *.a2f} (for a formatted file) 920or {\tt *.a2b} (for a binary file), 921an error message is printed and the method returns zero. 922%----------------------------------------------------------------------- 923\item 924\begin{verbatim} 925int A2_readFromFormattedFile ( A2 *mtx, FILE *fp ) ; 926\end{verbatim} 927\index{A2_readFromFormattedFile@{\tt A2\_readFromFormattedFile()}} 928\par 929This method reads a {\tt A2} object from a formatted file 930whose pointer is {\tt fp}. 931If there are no errors in reading the data, 932the value {\tt 1} is returned. 933If an IO error is encountered from {\tt fscanf}, zero is returned. 934\par \noindent {\it Error checking:} 935If {\tt mtx} or {\tt fp} are {\tt NULL}, 936an error message is printed and zero is returned. 937%----------------------------------------------------------------------- 938\item 939\begin{verbatim} 940int A2_readFromBinaryFile ( A2 *mtx, FILE *fp ) ; 941\end{verbatim} 942\index{A2_readFromBinaryFile@{\tt A2\_readFromBinaryFile()}} 943\par 944This method reads a {\tt A2} object from a binary file 945whose pointer is {\tt fp}. 946If there are no errors in reading the data, 947the value {\tt 1} is returned. 948If an IO error is encountered from {\tt fread}, zero is returned. 949\par \noindent {\it Error checking:} 950If {\tt mtx} or {\tt fp} are {\tt NULL}, 951an error message is printed and zero is returned. 952%----------------------------------------------------------------------- 953\item 954\begin{verbatim} 955int A2_writeToFile ( A2 *mtx, char *fn ) ; 956\end{verbatim} 957\index{A2_writeToFile@{\tt A2\_writeToFile()}} 958\par 959This method writes a {\tt A2} object to a file. 960It tries to open the file and if it is successful, 961it then calls {\tt A2\_writeFromFormattedFile()} or 962{\tt A2\_writeFromBinaryFile()}, 963closes the file 964and returns the value returned from the called routine. 965\par \noindent {\it Error checking:} 966If {\tt mtx} or {\tt fn} are {\tt NULL}, 967or if {\tt fn} is not of the form 968{\tt *.a2f} (for a formatted file) 969or {\tt *.a2b} (for a binary file), 970an error message is printed and the method returns zero. 971%----------------------------------------------------------------------- 972\item 973\begin{verbatim} 974int A2_writeToFormattedFile ( A2 *mtx, FILE *fp ) ; 975\end{verbatim} 976\index{A2_writeToFormattedFile@{\tt A2\_writeToFormattedFile()}} 977\par 978This method writes a {\tt A2} object to a formatted file 979whose pointer is {\tt fp}. 980If there are no errors in writing the data, 981the value {\tt 1} is returned. 982If an IO error is encountered from {\tt fprintf}, zero is returned. 983\par \noindent {\it Error checking:} 984If {\tt mtx} or {\tt fp} are {\tt NULL}, 985an error message is printed and zero is returned. 986%----------------------------------------------------------------------- 987\item 988\begin{verbatim} 989int A2_writeToBinaryFile ( A2 *mtx, FILE *fp ) ; 990\end{verbatim} 991\index{A2_writeToBinaryFile@{\tt A2\_writeToBinaryFile()}} 992\par 993This method writes a {\tt A2} object to a binary file 994whose pointer is {\tt fp}. 995If there are no errors in writing the data, 996the value {\tt 1} is returned. 997If an IO error is encountered from {\tt fwrite}, zero is returned. 998\par \noindent {\it Error checking:} 999If {\tt mtx} or {\tt fp} are {\tt NULL}, 1000an error message is printed and zero is returned. 1001%----------------------------------------------------------------------- 1002\item 1003\begin{verbatim} 1004void A2_writeForHumanEye ( A2 *mtx, FILE *fp ) ; 1005\end{verbatim} 1006\index{A2_writeForHumanEye@{\tt A2\_writeForHumanEye()}} 1007\par 1008This method writes a {\tt A2} object to a file in an easily 1009readable format. 1010The method {\tt A2\_writeStats()} is called to write out the 1011header and statistics. 1012\par \noindent {\it Error checking:} 1013If {\tt mtx} or {\tt fp} are {\tt NULL}, 1014an error message is printed and zero is returned. 1015%----------------------------------------------------------------------- 1016\item 1017\begin{verbatim} 1018void A2_writeStats ( A2 *mtx, FILE *fp ) ; 1019\end{verbatim} 1020\index{A2_writeStats@{\tt A2\_writeStats()}} 1021\par 1022This method writes a header and some statistics to a file. 1023\par \noindent {\it Error checking:} 1024If {\tt mtx} or {\tt fp} are {\tt NULL}, 1025an error message is printed and zero is returned. 1026%----------------------------------------------------------------------- 1027\item 1028\begin{verbatim} 1029void A2_writeForMatlab ( A2 *mtx, char *mtxname, FILE *fp ) ; 1030\end{verbatim} 1031\index{A2_writeForMatlab@{\tt A2\_writeForMatlab()}} 1032\par 1033This method writes the entries of the matrix to a file 1034in Matlab format. 1035The name of the matrix is {\tt mtxname}. 1036\par \noindent {\it Error checking:} 1037If {\tt mtx}, {\tt mtxname} or {\tt fp} are {\tt NULL}, 1038an error message is printed and zero is returned. 1039%----------------------------------------------------------------------- 1040\end{enumerate} 1041 1042