vector<float> ofxKinectFeatures::getDistanceToTorsoHistory(int j){
    if (getElement(j)) {
        return getElement(j)->getDistanceToTorso();
    } else {
        return createVector(0.0f);
    }
}
vector<ofPoint> ofxKinectFeatures::getRelativePositionToTorsoHistory(int j){
    if (getElement(j)) {
        return getElement(j)->getRelativePositionToTorso();
    } else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
vector<ofPoint> ofxKinectFeatures::getAccelerationHistory(int j){
    if (getElement(j)) {
        return getElement(j)->getAcceleration();
    } else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
vector<float> ofxKinectFeatures::getAccelerationTrajectoryHistory(int j){
    if (getElement(j)) {
        return getElement(j)->getAccelerationTrajectory();
    } else {
        return createVector(0.0f);
    }
}
vector<ofPoint> ofxKinectFeatures::getPositionFilteredHistory(int j){
    if (getElement(j)) {
        return getElement(j)->getPositionFiltered();
    } else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
vector<ofPoint> ofxKinectFeatures::getVelocityHistory(int j){
    if (getElement(j)) {
        return getElement(j)->getVelocity();
    } else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
示例#7
0
文件: ex4-serial.c 项目: sjbs/tma4280
int main(int argc, char** argv)
{
	if (argc < 2) {
		printf("Need n, number of vector elements. Tard.\n");
		return 1;
	}
	
	int N=atoi(argv[1]);
	
	if (N<=0) {
		printf("Need a positive vector length, mormon.\n");
		return 1;
	}
	
	double sum=0;
	
	Vector v = createVector(N);
	
	for (long int i=0;i<N;++i) {
		double temp=1.0/((i+1)*(i+1));
		v->data[i] = temp;	
		sum += temp;
	}
	
	//exact value of pi
	double pi=(4.0*atan(1.0));
	
	printf("sum: %f\n", sum);
	printf("difference: %1.16f\n", pi*pi/6.0-sum);
	
}
示例#8
0
文件: lexer.c 项目: t3rm1n4l/alloy
void startLexingFiles(Lexer *self, Vector *sourceFiles) {
	for (int i = 0; i < sourceFiles->size; i++) {
		SourceFile *sourceFile = getVectorItem(sourceFiles, i);

		// reset everything
		self->inputLength = strlen(sourceFile->fileContents);
		if (self->inputLength <= 0) {
			errorMessage("File `%s` is empty", sourceFile->name);
			self->failed = true;
			return;
		}
		self->input = sourceFile->fileContents;
		self->pos = 0;
		self->lineNumber = 1;
		self->charNumber = 1;
		self->currentChar = self->input[self->pos];
		self->tokenStream = createVector(VECTOR_EXPONENTIAL);
		self->running = true;
		self->fileName = sourceFile->fileName;

		// get all the tokens
		while (self->running) {
			getNextToken(self);
		}

		// set the tokens to the current
		// token stream of the file being
		// lexed.
		sourceFile->tokens = self->tokenStream;
	}
}
int main() {
  int count = 0;
  int total = 0;
  int largest = INT_MIN;
  Element i;

  Vector vector = createVector();
  V_Iterator it = getEnd(&vector);

  while( (scanf("%d",&i) == 1 ) ) {
    if(vector.size == 0 )
      prepend(&vector,i);
    else {
      insertAfter(&it,i);
      moveNext(&it);
    }
    if( i > largest) largest = i;
  }
  
  printf( "Valor máximo: %d\n", largest);
  it = getBegin(&vector);

  while( it.index < vector.size ) {
    i = getElement(&it);  
//    if( largest % i == 0 ) {
      total += i;
      count++;
//    }
    moveNext(&it);
  }
  if(count != 0)
    printf( "Média: %d\n", (total/count));
}
示例#10
0
void applyingRightHouseHolder(Vector* w, Vector** A_n, int nlins){
  int i, j;
  Vector *aux;
  float lambda, wt_a_2;

  lambda = dotProduct(w,w);
  aux = createVector(A_n[0]->len);
  
  for(i = 0; i < nlins; i++){
    cpyVectors(w, aux);
    /* wt_a_2 = dotProduct(w, A_n[i]) * 2;*/
    wt_a_2 = 0;
    for(j = 0; j < A_n[0]->len; j++){
      wt_a_2 += w->data[j]*A_n[j]->data[i];
    }
    wt_a_2 *= 2;
    /***/

    if(lambda != 0.0) multByScalar((wt_a_2 / lambda), aux);

    /*subVectors(A_n[i], aux, A_n[i]);*/
    for(j = 0; j < A_n[0]->len; j++){
      A_n[j]->data[i] -=  aux->data[j];
    }
    /***/
  }
  free(aux);
}
示例#11
0
int main(int argc,char* argv[]){

  vector* vec = createVector();
  printf("\nnew vector-pointer generated\n\n");

  writeVector(vec,argv[1]);

  printVector(vec);

  int searchResult = search(vec,10);
  printf("%d\n\n",searchResult);

  data* newData1 = createData(51,44,19.290122);
  addBegin(vec,newData1);
  printf("new data added to beginning\n\n");

  data* newData2 = createData(10,59,82.430034);
  addNpos(vec,newData2,6);
  printf("new data added to position 6\n\n");

  searchResult = search(vec,10);
  printf("%d\n\n",searchResult);

  printVector(vec);

  freeVector(vec);
  printf("vector freed\n");

  return 0;
}
示例#12
0
static openstudio::TimeSeries convertData(std::vector<openstudio::DateTime> inputDateTimes,
                                          std::vector<double> inputValues, std::string units)
{
  // Use a per-interval trapezoidal approximation to convert the CONTAM point data into E+ interval data
  std::vector<openstudio::DateTime> dateTimes;
  std::vector<double> values;
  if(inputDateTimes.size()==1) // Account for steady simulation results
  {
    return openstudio::TimeSeries(inputDateTimes,createVector(inputValues),units);
  }
  for(unsigned i=1;i<inputDateTimes.size();i++)
  {
    dateTimes.push_back(inputDateTimes[i]);
    values.push_back(0.5*(inputValues[i-1]+inputValues[i]));
  }
  return openstudio::TimeSeries(dateTimes,createVector(values),units);
}
示例#13
0
	ALGEB lbCreateVector (MKernelVector kv, ALGEB *argv){
		M_INT argc = MapleNumArgs(kv, (ALGEB) argv);
		const VectorKey *key;
		if ((argc < 1) || (argc > 4)){
			MapleRaiseError(kv, "wrong number of arguments");
			return ToMapleNULL(kv);
		}
		try {
			if (argc == 1){
				if (IsMapleRTable(kv, argv[1]))
					return lbCreateVectorFromVector(kv, argv[1], LinBox::integer(0));
			}
			if (argc == 2){
				if (IsMapleInteger(kv, argv[1]) && IsMapleRTable(kv, argv[2])){
					//LinBox::integer *p = GMPMapleToLinBox(kv, argv[1]);
					LinBox::integer p;
					GMPMapleToLinBox(p, kv, argv[1]);
					LB_GMP_SET();
					ALGEB ret = lbCreateVectorFromVector(kv, argv[2], p);
					LB_GMP_RESTORE();
					return ret;
				}

				if ( IsMapleDomainKey(kv, argv[1]) && IsMapleInteger(kv, argv[2])) {
					const DomainKey *k = &MapleToDomainKey(kv, argv[1]);
					LB_GMP_SET();
					key = &createVector(*k, MapleToInteger32(kv, argv[2]));
					LB_GMP_RESTORE();
					return VectorKeyToMaple(kv, *key);
				}
			}
			if (argc == 3){
				if ( IsMapleDomainKey(kv, argv[1]) && IsMapleInteger(kv, argv[2]) && IsMapleString(kv, argv[3])){
					const DomainKey *k = &MapleToDomainKey(kv, argv[1]);
					LB_GMP_SET();
					key = &createVector(*k, MapleToInteger32(kv, argv[2]), MapleToString(kv, argv[3]));
					LB_GMP_RESTORE();
					return VectorKeyToMaple(kv, *key);
				}
			}
			MapleRaiseError(kv, "wrong types of arguments");
		}
		catch ( lb_runtime_error &t )
			{ lbRaiseError(kv, t); }
		return ToMapleNULL(kv);
	}
示例#14
0
Vector createEigenValues(int m)
{ 
  Vector diag = createVector(m);
  for (int i=0; i < m; i++) 
    diag->data[i] = 2.0*(1.0-cos((i+1)*M_PI/(m+1)));

  return diag;
}
示例#15
0
Quantity dot(OSQuantityVector lVector, const OSQuantityVector& rVector) {
  Unit lUnits(lVector.units()), rUnits(rVector.units());
  OptionalTemperatureUnit ltu = lUnits.optionalCast<TemperatureUnit>();
  OptionalTemperatureUnit rtu = rUnits.optionalCast<TemperatureUnit>();
  Unit resultUnits;
  if (ltu && rtu) {
    resultUnits = ltu.get() * rtu.get();
  }
  else {
    resultUnits = lUnits * rUnits;
  }
  ScaleOpReturnType resultScale = lVector.scale() * rVector.scale();
  lVector *= resultScale.second;
  DoubleVector lValues(lVector.values()), rValues(rVector.values());
  double resultValue = dot(createVector(lValues),createVector(rValues));
  return Quantity(resultValue,resultUnits);
}
示例#16
0
文件: common.c 项目: georgekw/tma4280
void collectMatrix(Matrix u)
{
#ifdef HAVE_MPI
  int source, dest;
  // south
  MPI_Cart_shift(*u->as_vec->comm, 1, -1, &source, &dest);
  MPI_Sendrecv(u->data[1]+1, u->rows-2, MPI_DOUBLE, dest, 0,
               u->data[u->cols-1]+1, u->rows-2, MPI_DOUBLE, source, 0,
               *u->as_vec->comm, MPI_STATUS_IGNORE);

  // north
  MPI_Cart_shift(*u->as_vec->comm, 1, 1, &source, &dest);
  MPI_Sendrecv(u->data[u->cols-2]+1, u->rows-2, MPI_DOUBLE, dest, 1,
               u->data[0]+1, u->rows-2, MPI_DOUBLE, source, 1,
               *u->as_vec->comm, MPI_STATUS_IGNORE);

  Vector sendBuf = createVector(u->cols-2);
  Vector recvBuf = createVector(u->cols-2);

  // west
  MPI_Cart_shift(*u->as_vec->comm, 0, -1, &source, &dest);
  if (dest != MPI_PROC_NULL)
    copyVectorDispl(sendBuf, u->row[1], u->cols-2, 1);
  MPI_Sendrecv(sendBuf->data, sendBuf->len, MPI_DOUBLE, dest, 2,
               recvBuf->data, recvBuf->len, MPI_DOUBLE, source, 2,
               *u->as_vec->comm, MPI_STATUS_IGNORE);
  if (source != MPI_PROC_NULL)
    dcopy(&recvBuf->len, recvBuf->data, &recvBuf->stride,
          u->row[u->rows-1]->data+u->rows, &u->rows);

  // east
  MPI_Cart_shift(*u->as_vec->comm, 0, 1, &source, &dest);
  if (dest != MPI_PROC_NULL)
    copyVectorDispl(sendBuf, u->row[u->rows-2], u->cols-2, 1);
  MPI_Sendrecv(sendBuf->data, sendBuf->len, MPI_DOUBLE, dest, 2,
               recvBuf->data, recvBuf->len, MPI_DOUBLE, source, 2,
               *u->as_vec->comm, MPI_STATUS_IGNORE);
  if (source != MPI_PROC_NULL)
    dcopy(&recvBuf->len, recvBuf->data, &recvBuf->stride,
          u->row[0]->data+u->rows, &u->rows);

  freeVector(sendBuf);
  freeVector(recvBuf);
#endif
}
示例#17
0
vector<ofPoint> OpenNIUser::getPositionFilteredHistory(int j)
{
    if (getElement(j)) {
        return getElement(j)->getPositionFiltered();
    }
    else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
vector<ofPoint> ofxKinectFeatures::getRelativePositionToTorsoHistory(int j, int frames){
    if (getElement(j)) {
        vector<ofPoint> fullHistory = getElement(j)->getRelativePositionToTorso();
        vector<ofPoint> history(fullHistory.begin(), fullHistory.begin() + frames);
        return history;
    } else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
vector<float> ofxKinectFeatures::getDistanceToTorsoHistory(int j, int frames){
    if (getElement(j)) {
        vector<float> fullHistory = getElement(j)->getDistanceToTorso();
        vector<float> history(fullHistory.begin(), fullHistory.begin() + frames);
        return history;
    } else {
        return createVector(0.0f);
    }
}
vector<float> ofxKinectFeatures::getAccelerationTrajectoryHistory(int j, int frames){
    if (getElement(j)) {
        vector<float> fullHistory = getElement(j)->getAccelerationTrajectory();
        vector<float> history(fullHistory.begin(), fullHistory.begin() + frames);
        return history;
    } else {
        return createVector(0.0f);
    }
}
vector<ofPoint> ofxKinectFeatures::getVelocityHistory(int j, int frames){
    if (getElement(j)) {
        vector<ofPoint> fullHistory = getElement(j)->getVelocity();
        vector<ofPoint> history(fullHistory.begin(), fullHistory.begin() + frames);
        return history;
    } else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
示例#22
0
const VectorKey& lb_minpoly(const BlackboxKey& key) {
	BlackboxTable::iterator it = blackbox_hashtable.find(key);
	if ( it == blackbox_hashtable.end())
		throw lb_runtime_error("LinBox ERROR: blackbox is not defined (minpoly computation impossible)");

	const VectorKey *res = & createVector(it->second->getDomainKey(), 0, "linbox_dense");
	lb_minpoly(*res, key);
	return *res;
}
示例#23
0
sparseVector *cloneVector(sparseVector *sparse)
{
  sparseVector *hold;
  hold = createVector(sparse->limit, sparse->count);
  hold->count = sparse->count;
  MEMCOPY(&hold->value[0], &sparse->value[0], (sparse->count+1));
  MEMCOPY(&hold->index[0], &sparse->index[0], (sparse->count+1));
  return(hold);
}
示例#24
0
vector<float> OpenNIUser::getDistanceToTorsoHistory(int j)
{
    if (getElement(j)) {
        return getElement(j)->getDistanceToTorso();
    }
    else {
        return createVector(0.0f);
    }
}
示例#25
0
vector<float> OpenNIUser::getAccelerationTrajectoryHistory(int j)
{
    if (getElement(j)) {
        return getElement(j)->getAccelerationTrajectory();
    }
    else {
        return createVector(0.0f);
    }
}
示例#26
0
vector<ofPoint> OpenNIUser::getVelocityHistory(int j)
{
    if (getElement(j)) {
        return getElement(j)->getVelocity();
    }
    else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
示例#27
0
vector<ofPoint> OpenNIUser::getAccelerationHistory(int j)
{
    if (getElement(j)) {
        return getElement(j)->getAcceleration();
    }
    else {
        return createVector(ofPoint(0.0,0.0,0.0));
    }
}
示例#28
0
Vector genVector(int length)
{
  Vector vec = createVector(length);
  for (int i = 0; i < length; ++i)
  {
    vec->data[i]=1./((i+1)*(i+1));
  }
  return vec;
}
示例#29
0
文件: poisson1D.c 项目: akva2/tma4280
void DiagonalizationPoisson1D(Vector u, const Vector lambda, const Matrix Q)
{
  Vector btilde = createVector(u->len);
  int i;
  MxV(btilde, Q, u, 1.0, 0.0, 'T');
  for (i=0;i<btilde->len;++i)
    btilde->data[i] /= lambda->data[i];
  MxV(u, Q, btilde, 1.0, 0.0, 'N');
  freeVector(btilde);
}
示例#30
0
void clearMap(OBMap *m){

  assert(m);

  release((obj *)m->hash_table);
  release((obj *)m->pairs);

  m->hash_table = createVector(MAP_CAPACITIES[m->cap_idx]);
  m->pairs = createDeque();
}