本文整理汇总了C++中VECTOR函数的典型用法代码示例。如果您正苦于以下问题:C++ VECTOR函数的具体用法?C++ VECTOR怎么用?C++ VECTOR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VECTOR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
igraph_t graph;
igraph_vector_t walk, weights;
igraph_integer_t ec, i;
igraph_rng_seed(igraph_rng_default(), 137);
igraph_vector_init(&walk, 0);
igraph_vector_init(&weights, 0);
/* This directed graph has loop edges.
It also has multi-edges when considered as undirected. */
igraph_de_bruijn(&graph, 3, 2);
ec = igraph_ecount(&graph);
/* unweighted, directed */
igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
assert(igraph_vector_size(&walk) == 1000);
/* unweighted, undirected */
igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
assert(igraph_vector_size(&walk) == 1000);
igraph_vector_resize(&weights, ec);
for (i=0; i < ec; ++i)
VECTOR(weights)[i] = igraph_rng_get_unif01(igraph_rng_default());
/* weighted, directed */
igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
assert(igraph_vector_size(&walk) == 1000);
/* weighted, undirecetd */
igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
assert(igraph_vector_size(&walk) == 1000);
igraph_destroy(&graph);
/* 1-vertex graph, should get stuck */
igraph_empty(&graph, 1, /* directed = */ 0);
igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
assert(igraph_vector_size(&walk) == 0);
igraph_destroy(&graph);
igraph_vector_destroy(&weights);
igraph_vector_destroy(&walk);
return 0;
}
示例2: multi_yw
void multi_yw(double *acf, int *pn, int *pomax, int *pnser, double *coef,
double *pacf, double *var, double *aic, int *porder, int *useaic)
{
int i, m;
int omax = *pomax, n = *pn, nser=*pnser, order=*porder;
double aicmin;
Array acf_array, p_forward, p_back, v_forward, v_back;
Array *A, *B;
int dim[3];
dim[0] = omax+1; dim[1] = dim[2] = nser;
acf_array = make_array(acf, dim, 3);
p_forward = make_array(pacf, dim, 3);
v_forward = make_array(var, dim, 3);
/* Backward equations (discarded) */
p_back= make_zero_array(dim, 3);
v_back= make_zero_array(dim, 3);
A = (Array *) R_alloc(omax+2, sizeof(Array));
B = (Array *) R_alloc(omax+2, sizeof(Array));
for (i = 0; i <= omax; i++) {
A[i] = make_zero_array(dim, 3);
B[i] = make_zero_array(dim, 3);
}
whittle(acf_array, omax, A, B, p_forward, v_forward, p_back, v_back);
/* Model order selection */
for (m = 0; m <= omax; m++) {
aic[m] = n * ldet(subarray(v_forward,m)) + 2 * m * nser * nser;
}
if (*useaic) {
order = 0;
aicmin = aic[0];
for (m = 0; m <= omax; m++) {
if (aic[m] < aicmin) {
aicmin = aic[m];
order = m;
}
}
}
else order = omax;
*porder = order;
for(i = 0; i < vector_length(A[order]); i++)
coef[i] = VECTOR(A[order])[i];
}
示例3: igraph_is_connected_weak
int igraph_is_connected_weak(const igraph_t *graph, igraph_bool_t *res) {
long int no_of_nodes=igraph_vcount(graph);
char *already_added;
igraph_vector_t neis=IGRAPH_VECTOR_NULL;
igraph_dqueue_t q=IGRAPH_DQUEUE_NULL;
long int i, j;
already_added=igraph_Calloc(no_of_nodes, char);
if (already_added==0) {
IGRAPH_ERROR("is connected (weak) failed", IGRAPH_ENOMEM);
}
IGRAPH_FINALLY(free, already_added); /* TODO: hack */
IGRAPH_DQUEUE_INIT_FINALLY(&q, 10);
IGRAPH_VECTOR_INIT_FINALLY(&neis, 0);
/* Try to find at least two clusters */
already_added[0]=1;
IGRAPH_CHECK(igraph_dqueue_push(&q, 0));
j=1;
while ( !igraph_dqueue_empty(&q)) {
long int actnode=igraph_dqueue_pop(&q);
IGRAPH_ALLOW_INTERRUPTION();
IGRAPH_CHECK(igraph_neighbors(graph, &neis, actnode, IGRAPH_ALL));
for (i=0; i <igraph_vector_size(&neis); i++) {
long int neighbor=VECTOR(neis)[i];
if (already_added[neighbor] != 0) {
continue;
}
IGRAPH_CHECK(igraph_dqueue_push(&q, neighbor));
j++;
already_added[neighbor]++;
}
}
/* Connected? */
*res = (j == no_of_nodes);
igraph_Free(already_added);
igraph_dqueue_destroy(&q);
igraph_vector_destroy(&neis);
IGRAPH_FINALLY_CLEAN(3);
return 0;
}
示例4: igraph_i_2dgrid_addvertices
int igraph_i_2dgrid_addvertices(igraph_2dgrid_t *grid, igraph_vector_t *eids,
igraph_integer_t vid, igraph_real_t r,
long int x, long int y) {
long int act;
igraph_real_t *v=VECTOR(grid->next);
r=r*r;
act=(long int) MATRIX(grid->startidx, x, y);
while (act != 0) {
if (igraph_2dgrid_dist2(grid, vid, act-1) < r) {
IGRAPH_CHECK(igraph_vector_push_back(eids, act-1));
}
act=(long int) v[act-1];
}
return 0;
}
示例5: splicing_dgesdd
int splicing_dgesdd(const splicing_matrix_t *matrix,
splicing_vector_t *values) {
splicing_matrix_t tmp;
int m=splicing_matrix_nrow(matrix);
int n=splicing_matrix_ncol(matrix);
int lda=m, minmn= m < n ? m : n, maxmn = m < n ? n : m;
int lwork=-1;
int info=0;
splicing_vector_t work;
splicing_vector_int_t iwork;
char jobz='N';
int dummy=1;
double dummy2;
SPLICING_CHECK(splicing_matrix_copy(&tmp, matrix));
SPLICING_FINALLY(splicing_matrix_destroy, &tmp);
SPLICING_CHECK(splicing_vector_init(&work, 1));
SPLICING_FINALLY(splicing_vector_destroy, &work);
SPLICING_CHECK(splicing_vector_int_init(&iwork, 8*minmn));
SPLICING_FINALLY(splicing_vector_int_destroy, &iwork);
SPLICING_CHECK(splicing_vector_resize(values, minmn));
/* Get the optiomal lwork first*/
splicingdgesdd_(&jobz, &m, &n, &MATRIX(tmp,0,0), &lda, VECTOR(*values),
/*U=*/ &dummy2, /*LDU=*/ &dummy,
/*VT=*/ &dummy2, /*LDVT=*/ &dummy,
VECTOR(work), &lwork, VECTOR(iwork), &info);
lwork = VECTOR(work)[0];
SPLICING_CHECK(splicing_vector_resize(&work, lwork));
/* Now do the SVD */
splicingdgesdd_(&jobz, &m, &n, &MATRIX(tmp,0,0), &lda, VECTOR(*values),
/*U=*/ &dummy2, /*LDU=*/ &dummy,
/*VT=*/ &dummy2, /*LDVT=*/ &dummy,
VECTOR(work), &lwork, VECTOR(iwork), &info);
if (info != 0) {
SPLICING_ERROR("Cannot calculate SVD", SPLICING_ELAPACK);
}
splicing_vector_destroy(&work);
splicing_vector_int_destroy(&iwork);
splicing_matrix_destroy(&tmp);
SPLICING_FINALLY_CLEAN(3);
return 0;
}
示例6: camera
/*-<==>-----------------------------------------------------------------
/ Save the new camera position and target point.
/ Define the axis of the camera (front, up, left) in world coordinates
/ based on the current values of the vectors target & loc
/---------------------------------------------------------------------*/
void CCamera::lookAt(const VECTOR &src_point, const VECTOR &dst_point) {
loc = src_point;//position
target = dst_point;//target
// Pendiente de implementar correctamente
// ...
front = target-loc;
front.normalize();
VECTOR aux_up = VECTOR(0,1,0);
left=aux_up.cross(front);
left.normalize();
aux_up.normalize();
up = front.cross(left);
up.normalize();
// REVISADA
}
示例7: cIGraph_community_spinglass_single
VALUE cIGraph_community_spinglass_single(VALUE self, VALUE weights, VALUE vertex, VALUE spins, VALUE update_rule, VALUE gamma){
igraph_t *graph;
igraph_vector_t weights_vec;
igraph_vector_t community;
igraph_real_t cohesion;
igraph_real_t adhesion;
VALUE group;
VALUE res;
int i;
Data_Get_Struct(self, igraph_t, graph);
igraph_vector_init(&community,0);
igraph_vector_init(&weights_vec,RARRAY_LEN(weights));
for(i=0;i<RARRAY_LEN(weights);i++){
VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]);
}
igraph_community_spinglass_single(graph,
igraph_vector_size(&weights_vec) > 0 ? &weights_vec : NULL,
cIGraph_get_vertex_id(self, vertex),
&community, &cohesion, &adhesion,
NULL, NULL,
NUM2INT(spins),NUM2INT(update_rule),
NUM2DBL(gamma));
group = rb_ary_new();
for(i=0;i<igraph_vector_size(&community);i++){
rb_ary_push(group,cIGraph_get_vertex_object(self, i));
}
res = rb_ary_new3(3,group,
rb_float_new(cohesion),
rb_float_new(adhesion));
igraph_vector_destroy(&community);
igraph_vector_destroy(&weights_vec);
return res;
}
示例8: main
int main() {
igraph_t g;
igraph_vector_ptr_t vecs, evecs;
long int i;
igraph_vs_t vs;
igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 1);
igraph_vector_ptr_init(&vecs, 5);
igraph_vector_ptr_init(&evecs, 5);
for (i=0; i<igraph_vector_ptr_size(&vecs); i++) {
VECTOR(vecs)[i] = calloc(1, sizeof(igraph_vector_t));
igraph_vector_init(VECTOR(vecs)[i], 0);
VECTOR(evecs)[i] = calloc(1, sizeof(igraph_vector_t));
igraph_vector_init(VECTOR(evecs)[i], 0);
}
igraph_vs_vector_small(&vs, 1, 3, 5, 2, 1, -1);
igraph_get_shortest_paths(&g, &vecs, &evecs, 0, vs, IGRAPH_OUT);
check_evecs(&g, &vecs, &evecs, 10);
for (i=0; i<igraph_vector_ptr_size(&vecs); i++) {
print_vector(VECTOR(vecs)[i]);
igraph_vector_destroy(VECTOR(vecs)[i]);
free(VECTOR(vecs)[i]);
igraph_vector_destroy(VECTOR(evecs)[i]);
free(VECTOR(evecs)[i]);
}
igraph_vector_ptr_destroy(&vecs);
igraph_vector_ptr_destroy(&evecs);
igraph_vs_destroy(&vs);
igraph_destroy(&g);
if (!IGRAPH_FINALLY_STACK_EMPTY) return 1;
return 0;
}
示例9: igraph_i_maximal_cliques_select_pivot
int igraph_i_maximal_cliques_select_pivot(const igraph_vector_int_t *PX,
int PS, int PE, int XS, int XE,
const igraph_vector_int_t *pos,
const igraph_adjlist_t *adjlist,
int *pivot,
igraph_vector_int_t *nextv,
int oldPS, int oldXE) {
igraph_vector_int_t *pivotvectneis;
int i, pivotvectlen, j, usize=-1;
int soldPS=oldPS+1, soldXE=oldXE+1, sPS=PS+1, sPE=PE+1;
/* Choose a pivotvect, and bring up P vertices at the same time */
for (i=PS; i<=XE; i++) {
int av=VECTOR(*PX)[i];
igraph_vector_int_t *avneis=igraph_adjlist_get(adjlist, av);
int *avp=VECTOR(*avneis);
int avlen=igraph_vector_int_size(avneis);
int *ave=avp+avlen;
int *avnei=avp, *pp=avp;
for (; avnei < ave; avnei++) {
int avneipos=VECTOR(*pos)[(int)(*avnei)];
if (avneipos < soldPS || avneipos > soldXE) { break; }
if (avneipos >= sPS && avneipos <= sPE) {
if (pp != avnei) {
int tmp=*avnei;
*avnei = *pp;
*pp = tmp;
}
pp++;
}
}
if ((j=pp-avp) > usize) { *pivot = av; usize=j; }
}
igraph_vector_int_push_back(nextv, -1);
pivotvectneis=igraph_adjlist_get(adjlist, *pivot);
pivotvectlen=igraph_vector_int_size(pivotvectneis);
for (j=PS; j <= PE; j++) {
int vcand=VECTOR(*PX)[j];
igraph_bool_t nei=0;
int k=0;
for (k=0; k < pivotvectlen; k++) {
int unv=VECTOR(*pivotvectneis)[k];
int unvpos=VECTOR(*pos)[unv];
if (unvpos < sPS || unvpos > sPE) { break; }
if (unv == vcand) { nei=1; break; }
}
if (!nei) { igraph_vector_int_push_back(nextv, vcand); }
}
return 0;
}
示例10: splicing_iso_to_genomic
int splicing_iso_to_genomic(const splicing_gff_t *gff, size_t gene,
const splicing_vector_int_t *isoform,
const splicing_gff_converter_t *converter,
splicing_vector_int_t *position) {
size_t i, n=splicing_vector_int_size(position);
splicing_gff_converter_t vconverter,
*myconverter = (splicing_gff_converter_t*) converter;
if (!converter) {
myconverter=&vconverter;
SPLICING_CHECK(splicing_gff_converter_init(gff, gene, myconverter));
SPLICING_FINALLY(splicing_gff_converter_destroy, myconverter);
}
/* Do the shifting */
for (i=0; i<n; i++) {
int iso=VECTOR(*isoform)[i];
size_t pos=VECTOR(*position)[i];
int ex;
if (pos==-1) { continue; }
for (ex=VECTOR(myconverter->exidx)[iso];
ex < VECTOR(myconverter->exidx)[iso+1] &&
VECTOR(myconverter->exlim)[ex] <= pos;
ex++) ;
if (ex < VECTOR(myconverter->exidx)[iso+1]) {
VECTOR(*position)[i] = pos + VECTOR(myconverter->shift)[ex];
} else {
VECTOR(*position)[i] = -1;
}
}
if (!converter) {
splicing_gff_converter_destroy(myconverter);
SPLICING_FINALLY_CLEAN(1);
}
return 0;
}
示例11: splicing_genomic_to_iso
int splicing_genomic_to_iso(const splicing_gff_t *gff, size_t gene,
const splicing_vector_int_t *position,
const splicing_gff_converter_t *converter,
splicing_matrix_int_t *isopos) {
size_t r, i, noreads=splicing_vector_int_size(position);
splicing_gff_converter_t vconverter,
*myconverter = (splicing_gff_converter_t*) converter;
if (!converter) {
myconverter=&vconverter;
SPLICING_CHECK(splicing_gff_converter_init(gff, gene, myconverter));
SPLICING_FINALLY(splicing_gff_converter_destroy, myconverter);
}
SPLICING_CHECK(splicing_matrix_int_resize(isopos, myconverter->noiso,
noreads));
for (r=0; r<noreads; r++) {
for (i=0; i<myconverter->noiso; i++) {
size_t pos=VECTOR(*position)[r];
size_t startpos=VECTOR(myconverter->exidx)[i];
size_t endpos=VECTOR(myconverter->exidx)[i+1];
int ex;
for (ex=startpos;
ex < endpos && VECTOR(myconverter->exend)[ex] < pos;
ex++) ;
if (ex < endpos && VECTOR(myconverter->exstart)[ex] <= pos &&
pos <= VECTOR(myconverter->exend)[ex]) {
MATRIX(*isopos, i, r) = VECTOR(*position)[r] -
VECTOR(myconverter->shift)[ex];
} else {
MATRIX(*isopos, i, r) = -1;
}
}
}
if (!converter) {
splicing_gff_converter_destroy(myconverter);
SPLICING_FINALLY_CLEAN(1);
}
return 0;
}
示例12: spmY
/*
--------------------------------------------------------------------------------------------------
- check collision with stairs
--------------------------------------------------------------------------------------------------
*/
bool PlanesPhysicHandler::ColisionWithCornerStair(const AABB & actorBB, const VECTOR &Speed, VECTOR &ModifiedSpeed)
{
float moveX = Speed.x;
float moveZ = Speed.z;
// calculate norm of speed
VECTOR speedNorm = Speed.unit();
float startX = (actorBB.P.x+actorBB.E.x)/2.0f;
float startZ = (actorBB.P.z+actorBB.E.z)/2.0f;
std::vector<CornerStairPlane>::const_iterator it = _corner_stairs.begin();
std::vector<CornerStairPlane>::const_iterator end = _corner_stairs.end();
// for each stairs
for(int i=0; it != end; ++it, ++i)
{
// project point to plane and check if we cross it
float DotProduct=speedNorm.dot(it->Normal);
// Determine If Ray Parallel To Plane
if (abs(DotProduct) > 0.000001f)
{
// Find Distance To Collision Point
float l2=(it->Normal.dot(it->C1-VECTOR(startX, actorBB.P.y, startZ)))/DotProduct;
// Test If Collision Behind Start or after end
if (l2 > 0 && l2 < Speed.length())
{
float collionsX = startX + (speedNorm.x * l2);
float collionsZ = startZ + (speedNorm.z * l2);
if(it->tr_wh_y.contains(Point2D(collionsX, collionsZ)))
{
VECTOR spmY(Speed.x, 0, Speed.z);
VECTOR Vt(it->Normal.dot(spmY)*it->Normal);
VECTOR Vn(spmY - Vt);
ModifiedSpeed = Vn;
return true;
}
}
}
}
return false;
}
示例13: VECTOR
/*******************************
** Minimalization of the GB ***
*******************************/
void gbB::minimalize_gb()
{
if (minimal_gb_valid) return;
delete minimal_gb;
minimal_gb = ReducedGB::create(originalR,F,Fsyz);
VECTOR(POLY) polys;
for (int i=first_gb_element; i<gb.size(); i++)
{
if (gb[i]->minlevel & ELEMB_MINGB)
polys.push_back(gb[i]->g);
}
minimal_gb->minimalize(polys);
minimal_gb_valid = true;
}
示例14: igraph_vector_order2
int igraph_vector_order2(igraph_vector_t *v) {
igraph_indheap_t heap;
igraph_indheap_init_array(&heap, VECTOR(*v), igraph_vector_size(v));
IGRAPH_FINALLY(igraph_indheap_destroy, &heap);
igraph_vector_clear(v);
while (!igraph_indheap_empty(&heap)) {
IGRAPH_CHECK(igraph_vector_push_back(v, igraph_indheap_max_index(&heap)-1));
igraph_indheap_delete_max(&heap);
}
igraph_indheap_destroy(&heap);
IGRAPH_FINALLY_CLEAN(1);
return 0;
}
示例15: isZeroHMMlinear
int isZeroHMMlinear(Hmm *m){
int u, v, zero = 1;
for (u = 0; u < m->uu; u ++){
if (VECTOR(m->logB)[u] != 0){
zero = 0;
break;
}
for (v = 0; v < m->uu; v ++){
if (MATRIX(m->logA)[u][v] != 0){
zero = 0;
break;
}
}
if (zero == 0) break;
}
return zero;
}