コード例 #1
0
int main()
{
    init_platform();
    initInterrupts();

	int source_word[16];
	int destination_word[16];
	setArray(source_word, 16, 0);
	setArray(destination_word, 16, 1);

    printf("Printing value before DMA transfer.\n\r");
    printArray(destination_word, 16);

    DMA_CONTROLLER_InitiateTransfer(XPAR_DMA_CONTROLLER_0_BASEADDR, (Xuint32) &source_word, (Xuint32) &destination_word, 4 * 10);

    printf("Printing value after DMA transfer.\n\r");
    printArray(destination_word, 16);

	setArray(source_word, 6, 1);
    DMA_CONTROLLER_InitiateTransfer(XPAR_DMA_CONTROLLER_0_BASEADDR, (Xuint32) &source_word, (Xuint32) &destination_word, 4 * 10);

    printf("Printing value after 2nd DMA transfer.\n\r");
    printArray(destination_word, 16);

    cleanup_platform();

    return 0;
}
コード例 #2
0
int main(int argc, char const *argv[]) {
	int TC;
	scanf("%d", &TC);
	while(TC--) {
		int a, b;
		scanf("%d %d", &a, &b);
		int digitsA = digits(a), digitsB = digits(b);
		char reversedValueA[digitsA], reversedValueB[digitsB];
		setArray(reversedValueA);
		setArray(reversedValueB);
		reversedToString(a, digitsA, reversedValueA);
		reversedToString(b, digitsB, reversedValueB);
		detArray(reversedValueA);
		detArray(reversedValueB);
		int ra = valueOf(digitsA, reversedValueA);
		int rb = valueOf(digitsB, reversedValueB);
		int sum = ra + rb;
		int digitsSum = digits(sum);
		char reversedValue[digitsSum];
		setArray(reversedValue);
		reversedToString(sum, digitsSum, reversedValue);
		printf("%d\n", valueOf(digitsSum, reversedValue));
	}
	return 0;
}
コード例 #3
0
ファイル: two_arrays2.c プロジェクト: ArtisticCoding/T2
int main() {
  int i = 0;
  elem *arrayOne = (elem*)malloc(arraySize * sizeof(elem));
  elem *arrayTwo = (elem*)malloc(arraySize * sizeof(elem));

  resetArray(arrayOne);
  setArray(arrayTwo);
  initializeCount(arrayTwo);

  for (i = 0; i < arraySize; i++) {
    __SMACK_assert(arrayOne[i].status == RESET);
    __SMACK_assert(arrayTwo[i].status == SET);
    __SMACK_assert(arrayTwo[i].count == 0);
  }

  initializeCount(arrayOne);
  setArray(arrayOne);
  resetArray(arrayTwo);

  for (i = 0; i < arraySize; i++) {
    __SMACK_assert(arrayOne[i].count == 0);
    __SMACK_assert(arrayOne[i].status == SET);
    __SMACK_assert(arrayTwo[i].status == RESET);
  }

  free(arrayOne);
  free(arrayTwo);
  return 0;
}
コード例 #4
0
ファイル: two_arrays.c プロジェクト: DastanIqbal/smack
int main() {
  int i = 0;
  int *arrayOne = (int*)malloc(MAXSIZE * sizeof(int));
  int *arrayTwo = (int*)malloc(MAXSIZE * sizeof(int));

  resetArray(arrayOne);
  setArray(arrayTwo);

  for (i = 0; i < MAXSIZE; i++) {
    __SMACK_assert(arrayOne[i] == RESET);
    __SMACK_assert(arrayTwo[i] == SET);
  }

  setArray(arrayOne);
  resetArray(arrayTwo);

  for (i = 0; i < MAXSIZE; i++) {
    __SMACK_assert(arrayOne[i] == SET);
    __SMACK_assert(arrayTwo[i] == RESET);
  }

  free(arrayOne);
  free(arrayTwo);
  return 0;
}
コード例 #5
0
int bitonic_subs(int a[], int n){
	
	//Find LIS
	//LDS (longest decreasing subs)
	//return max(lis[i],lds[i]-1);
	
	int sol_lis[n];
	setArray(sol_lis,n,1);
	for(int i = 1; i < n; i++){
		for(int j = 0; j < i; j++){
			if(a[j] < a[i] && sol_lis[i] < sol_lis[j]+1){
				sol_lis[i] = sol_lis[j]+1;
			}
		}
	}

	int sol_lds[n];
	setArray(sol_lds,n,1);
	for(int i = n-2; i >= 0; i--){
		for(int j = n-1; j > i; j--){
			if(a[j] < a[i] && sol_lds[i] < sol_lds[j]+1){
				sol_lds[i] = sol_lds[j]+1;
			}
		}
	}
	
	int maxi = INT_MIN;
	for(int i = 0; i < n; i++){
		maxi = max(maxi,sol_lds[i]+sol_lis[i]-1);
	}
	return maxi;
}
コード例 #6
0
ファイル: two_arrays6_fail.c プロジェクト: Checkmate50/smack
int main() {
  int i = 0;
  elem *arrayOne;
  elem *arrayTwo;

  arraySize = __VERIFIER_nondet_int();
  assume(arraySize > 0);

  arrayOne = (elem*)malloc(arraySize * sizeof(elem));
  arrayTwo = (elem*)malloc(arraySize * sizeof(elem));

  resetArray(arrayOne);
  setArray(arrayTwo);
  initializeCount(arrayTwo);

  for (i = 0; i < arraySize; i++) {
    assert(arrayOne[i].status == RESET);
    assert(arrayTwo[i].status == SET);
    assert(arrayTwo[i].count == 0);
  }

  initializeCount(arrayOne);
  setArray(arrayOne);
  resetArray(arrayTwo);

  for (i = arraySize - 1; i >= 0; i--) {
    assert(arrayOne[i].count != 0 || arrayOne[i].status != SET || arrayTwo[i].status != RESET);
  }

  free(arrayOne);
  free(arrayTwo);
  return 0;
}
コード例 #7
0
ファイル: bodySystemGPU-impl.hpp プロジェクト: Hopobcn/nbody
void BodySystemGPU<T>::loadFile(const std::string &filename)
{
    if (m_bInitialized)
        _finalize();

    std::vector< typename vec4<T>::Type > positions;
    std::vector< typename vec4<T>::Type > velocities;
    std::vector< int > ids;

    int nBodies = 0;
    int nFirst=0, nSecond=0, nThird=0;

    read_file(positions,
              velocities,
              ids,
              filename,
              nBodies,
              nFirst,
              nSecond,
              nThird);

    _initialize(nBodies);

    setArray(BODYSYSTEM_POSITION, (T *)&positions[0]);
    setArray(BODYSYSTEM_VELOCITY, (T *)&velocities[0]);
}
コード例 #8
0
ファイル: FluidSystem.cpp プロジェクト: Alan-ZhangDaixi/fluid
void FluidSystem::reset(FluidConfig config) //回到初始状态
{
	uint s = (int)ceilf(powf((float)m_numParticles, 1.0f / 3.0f));

	float jitter = m_params.particleRadius*0.01f;
	switch (config)
	{
	default:
	case CONFIG_RANDOM:
	{
		for (uint z = 0; z < s; z++)
		{
			for (uint y = 0; y < s; y++)
			{
				for (uint x = 0; x < s; x++)
				{
					uint i = (z*s * s) + (y*s) + x;

					if (i < m_numParticles)
					{
						m_hPos[i * 4] = (3 * x) + m_params.particleRadius - 128.0f /*+ (frand()*2.0f-1.0f)*jitter*/;
						m_hPos[i * 4 + 1] = (3 * y) + m_params.particleRadius - 31.0f /*+ (frand()*2.0f-1.0f)*jitter*/;
						m_hPos[i * 4 + 2] = (3 * z) + m_params.particleRadius - 64.0f /*+ (frand()*2.0f-1.0f)*jitter*/;
						m_hPos[i * 4 + 3] = 1.0f;

						m_hVel[i * 4] = 0.0f;
						m_hVel[i * 4 + 1] = 0.0f;
						m_hVel[i * 4 + 2] = 0.0f;
						m_hVel[i * 4 + 3] = 0.0f;

						m_hDen[i] = 0.0f;
						m_hPre[i] = 0.0f;
						m_hColorf[i] = 0.0f;
					}
				}
			}
		}
	}
	break;

	case CONFIG_GRID:
	{
		uint gridSize[3];
		gridSize[0] = gridSize[1] = gridSize[2] = s;



		initGrid(gridSize, m_params.particleRadius*2.0f, jitter, m_numParticles);
	}
	break;
	}

	setArray(POSITION, m_hPos, 0, m_numParticles);
	setArray(VELOCITY, m_hVel, 0, m_numParticles);
	setArray(DENSITY, m_hDen, 0, m_numParticles);
	setArray(PRESSURE, m_hPre, 0, m_numParticles);
	setArray(COLORFIELD, m_hColorf, 0, m_numParticles);
}
コード例 #9
0
ファイル: poiseuilleFlowSystem.cpp プロジェクト: hoopoe/cmag
void PoiseuilleFlowSystem::reset(){
	elapsedTime = 0.0f;
	float jitter = params.particleRadius * 0.01f;			            
	float spacing = params.particleRadius * 2.0f;
	initFluid(spacing, jitter, numParticles);
	initBoundaryParticles(spacing);

	setArray(POSITION, hPos, 0, numParticles);
	setArray(VELOCITY, hVel, 0, numParticles);	
	setArray(MEASURES, hMeasures, 0, numParticles);
	setArray(ACCELERATION, hAcceleration, 0, numParticles);
	setArray(VELOCITYLEAPFROG, hVelLeapFrog, 0, numParticles);
}
コード例 #10
0
/*
	Note:
	* change priority queue implementation
*/
Graph shortestPathPQ(Graph g, Vertex v)
{
	Graph mst = newGraph(g->nV);
	int *dist = malloc(sizeof(int) * g->nV); // create the distance array
	int *pred = malloc(sizeof(int) * g->nV); // create the predecessor array, stores vertices passed through
	PQueue q = newPQueue(); // create a new priority queue
	Vertex currentVertex = 0, w = 0;
	int i = 0;
	int total = 0;

	assert(dist != NULL && pred != NULL);
	
	// clear all the memory blocks
	setArray(dist, INF, g->nV);
	setArray(pred, -1, g->nV);

	dist[v] = 0;
	for (i = 0; i < g->nV; i++){
		joinPQueue(q, i, dist[i]);
	}
	
	reorder(q, NO_UPDATE, NO_UPDATE);
	while ( !isEmptyPQ(q) ){ // while priority queue is not empty
		currentVertex = leavePQueue(q);
		for (w = 0; w < getnV(g); w++){
			if (g->wt[currentVertex][w] == NO_WEIGHT) continue;
			if (g->wt[currentVertex][w] + dist[currentVertex] < dist[w]){
				dist[w] = g->wt[currentVertex][w] + dist[currentVertex];
				pred[w] = currentVertex;
				reorder(q, w, dist[w]); // updates the priority of vertex w as well
			}
		}
		reorder(q, NO_UPDATE, NO_UPDATE);
	}

	// construct the mst graph
	for (i = 0; i < getnV(g); i++){
		if (pred[i] != NOT_ASSIGNED){
			addEdge(mst, pred[i], i);		
			total += dist[i];
		}
	}

	printf("Total = %d.\n", total);
	deletePQueue(q);
	free(dist);
	free(pred);
	
	return mst;
}
コード例 #11
0
Graph shortestPath(Graph g, Vertex v)
{
	Graph mst = newGraph(g->nV); // create a new mst graph
	Queue q = newQueue(); // create a new queue
	int *visitedVertices = malloc(sizeof(Vertex) * g->nV);
	int *dist = malloc(sizeof(int) * g->nV); // create the distance array
	int *pred = malloc(sizeof(int) * g->nV); // create the predecessor array, stores vertices passed through
	int total = 0, i = 0;
	Vertex curV = 0, w = 0;

	assert(visitedVertices != NULL && dist != NULL && pred != NULL);
	
	// clear all the memory blocks
	setArray(visitedVertices, UNVISITED, g->nV);
	setArray(dist, INF, g->nV);
	setArray(pred, -1, g->nV);

	visitedVertices[v] = VISITED; // mark the starting vertex as visited
	dist[v] = 0;
	
	enQueue(q, v); // add the starting vertex to the queue

	while ( !isEmptyQueue(q) ){
		curV = deQueue(q); // remvoe first element from queue
		for (w = 0; w < getnV(g); w++){
			if (g->wt[curV][w] == NO_WEIGHT) continue;
			if (dist[curV] + g->wt[curV][w] < dist[w]){ // edge relaxation
				dist[w] = dist[curV] + g->wt[curV][w];
				pred[w] = curV;
				enQueue(q,w);
			}
		}
	}
	

	// add the appropriate edges
	for (i = 0; i < g->nV; i++){
		if (pred[i] != NOT_ASSIGNED){
			addEdge(mst, pred[i], i);
			total += dist[i];
		}
	}

	deleteQueue(q);
	free(dist);
	free(pred);
	printf("Total = %d.\n", total);

	return mst;
}
コード例 #12
0
ファイル: ConfigFile.cpp プロジェクト: murdockq/OpenPaint
std::vector<std::string> ConfigFile::getArray(std::string strAttribute, std::vector<std::string> listDefaults)
{
    std::map<std::string, ConfigAttribute>::iterator p;
    
    //Find the uppercase string in the map
    std::string lstr = Uppercase(strAttribute);
    p = m_mapConfig.find(lstr);
    
    if (p != m_mapConfig.end() && p->second.bIsArray)
    {
        return p->second.listValues;
    }
    else
    {
        std::cout << "Variable " << strAttribute.c_str() << " does not exist in config file or is not an array." <<  std::endl;
        
        //Store the default value in the config file
        if(m_bAddDefaultsToConfig && listDefaults.size() > 0)
        {
            setArray(strAttribute, listDefaults);
        }

        return listDefaults;
    }
}
コード例 #13
0
ファイル: WString.cpp プロジェクト: MattSanford/Arduino
String::String(const String &str)
{
  _length = _capacity = str._length;
  _array = (char*)malloc(_length + 1);
  clear();
  setArray(str._array);
}
コード例 #14
0
ファイル: VertexArray.cpp プロジェクト: Meorw/spaceofroids
VertexArray::VertexArray(
		const char				*nidentifier,

		void					*new_array,
		u32						nstride,
		u32						n,

		PrimitiveLayout_t		layout,

		AttributeUsage_t		nusage

	) : Resource(nidentifier, NO_PURGE, RESOURCE_VERTEX_ARRAY)
{
	handle = 0;
	n_attribs = 0;
	stride = nstride;

	indexArrayTypeSize = 0;

	primitiveLayout = layout;

	usage = nusage;
	n_elements = n;

	holds_index_array = false;
	holds_array = false;

	iarray = 0;
	varray = 0;

	has_bounds = false;

	setArray(new_array, n);
}
コード例 #15
0
ファイル: ArrayImpl.hpp プロジェクト: cbywxkj/COptdev
Array<scalar,index>::Array(const Array& arr)
{
	if(arr.isReferred())
		setReferredArray(arr.size(),arr.dataPtr(),arr.interval());
	else
		setArray(arr);
}
コード例 #16
0
// =============================================================================
Epetra_NumPySerialDenseVector::Epetra_NumPySerialDenseVector(
  const Epetra_SerialDenseVector & src) :
  Epetra_SerialDenseVector(src)
{
  // Synchronize the PyArrayObject with the Epetra_SerialDenseVector
  setArray();
}
コード例 #17
0
// =============================================================================
Epetra_NumPySerialSymDenseMatrix::Epetra_NumPySerialSymDenseMatrix(
  const Epetra_SerialSymDenseMatrix & src) :
  Epetra_SerialSymDenseMatrix(src)
{
  // Synchronize the PyArrayObject with the Epetra_SerialSymDenseMatrix
  setArray(true);
}
コード例 #18
0
// =============================================================================
Epetra_NumPyIntSerialDenseMatrix::Epetra_NumPyIntSerialDenseMatrix(PyObject * pyObject):
  Epetra_IntSerialDenseMatrix(View, getArray(pyObject), getNumRows(pyObject),
			      getNumRows(pyObject), getNumCols(pyObject))
{
  // Synchronize the PyArrayObject with the Epetra_IntSerialDenseMatrix
  setArray();
}
コード例 #19
0
ファイル: Object.cpp プロジェクト: ripple/rippled
void Object::set (std::string const& k, Json::Value const& v)
{
    auto t = v.type();
    switch (t)
    {
    case Json::nullValue:
        return set (k, nullptr);
    case Json::intValue:
        return set (k, v.asInt());
    case Json::uintValue:
        return set (k, v.asUInt());
    case Json::realValue:
        return set (k, v.asDouble());
    case Json::stringValue:
        return set (k, v.asString());
    case Json::booleanValue:
        return set (k, v.asBool());

    case Json::objectValue:
    {
        auto object = setObject (k);
        copyFrom (object, v);
        return;
    }

    case Json::arrayValue:
    {
        auto array = setArray (k);
        for (auto& item: v)
            array.append (item);
        return;
    }
    }
    assert (false);  // Can't get here.
}
コード例 #20
0
int main() {
  elem *array = (elem*)malloc(sizeof(elem));
  array->status = (int*)malloc(sizeof(int));
  setArray(array);
  free(array->status);
  free(array);
  return 0;
}
コード例 #21
0
STDMETHODIMP CVComplexShape::SetEdgeFlags(VARIANT newVal, long iLogID)
{
	double *data;
	if (VariantToDoubleArray(&data, &newVal)) return E_INVALIDARG;
	setArray(aiEdgeFlags,data);

	m_RequestUpdate(iLogID);
	return S_OK;
}
コード例 #22
0
ファイル: SkAnimator.cpp プロジェクト: AliFarahnak/XobotOS
bool SkAnimator::setArray(const char* id, const char* fieldID, SkTypedArray array) {
    SkDisplayable* element = (SkDisplayable*) getElement(id);
    //should I go ahead and change all 'NULL's to 'NULL'?
    if (element == NULL)
        return false;
    const SkMemberInfo* field = getField(element, fieldID);
    if (field == NULL)
        return false;
    return setArray(element, field, array);
}
コード例 #23
0
void
ParticleSystem::reset(ParticleConfig config)
{
    switch (config)
    {
        default:
        case CONFIG_RANDOM:
            {
                int p = 0, v = 0;

                for (uint i=0; i < m_numParticles; i++)
                {
                    float point[3];
                    point[0] = frand();
                    point[1] = frand();
                    point[2] = frand();
                    m_hPos[p++] = 2 * (point[0] - 0.5f);
                    m_hPos[p++] = 2 * (point[1] - 0.5f);
                    m_hPos[p++] = 2 * (point[2] - 0.5f);
                    m_hPos[p++] = 1.0f; // radius
                    m_hVel[v++] = 0.0f;
                    m_hVel[v++] = 0.0f;
                    m_hVel[v++] = 0.0f;
                    m_hVel[v++] = 0.0f;
                }
            }
            break;

        case CONFIG_GRID:
            {
                float jitter = m_params.particleRadius*0.01f;
                uint s = (int) ceilf(powf((float) m_numParticles, 1.0f / 3.0f));
                uint gridSize[3];
                gridSize[0] = gridSize[1] = gridSize[2] = s;
                initGrid(gridSize, m_params.particleRadius*2.0f, jitter, m_numParticles);
            }
            break;
    }

    setArray(POSITION, m_hPos, 0, m_numParticles);
    setArray(VELOCITY, m_hVel, 0, m_numParticles);
}
コード例 #24
0
ファイル: SkAnimator.cpp プロジェクト: AliFarahnak/XobotOS
bool SkAnimator::setArrayInt(const char* id, const char* fieldID, const int* array, int num)
{
    SkTypedArray tArray(SkType_Int);
    tArray.setCount(num);
    for (int i = 0; i < num; i++) {
        SkOperand op;   
        op.fS32 = array[i];
        tArray[i] = op;
    }
    return setArray(id, fieldID, tArray);
}
コード例 #25
0
ファイル: SkAnimator.cpp プロジェクト: AliFarahnak/XobotOS
bool SkAnimator::setArrayString(const char* id, const char* fieldID, const char** array, int num)
{
    SkTypedArray tArray(SkType_String);
    tArray.setCount(num);
    for (int i = 0; i < num; i++) {
        SkOperand op;
        op.fString = new SkString(array[i]);
        tArray[i] = op;
    }
    return setArray(id, fieldID, tArray);
}
コード例 #26
0
ファイル: spinKernelCpu.cpp プロジェクト: nudigamma/dSim
void SpinSystem::cpuIntegrateSystem(float deltaTime, float3 magneticGradient, float phaseConstant){

	//printf("
	
	for (uint i=0; i<m_numSpins; i++){
		cpuIntegrate(i, magneticGradient, phaseConstant, deltaTime);
	}	

	setArray();
	setSpinArray();
}
コード例 #27
0
STDMETHODIMP CVComplexShape::SetPolygonStipple(VARIANT newVal, long iLogID)
{
	double *data;
	if (VariantToDoubleArray(&data, &newVal)) return E_INVALIDARG;
    if (GetLength(data) != 32) return E_INVALIDARG;
    for (int i=0; i<32; ++i)
        ((unsigned int *)data)[i] = (unsigned int)data[i];
	setArray(aiPolygonStipple,data);

	m_RequestUpdate(iLogID);
	return S_OK;
}
コード例 #28
0
ViewmdaModel::ViewmdaModel() 
{
	m_window_min=0;
	m_window_max=1;
	m_saturation_window_min=0;
	m_saturation_window_max=255;
	Mda dummy;
	dummy.allocate(MDA_TYPE_REAL,1,1);
	setArray(dummy);
	m_elliptical_selection=false;
	m_selected_rect=QRect(-1,-1,1,1);
	m_d1=0; m_d2=1; m_d3=2;
}
コード例 #29
0
ファイル: WString.cpp プロジェクト: MattSanford/Arduino
String::String(const char* bytes)
{
  if(bytes == NULL)
    bytes= "";
  _length = strlen(bytes);
  //if (_capacity < _length) {
  _capacity = _length;
  //  free(_array);
  _array = (char*)malloc(_length+1);
  //}
     
  clear();  
  setArray(bytes);
}
コード例 #30
0
int main() {
  double arrayOnStack[10];
  stackArray = arrayOnStack;
  createNewArray();
  createMallocArray();

  setArray(stackArray);
  setArray(newArray - 1);
  setArray(mallocArray - 1);

  printArray(newArray);
  printArray(mallocArray);

  axpy(newArray, stackArray);
  axpy(newArray, mallocArray);

  // delete stackArray;
  stackArray = 0;
  newArray = 0;
  mallocArray = 0;

  return 0;
}