| 1 | /* |
| 2 | |
| 3 | Copyright (C) 2008-2019 Michele Martone |
| 4 | |
| 5 | This file is part of librsb. |
| 6 | |
| 7 | librsb is free software; you can redistribute it and/or modify it |
| 8 | under the terms of the GNU Lesser General Public License as published |
| 9 | by the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | librsb is distributed in the hope that it will be useful, but WITHOUT |
| 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 15 | License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with librsb; see the file COPYING. |
| 19 | If not, see <https://www.gnu.org/licenses/>. |
| 20 | |
| 21 | */ |
| 22 | /* @cond INNERDOC */ |
| 23 | /*! |
| 24 | * @file |
| 25 | * @author Michele Martone |
| 26 | * @brief |
| 27 | * This source file contains functions for COO symmetry handling. |
| 28 | * */ |
| 29 | |
| 30 | #include "rsb_internals.h"cxx . . $ `<file>/rsb_internals.h`/ |
| 31 | |
| 32 | rsb_err_tcxx . . $ rsb_err_t# rsb__reallocate_with_symmetrycxx . . $ rsb__reallocate_with_symmetry(2d15b7db8a0fb85f).( rsb_coo_idx_tcxx . . $ rsb_coo_idx_t# ** IA, rsb_coo_idx_tcxx . . $ rsb_coo_idx_t# ** JA, void **coo, rsb_nnz_idx_tcxx . . $ rsb_nnz_idx_t# * nnz, rsb_type_tcxx . . $ rsb_type_t# typecode ) |
| 33 | { |
| 34 | /*! |
| 35 | * \ingroup gr_internals |
| 36 | * Assuming that for a symmetric matrix we are given |
| 37 | * these arrays containing (i,j) pairs, with no (j,i) pairs at all (except j=i), |
| 38 | * we reallocate arrays (if possible) and fill them with the symmetric elements |
| 39 | * with no duplicate. |
| 40 | * |
| 41 | * note : this is a slow service/debug function, not a high performance one. |
| 42 | * */ |
| 43 | rsb_coo_idx_tcxx . . $ rsb_coo_idx_t# * new_IA, *new_JA; |
| 44 | void * ncoo; |
| 45 | rsb_nnz_idx_tcxx . . $ rsb_nnz_idx_t# nnnz; |
| 46 | size_t i,odel = 0, el_size = RSB_NUMERICAL_TYPE_SIZEcxx . . $ `rsb_types.h:276:9`!(typecode);/* off diagonal elements */ |
| 47 | rsb_err_tcxx . . $ rsb_err_t# errval = RSB_ERR_NO_ERRORcxx . . $ `rsb.h:616:9`!; |
| 48 | |
| 49 | if(!IA || !JA || !*IA || !*JA || !nnz || !*nnz || !el_size) |
| 50 | return RSB_ERR_BADARGScxx . . $ `rsb.h:634:9`!; |
| 51 | |
| 52 | nnnz = *nnz; |
| 53 | for(i=0;i<nnnz;++i) |
| 54 | { |
| 55 | if((*IA)[i]!=(*JA)[i])++odel; |
| 56 | } |
| 57 | nnnz += odel; |
| 58 | |
| 59 | if(!odel) |
| 60 | { |
| 61 | return RSB_ERR_NO_ERRORcxx . . $ `rsb.h:616:9`!;/* a diagonal matrix */ |
| 62 | } |
| 63 | |
| 64 | errval = rsb__util_coo_alloccxx . . $ rsb__util_coo_alloc(cf3c87fd66181ef0).(&ncoo,&new_IA,&new_JA,nnnz,typecode,RSB_BOOL_TRUEcxx . . $ `rsb.h:418:9`!); |
| 65 | if(RSB_SOME_ERRORcxx . . $ `rsb_common.h:1321:9`!(errval)) |
| 66 | return RSB_ERR_ENOMEMcxx . . $ `rsb.h:637:9`!; |
| 67 | |
| 68 | RSB_COO_MEMCPYcxx . . $ `rsb_common.h:815:9`!(ncoo,new_IA,new_JA,*coo,*IA,*JA,0,0,*nnz,el_size); |
| 69 | |
| 70 | odel = 0; |
| 71 | for(i=0;i<*nnz;++i) |
| 72 | { |
| 73 | if((*IA)[i]!=(*JA)[i]) |
| 74 | { |
| 75 | new_IA[*nnz+odel] = new_JA[i]; |
| 76 | new_JA[*nnz+odel] = new_IA[i]; |
| 77 | /* new_IA[*nnz+odel] = 1; |
| 78 | new_JA[*nnz+odel] = 1;*/ |
| 79 | rsb__memcpycxx . . $ rsb__memcpy(cc817cb175f282d).(((char*)ncoo) + (*nnz+odel) * el_size, ((const char*)ncoo) + i * el_size ,el_size); |
| 80 | ++odel; |
| 81 | //RSB_ERROR("%d %d ..\n",new_IA[i],new_JA[i]); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | rsb__freecxx . . $ rsb__free(9f162e79bfc6c74).(*IA); |
| 86 | rsb__freecxx . . $ rsb__free(9f162e79bfc6c74).(*JA); |
| 87 | rsb__freecxx . . $ rsb__free(9f162e79bfc6c74).(*coo); |
| 88 | |
| 89 | *IA = new_IA; |
| 90 | *JA = new_JA; |
| 91 | *coo = ncoo; |
| 92 | *nnz += odel; |
| 93 | |
| 94 | return errval; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /* @endcond */ |