/** * Computes number of given @a vector by finding it in @a vectors. * Searches for @a vector in @a vectors. @a vectors should consist of * a bunch of vectors one after another in memory, in lexicographic * order. Returned is the entry number to which @a vector corresponds. * * @param vector vector to compute number of * @param vectors vectors to search @a vector in * @param vec_length length of vectors * @return number of vector */ static unsigned vector_to_number (unsigned *vector, unsigned *vectors, unsigned vec_length, unsigned left, unsigned right) { unsigned mid = left; int comp_res; unsigned *comp_vec; BOOL found; found = FALSE; while (!found && (left <= right)) { mid = left + ((right - left) / 2); comp_vec = vectors + mid * vec_length; comp_res = compare_vectors(vector, comp_vec, vec_length); if (0 == comp_res) { found = TRUE; } else if (-1 == comp_res) { right = mid - 1; } else { left = mid + 1; } } return mid; }
void test(int r,int m) { int n = 1 << m; int i, k = 1, d,s, max; vector *message, *decoded, *encoded; char filename[100]; FILE *outputstream; sprintf(filename, "test2_out_%d_%d.txt", m, r); outputstream = fopen(filename,"w"); for (i = 0, s = 1; i < r; i++) { s = s * (m - i)/(i + 1); k += s; } max = 1 << n; d = n >> r; fprintf(outputstream, "r = %d, m = %d\n", r,m); fprintf(outputstream, "[%d, %d, %d]\n\n", n, k, d); message = create_vector(n); for (i = 0; i < max; i++) { fprintf(outputstream, "received: "); print_vector(message, outputstream); decoded = decode(message, r, m); fprintf(outputstream, "decoded: "); if (decoded == NULL) { fprintf(outputstream, "Error - 0s and 1s tied in majority logic. Indeterminate message.\n\n"); } else { print_vector(decoded, outputstream); encoded = encode(decoded,r, m); fprintf(outputstream, "encoded: "); print_vector(encoded, outputstream); if (compare_vectors(encoded,message) == 0) { fprintf(outputstream, "NO ERRORS\n\n"); } else { fprintf(outputstream, "%d ERROR(S)\n\n", distance(encoded, message)); } destroy_vector(encoded); destroy_vector(decoded); } increment(message); } fclose(outputstream); destroy_vector(message); }
void handle_values_tests_distributed_access(hpx::vector<T>& v) { fill_vector (v, T(42)); std::vector<std::size_t> positions(5); fill_vector(positions, 0, 2); std::vector<std::size_t> positions2(5); fill_vector(positions2, 1, 2); std::vector<T> values(positions.size()); fill_vector(values, T(48), T(3)); std::vector<T> values2(positions2.size()); fill_vector(values2, T(42), T(0)); v.set_values(positions, values); std::vector<T> result = v.get_values_sync(positions ); std::vector<T> result2 = v.get_values_sync(positions2); compare_vectors(values , result); compare_vectors(values2, result2); }
void handle_values_tests(hpx::vector<T>& v) { fill_vector(v, T(42)); std::vector<std::size_t> positions(2); fill_vector(positions, 0, 2); std::vector<T> values(positions.size()); fill_vector(values, T(48), T(3)); v.set_values(0, positions, values); std::vector<T> result = v.get_values_sync(0, positions); compare_vectors(values, result); }
igraph_bool_t handler(igraph_vector_t *clique, void *arg) { struct userdata *ud; igraph_bool_t cont; ud = (struct userdata *) arg; cont = 1; /* true */ if (compare_vectors(&clique, &(VECTOR(*(ud->list))[ud->i])) != 0) { printf("igraph_cliques() and igraph_cliques_callback() give different results.\n"); cont = 0; /* false */ } igraph_vector_destroy(clique); igraph_free(clique); ud->i += 1; return cont; }
void loop(char *s,int r,int m) { vector *v = to_int_vector(s,strlen(s)); vector *e = encode(v,r,m); vector *d = decode(e,r,m); printf("original:\n"); print_vector(v, stdout); printf("encoded:\n"); print_vector(e, stdout); printf("decoded:\n"); if (d == NULL) { printf("Error: 0s and 1s tied in majority logic.\n"); } else { print_vector(d, stdout); if (compare_vectors(v,d) == 0) { printf("SAME\n"); } else { printf("DIFFERENT\n"); } destroy_vector(d); } destroy_vector(e); destroy_vector(v); printf("\n\n"); }
/* * Counts occurrences of three-node structural motifs in a binary graph. */ VECTOR_T* BCT_NAMESPACE::motif3struct_bin(const MATRIX_T* A, MATRIX_T** F) { if (safe_mode) check_status(A, SQUARE | BINARY, "motif3struct_bin"); // load motif34lib M3n ID3 VECTOR_T* ID3; MATRIX_T* M3 = motif3generate(&ID3); // n=length(A); int n = length(A); // F=zeros(13,n); if (F != NULL) { *F = zeros(13, n); } // f=zeros(13,1); VECTOR_T* f = zeros_vector(13); // As=A|A.'; MATRIX_T* A_transpose = MATRIX_ID(alloc)(A->size2, A->size1); MATRIX_ID(transpose_memcpy)(A_transpose, A); MATRIX_T* As = logical_or(A, A_transpose); MATRIX_ID(free)(A_transpose); // for u=1:n-2 for (int u = 0; u < n - 2; u++) { // V1=[false(1,u) As(u,u+1:n)]; VECTOR_T* V1 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V1, As, u); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V1, i, 0.0); } // for v1=find(V1) VECTOR_T* find_V1 = find(V1); if (find_V1 != NULL) { for (int i_find_V1 = 0; i_find_V1 < (int)find_V1->size; i_find_V1++) { int v1 = (int)VECTOR_ID(get)(find_V1, i_find_V1); // V2=[false(1,u) As(v1,u+1:n)]; VECTOR_T* V2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V2, As, v1); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V2, i, 0.0); } // V2(V1)=0; logical_index_assign(V2, V1, 0.0); // V2=([false(1,v1) As(u,v1+1:n)])|V2; VECTOR_T* V2_1 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V2_1, As, u); for (int i = 0; i <= v1; i++) { VECTOR_ID(set)(V2_1, i, 0.0); } VECTOR_T* V2_2 = V2; V2 = logical_or(V2_1, V2_2); VECTOR_ID(free)(V2_1); VECTOR_ID(free)(V2_2); // for v2=find(V2) VECTOR_T* find_V2 = find(V2); if (find_V2 != NULL) { for (int i_find_V2 = 0; i_find_V2 < (int)find_V2->size; i_find_V2++) { int v2 = (int)VECTOR_ID(get)(find_V2, i_find_V2); // s=uint32(sum(10.^(5:-1:0).*[A(v1,u) A(v2,u) A(u,v1) A(v2,v1) A(u,v2) A(v1,v2)])); int A_rows[] = { v1, v2, u, v2, u, v1 }; int A_cols[] = { u, u, v1, v1, v2, v2 }; VECTOR_T* s = VECTOR_ID(alloc)(6); for (int i = 0; i < 6; i++) { VECTOR_ID(set)(s, i, MATRIX_ID(get)(A, A_rows[i], A_cols[i])); } // ind=ID3(s==M3n); int i_M3 = 0; for ( ; i_M3 < (int)M3->size1; i_M3++) { VECTOR_ID(view) M3_row_i_M3 = MATRIX_ID(row)(M3, i_M3); if (compare_vectors(s, &M3_row_i_M3.vector) == 0) { break; } } VECTOR_ID(free)(s); if (i_M3 < (int)M3->size1) { int ind = (int)VECTOR_ID(get)(ID3, i_M3) - 1; // if nargout==2; F(ind,[u v1 v2])=F(ind,[u v1 v2])+1; end if (F != NULL) { int F_cols[] = { u, v1, v2 }; for (int i = 0; i < 3; i++) { MATRIX_ID(set)(*F, ind, F_cols[i], MATRIX_ID(get)(*F, ind, F_cols[i]) + 1.0); } } // f(ind)=f(ind)+1; VECTOR_ID(set)(f, ind, VECTOR_ID(get)(f, ind) + 1.0); } } VECTOR_ID(free)(find_V2); } VECTOR_ID(free)(V2); } VECTOR_ID(free)(find_V1); } VECTOR_ID(free)(V1); } VECTOR_ID(free)(ID3); MATRIX_ID(free)(M3); MATRIX_ID(free)(As); return f; }
/* * Counts occurrences of four-node structural motifs in a binary graph. */ VECTOR_T* BCT_NAMESPACE::motif4struct_bin(const MATRIX_T* A, MATRIX_T** F) { if (safe_mode) check_status(A, SQUARE | BINARY, "motif4struct_bin"); // load motif34lib M4n ID4 VECTOR_T* ID4; MATRIX_T* M4 = motif4generate(&ID4); // n=length(A); int n = length(A); // F=zeros(199,n); if (F != NULL) { *F = zeros(199, n); } // f=zeros(199,1); VECTOR_T* f = zeros_vector(199); // As=A|A.'; MATRIX_T* A_transpose = MATRIX_ID(alloc)(A->size2, A->size1); MATRIX_ID(transpose_memcpy)(A_transpose, A); MATRIX_T* As = logical_or(A, A_transpose); MATRIX_ID(free)(A_transpose); // for u=1:n-3 for (int u = 0; u < n - 3; u++) { // V1=[false(1,u) As(u,u+1:n)]; VECTOR_T* V1 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V1, As, u); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V1, i, 0.0); } // for v1=find(V1) VECTOR_T* find_V1 = find(V1); if (find_V1 != NULL) { for (int i_find_V1 = 0; i_find_V1 < (int)find_V1->size; i_find_V1++) { int v1 = (int)VECTOR_ID(get)(find_V1, i_find_V1); // V2=[false(1,u) As(v1,u+1:n)]; VECTOR_T* V2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V2, As, v1); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V2, i, 0.0); } // V2(V1)=0; logical_index_assign(V2, V1, 0.0); // V2=V2|([false(1,v1) As(u,v1+1:n)]); VECTOR_T* V2_1 = V2; VECTOR_T* V2_2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V2_2, As, u); for (int i = 0; i <= v1; i++) { VECTOR_ID(set)(V2_2, i, 0.0); } V2 = logical_or(V2_1, V2_2); VECTOR_ID(free)(V2_1); VECTOR_ID(free)(V2_2); // for v2=find(V2) VECTOR_T* find_V2 = find(V2); if (find_V2 != NULL) { for (int i_find_V2 = 0; i_find_V2 < (int)find_V2->size; i_find_V2++) { int v2 = (int)VECTOR_ID(get)(find_V2, i_find_V2); // vz=max(v1,v2); int vz = (v1 > v2) ? v1 : v2; // V3=([false(1,u) As(v2,u+1:n)]); VECTOR_T* V3 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V3, As, v2); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V3, i, 0.0); } // V3(V2)=0; logical_index_assign(V3, V2, 0.0); // V3=V3|([false(1,v2) As(v1,v2+1:n)]); VECTOR_T* V3_1 = V3; VECTOR_T* V3_2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V3_2, As, v1); for (int i = 0; i <= v2; i++) { VECTOR_ID(set)(V3_2, i, 0.0); } V3 = logical_or(V3_1, V3_2); VECTOR_ID(free)(V3_1); VECTOR_ID(free)(V3_2); // V3(V1)=0; logical_index_assign(V3, V1, 0.0); // V3=V3|([false(1,vz) As(u,vz+1:n)]); V3_1 = V3; V3_2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V3_2, As, u); for (int i = 0; i <= vz; i++) { VECTOR_ID(set)(V3_2, i, 0.0); } V3 = logical_or(V3_1, V3_2); VECTOR_ID(free)(V3_1); VECTOR_ID(free)(V3_2); // for v3=find(V3) VECTOR_T* find_V3 = find(V3); if (find_V3 != NULL ) { for (int i_find_V3 = 0; i_find_V3 < (int)find_V3->size; i_find_V3++) { int v3 = (int)VECTOR_ID(get)(find_V3, i_find_V3); // s=uint32(sum(10.^(11:-1:0).*[A(v1,u) A(v2,u) A(v3,u) A(u,v1) A(v2,v1) A(v3,v1) A(u,v2) A(v1,v2) A(v3,v2) A(u,v3) A(v1,v3) A(v2,v3)])); int A_rows[] = { v1, v2, v3, u, v2, v3, u, v1, v3, u, v1, v2 }; int A_cols[] = { u, u, u, v1, v1, v1, v2, v2, v2, v3, v3, v3 }; VECTOR_T* s = VECTOR_ID(alloc)(12); for (int i = 0; i < 12; i++) { VECTOR_ID(set)(s, i, MATRIX_ID(get)(A, A_rows[i], A_cols[i])); } // ind=ID4(s==M4n); int i_M4 = 0; for ( ; i_M4 < (int)M4->size1; i_M4++) { VECTOR_ID(view) M4_row_i_M4 = MATRIX_ID(row)(M4, i_M4); if (compare_vectors(s, &M4_row_i_M4.vector) == 0) { break; } } VECTOR_ID(free)(s); if (i_M4 < (int)M4->size1) { int ind = (int)VECTOR_ID(get)(ID4, i_M4) - 1; // if nargout==2; F(ind,[u v1 v2 v3])=F(ind,[u v1 v2 v3])+1; end if (F != NULL) { int F_cols[] = { u, v1, v2, v3 }; for (int i = 0; i < 4; i++) { MATRIX_ID(set)(*F, ind, F_cols[i], MATRIX_ID(get)(*F, ind, F_cols[i]) + 1.0); } } // f(ind)=f(ind)+1; VECTOR_ID(set)(f, ind, VECTOR_ID(get)(f, ind) + 1.0); } } VECTOR_ID(free)(find_V3); } VECTOR_ID(free)(V3); } VECTOR_ID(free)(find_V2); } VECTOR_ID(free)(V2); } VECTOR_ID(free)(find_V1); } VECTOR_ID(free)(V1); } VECTOR_ID(free)(ID4); MATRIX_ID(free)(M4); MATRIX_ID(free)(As); return f; }