#include "BSprivate.h"

/*@ BScopy_nz - Copy the nonzero values from one matrix to another

    Input Parameters:
.   A - The source matrix

    Output Parameters:
.   newA - The destination matrix

    Returns:
    void

    Notes: Recall that (in the incomplete Cholesky case)
           A and another matrix are symmetric and generally
           share the square dense matrices (with the assumption that
           the diagonal of one matrix is either known or stored elsewhere)
           associated with the cliques.

 @*/
void BScopy_nz(BSpar_mat *A, BSpar_mat *newA)
{
	int	i, j, k;
	int	size, len;
	BSinode *inodes, *new_inodes;

	/* first copy the clique blocks */
	/* we now that both matrices point to the same blocks and */
	/* that A is stored in the lower triangle and newA in the upper */
	BScopy_cliques(A,newA); CHKERR(0);

	/* now copy the inodes */
	inodes = A->inodes->list;
	len = A->inodes->length;
	new_inodes = newA->inodes->list;
	for (i=0;i<len;i++) {
		size = inodes[i].length;
		for (j=0;j<inodes[i].num_cols;j++) {
			for (k=0;k<size;k++) {
				new_inodes[i].nz[(j*size)+k] = inodes[i].nz[(j*size)+k];
			}
		}
	}
}

/*+ BScopy_cliques - Copy the nonzero values from the cliques of
                     one matrix to another

    Input Parameters:
.   A - The source matrix

    Output Parameters:
.   newA - The destination matrix

    Returns:
    void

    Notes: Recall that A and another matrix are symmetric and generally
           share the square dense matrices (with the assumption that
           the diagonal of one matrix is either known or stored elsewhere)
           associated with the cliques.  In the nonsymmetric case the dense
           matrices are unique (storage not shared with another matrix).

+*/
void BScopy_cliques(BSpar_mat *A, BSpar_mat *newA)
{
	int	i, j, k;
	int	size;
	BScl_2_inode *cl2i, *new_cl2i;
	FLOAT *matrix, *new_matrix;


	/* copy from the upper triangle to the lower triangle of the cliques */
	/* that A is stored in the lower triangle and newA in the upper */
	/* for the symmetric case.  For the nonsymmetric case we have to */
	/* copy everything. */
	cl2i = A->clique2inode;
	new_cl2i = newA->clique2inode;
	for (i=0;i<cl2i->num_cols;i++) {
		matrix = cl2i->d_mats[i].matrix;
    	new_matrix = new_cl2i->d_mats[i].matrix;
		size = cl2i->d_mats[i].size;
		for (j=0;j<size;j++) {
			if(A->icc_storage) {
				for (k=0;k<j;k++) {
					matrix[(j*size)+k] = matrix[(k*size)+j];
				}
			} else {
				for (k=0;k<size;k++) {
					new_matrix[(j*size)+k] = matrix[(j*size)+k];
				}
			}
		}
	}
}


syntax highlighted by Code2HTML, v. 0.9.1