All pastes #68561 Raw Edit

Unnamed

public c v1 · immutable
#68561 ·published 2006-06-21 20:06 UTC
rendered paste body
#include "Laplacian.h"sparse_matrix_arr* Elad_Laplacian( int *fa , int nf , int nv ){	int i , j , t1 , t2 , nnz;	sparse_matrix_arr *lplcn;	sparse_matrix_lst *temp = allocate_sparse_matrix_lst(nv);	cell_t *cell;	nnz = nv;		// Initialize the temp sml.	for ( i = 0 ; i < nv ; i++ )	{		cell = create_cell_t( i , i , 0.0 );		insert_NEW_cell_into_matrix( cell, temp );	}	// Shape the temp sml into the desired Laplacian matrix thingie thing.	for ( i = 0 ; i < nv ; i++ )		for ( j = 0 ; j < (nf*3) ; j += 3 )			if ( fa[j+0] == i || fa[j+1] == i || fa[j+2] == i )			{						t1 = ( fa[j+0] != i ) ? j+0 : j+1;				t2 = ( fa[j+2] != i ) ? j+2 : j+1;				//				printf("\ndookie\n");								if ( is_zero( i , fa[t1] , temp ) )				{					cell = create_cell_t(i,fa[t1],-1.0);					insert_NEW_cell_into_matrix( cell, temp );					increment_non_zero_element(i,i,temp);					nnz++;				}								if ( is_zero( i , fa[t2] , temp ) )				{					cell = create_cell_t(i,fa[t2],-1.0);					insert_NEW_cell_into_matrix( cell, temp );					increment_non_zero_element(i,i,temp);					nnz++;				}							}		//printf("\ndookie\n");						// Convert the sml to an sma, and return it.	lplcn = allocate_sparse_matrix_arr(nv,nnz);	//printf("\n%d\n",nnz);//	print_sparse_matrix_lst(temp);	printf("\n");	sml_to_sma(temp,lplcn);//	free_sparse_matrix_lst(temp);	print_sparse_matrix_arr(lplcn);	return lplcn;}void sml_to_sma( sparse_matrix_lst *source , sparse_matrix_arr *target ){	int inserted = 0 , j = 0 , previously;	cell_t *cell;		target->colptr[0] = 0;		while ( j < source->n )	{		cell = source->cols[j++];				previously = inserted;				while ( cell != NULL )		{			target->values[inserted] = cell->value;			target->rowind[inserted] = cell->rowind;			cell = cell->col_next;			inserted++;		}				target->colptr[j] = target->colptr[j-1] + inserted - previously;		}}