Example #1
0
  void operator_2( const blocked_range<size_t>& r ) {   
	double value;
	IntVector indexArray(m_lenArray.size());
	DoubleVector argArray(m_lenArray.size());	
    Index1DToArray(r.begin(), m_lenArray, indexArray);

	int nStride0 = m_ControlGridArray[0].strides()[0];
	const char *pBegin0 = (const char*) (m_ControlGridArray[0].array().data());
	const char *pEnd0 = pBegin0 + (nStride0 * m_lenArray[0]);
	const char *pData0 = pBegin0 + (nStride0 * indexArray[0]);
	int nStride1 = m_ControlGridArray[1].strides()[0];
	const char *pBegin1 = (const char*) (m_ControlGridArray[1].array().data());
	const char *pEnd1 = pBegin1 + (nStride1 * m_lenArray[1]);
	const char *pData1 = pBegin1 + (nStride1 * indexArray[1]);
	
    for( size_t index=r.begin(); index!=r.end(); ++index ){
      argArray[0] = * (double*) pData0;
	  argArray[1] = * (double*) pData1;

  	  value = m_params.objectiveFunction(argArray);	  
      if (value > m_value_of_max) {
        m_value_of_max = value;
		m_argmax = argArray;
      }

	  pData1 += nStride1;
	  if (pData1 == pEnd1) {
	    pData1 = pBegin1;
	    pData0 += nStride0;
	  }	  
    }
  }
  QVariant DiscreteVariable_Impl::toServerFormulationVariant() const {
    QVariantMap map;

    map["uuid"] = toQString(removeBraces(uuid()));
    map["version_uuid"] = toQString(removeBraces(uuid()));
    map["name"] = toQString(name());
    map["display_name"] = toQString(displayName());
    map["type"] = QString("Integer"); // could be Discrete instead

    // determine minimum, maximum from all values
    IntVector allValues = validValues(false);
    // right now, only have MeasureGroup, this will always be contiguous listing
    map["minimum"] = 0;
    map["maximum"] = int(allValues.size()) - 1;
    // no initial_value implemented right now

    // if selected values are subset, list them separately
    IntVector selectedValues = validValues(true);
    if (selectedValues.size() < allValues.size()) {
      QVariantList selectedList;
      for (int val : selectedValues) {
        selectedList.push_back(QVariant(val));
      }
      map["selected_values"] = selectedList;
    }

    return QVariant(map);
  }
Example #3
0
void Ioss::ParallelUtils::global_count(const IntVector &local_counts, IntVector &global_counts) const
{
  // Vector 'local_counts' contains the number of objects
  // local to this processor.  On exit, global_counts
  // contains the total number of objects on all processors.
  // Assumes that ordering is the same on all processors
  global_counts.resize(local_counts.size());
#ifdef HAVE_MPI
  if (local_counts.size() > 0 && parallel_size() > 1) {
    if (Ioss::SerializeIO::isEnabled() && Ioss::SerializeIO::inBarrier()) {
      std::ostringstream errmsg;
      errmsg << "Attempting mpi while in barrier owned by " << Ioss::SerializeIO::getOwner();
      IOSS_ERROR(errmsg);
    }
    const int success = MPI_Allreduce((void*)&local_counts[0], &global_counts[0],
				      static_cast<int>(local_counts.size()),
				      MPI_INT, MPI_SUM, communicator_);
    if (success !=  MPI_SUCCESS) {
      std::ostringstream errmsg;
      errmsg  << "Ioss::ParallelUtils::global_count - MPI_Allreduce failed";
      IOSS_ERROR(errmsg);
    }
  } else {
    // Serial run, just copy local to global...
    std::copy(local_counts.begin(), local_counts.end(), global_counts.begin());
  }
#else
  std::copy(local_counts.begin(), local_counts.end(), global_counts.begin());
#endif
}
void FileSplit::init ( const IntVector& nFileSpec, const IntVector& nSearchSpec )
{
	int spec = 0;
	for ( IntVectorSizeType j = 0, k = 0 ; j < nSearchSpec.size () ; j++ ) {
		startFraction.push_back ( k+1 );
		startSpec.push_back ( spec+1 );
		int r = nFileSpec [k] - spec;		// Number of spectra remaining in this fraction
		int s = nSearchSpec [j];			// Number of spectra for this search
		if ( r >= s ) {						// All spectra available from this fraction
			s += spec;
		}
		else {								// Get some spectra from other fractions
			while ( r < s ) {
				k++;
				s -= r;
				r = nFileSpec [k];
			}
		}
		endFraction.push_back ( k+1 );
		endSpec.push_back ( s );
		if ( nFileSpec [k] == s ) {
			if ( k+1 < nFileSpec.size () ) k++;
			spec = 0;
		}
		else spec = s;
	}
}
Example #5
0
TEST(IntegerVectorTest, ShortInitializerListConstructor) {
    IntVector* object = IntVector::create({ 7 });
    ASSERT_EQ(1, object->size());
    EXPECT_EQ( 7, (*object)[0]);

    object = IntVector::create({ });
    EXPECT_EQ(0, object->size());
}
Example #6
0
 void chain(const IntVector &path)
 {
   chain_lengths_.push_back(path.size()-1);
   for(IntVector::size_type position=0; position<path.size(); ++position)
   {
     IntVector::const_reference node = path[position];
     counts_[node][position] += 1;
   }
 }
Example #7
0
void
processSolution(IntVector const& subset)
{
	if (subset.size() < cmin)
	{
		cmin = subset.size();
		solution.assign(subset.begin(), subset.end());
	}
	//printVector(subset);
}
Example #8
0
IntVector riffleShuffle(const IntVector& v) {
    IntVector result(v.size());
    for (size_t i = 0; i < v.size(); ++i) {
        if (i & 1) {
            result[i] = v[i / 2 + (v.size() / 2)];
        } else {
            result[i] = v[i / 2];
        }
    }
    return result;
}
Example #9
0
// TBB will divide up the task range among threads with a blocked_range.
// for N arbitrary dimensions, we need to use a 1d blocked_range, and then translate the index given in each range into the correct N-dimensional coordinates.
// wrap a gridArray with something that maps indices to a 1d range (obviously total size can't exceed the max value of an int)
inline unsigned int IndexListTo1D(IntVector const &lenArray, IntVector const &indexArray) {
  unsigned int i;  
  assert(lenArray.size() == indexArray.size());
  if (lenArray.size() == 0) {
    return 0;
  }
  unsigned int result = indexArray[0];
  for (i=1; i<lenArray.size(); i++) {
    result *= lenArray[i];
    result += indexArray[i];
  }
  return result;
}
Example #10
0
/**
 * clear() tests
 */
void testClear() {
  IntVector v;
  v.push(0);
  v.push(1);
  v.push(2);
  
  v.clear();
  
  assert(v.size() == 0);
  
  // test empty
  v.clear();
  assert(v.size() == 0);
}
Example #11
0
IntVector Permutation::apply(IntVector const &v)const
{
  IntVector ret(size());
  assert(size()==v.size());
  for(int i=0;i<size();i++)ret[i]=v[(*this)[i]];
  return ret;
}
Example #12
0
void ParticleSystem::update()
{
    mMonitor->addSample(mUsed.size());

    typedef vector<int> IntVector;
    IntVector removeParticles;
    
    // Iterator over each particle, making its callback. If callback returns true, puts its index into the removeParticles list.
    for(uint32_t i = 0; i<mUsed.size(); ++i)
    {
        Particle* p = mUsed[i];
        if(p->mCallback(p, this) == false)
        {
            removeParticles.push_back(i);
        }
    }
    
    // Now iterate over remove list and the particles.
    for(uint32_t i=0; i < removeParticles.size(); ++i)
    {
        // Get a reference the particle. Every iteratation is going to remove one particle.
        // Which means the indexes stored in removeParticles are wrong.
        // To adjust, subtract from the stored index the number of particels we have already removed.
        uint32_t indexInUsed = removeParticles[i] - i;
        Particle* p = mUsed[indexInUsed];
        gImageLibrary->unreference(p->mImage.getImage());
        mUsed.erase(mUsed.begin() + indexInUsed);
        mAvailable.push_back(p);
    }
}
Example #13
0
	bool Solve(int number) {
		char *line = GetSingleLine();
		ULL A, B;
		int P;
		if (sscanf(line, "%lld %lld %d", &A, &B, &P) != 3) {
			return false;
		}

		int Size = (int)(B - A + 1);
		UnionFind uf(Size);

		int i, j;
		for (i = 0; i < (int)m_Primes.size(); ++i) {
			int p = m_Primes[i];
			if (p < P) {
				continue;
			}
			ULL r = A % (ULL)p;
			int x = (p - (int)r) % p;		// 区間における端数
			for (j = x + p; j < Size; j += p) {
				uf.unionSet(x, j);
			}
		}

		// 根となっている数(=集合の数)を調べる
		int result = 0;
		for (i = 0; i < Size; ++i) {
			if (uf.root(i) == i) {
				++result;
			}
		}

		printf("Case #%d: %d\n", number + 1, result);
		return true;
	}
Example #14
0
void
findLongestRun(const IntVector& vect_int)
{
	int start = 0;
	unsigned cmax = 1, max = 1, i = 0;
	for (; i < vect_int.size()-1; ++i)
	{
		if (vect_int[i] < vect_int[i+1])
		{
			++cmax;
		}
		else
		{
			if (max < cmax)
			{
				max = cmax;
				start = i + 1 - cmax;
			}
			cmax = 1;
		}
	}
	
	if (max < cmax)
	{
		max = cmax;
		start = i + 1 - cmax;
	}

	
	std::cout<<"max seq: "<<max <<" start: "<<start<<"\n";
}
Example #15
0
// check whether a rectangle cm collides with the fields
bool Scene::RectCollidesWithFields(CollisionModel *cm, IntVector fields)
{
    // read out data

    for(unsigned int i= 0; i < fields.size(); i++)
    {
        int idx = fields[i];
        float x = (idx % FIELD_SIZE);
        float z = float (floor( float(idx)/float(FIELD_SIZE)) );
        float offset = float(FIELD_SIZE)/2.0;

        // create a rectangle model for the current field
        CollisionModel field_cm(COLL_RECTANGLE);
        field_cm.setVertex(0, x - offset, z - offset);
        field_cm.setVertex(1, x - offset, z - offset + 1.0);
        field_cm.setVertex(2, x - offset + 1.0, z - offset + 1.0);
        field_cm.setVertex(3, x - offset + 1.0, z - offset);
        field_cm.setYBottom(0.0);
        field_cm.setYTop(50.0);      /** TODO: this should be read from
                                    // the landscape data structure */

        // check for collisions between rectangle and field
        bool res = cm->bCollision(&field_cm);
        if(res == true)
        {
            return true;
        }
    }

    return false;
}
Example #16
0
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QScriptEngine eng;
    // register our custom types
    qScriptRegisterMetaType<IntVector>(&eng, toScriptValue, fromScriptValue);
    qScriptRegisterMetaType<StringVector>(&eng, toScriptValue, fromScriptValue);

    QScriptValue val = eng.evaluate("[1, 4, 7, 11, 50, 3, 19, 60]");

    fprintf(stdout, "Script array: %s\n", qPrintable(val.toString()));

    IntVector iv = qscriptvalue_cast<IntVector>(val);

    fprintf(stdout, "qscriptvalue_cast to QVector<int>: ");
    for (int i = 0; i < iv.size(); ++i)
        fprintf(stdout, "%s%d", (i > 0) ? "," : "", iv.at(i));
    fprintf(stdout, "\n");

    val = eng.evaluate("[9, 'foo', 46.5, 'bar', 'Qt', 555, 'hello']");

    fprintf(stdout, "Script array: %s\n", qPrintable(val.toString()));

    StringVector sv = qscriptvalue_cast<StringVector>(val);

    fprintf(stdout, "qscriptvalue_cast to QVector<QString>: ");
    for (int i = 0; i < sv.size(); ++i)
        fprintf(stdout, "%s%s", (i > 0) ? "," : "", qPrintable(sv.at(i)));
    fprintf(stdout, "\n");

    return 0;
}
inline void IndexedList::erase(size_t const&e) {

	//	check();
	if (contains(e)) {
		//		TRACE("remove "<<e<<" " <<_element[e]<<std::endl);
		//		for (IntVector::const_iterator i(_list.begin()); i != _list.end(); ++i)
		//			std::cout << *i << std::endl;
		/// on switch avec le dernier puis on réduit
		//		std::cout << "_list[" << _element[e] << "] = " << _list.back()
		//				<< std::endl;

		_list[_element[e]] = front();
		_element[front()] = _element[e];

		//		std::cout << "_element[" << e << "] = " << max_size() << std::endl;

		_element[e] = max_size();

		_list[size() - 1] = -1;

		//		std::cout << "_list[" << size() - 1 << "] = -1;" << std::endl;

		_list.erase(_list.begin() + _list.size() - 1);
		//		std::cout << "###########" << std::endl;
		//		for (IntVector::const_iterator i(_list.begin()); i != _list.end(); ++i)
		//			std::cout << *i << std::endl;
		///
	}
	//	check();
	//	TRACE_N(size());
	//	TRACE_N(max_size());
	//	DEBUG_ASSERT("NO REALLOCATION ALLOWED"&&size()<=max_size());
}
Example #18
0
void
generateBacktrack(IntVector& current_set, unsigned n)
{
	unsigned csum = std::accumulate(current_set.begin(), current_set.end(), 0);
	if (csum > n)
	{
		//discard this solution
		return;
	}
	
	
	if (csum == n)		//if solution, print it
	{
		processSolution(current_set);
	}
	else
	{
		IntVector candidates = getCandidates(current_set, n, csum);
		for (unsigned i =0; i < candidates.size(); ++i)
		{
			current_set.push_back(candidates.at(i));
			generateBacktrack(current_set, n);
			current_set.pop_back();
		}
	}
}
Example #19
0
TEST(IntegerVectorTest, InitializerListConstructor) {
    IntVector* object = IntVector::create({ 7, 14, 8, 1 });
    ASSERT_EQ(4, object->size());
    EXPECT_EQ( 7, (*object)[0]);
    EXPECT_EQ(14, (*object)[1]);
    EXPECT_EQ( 8, (*object)[2]);
    EXPECT_EQ( 1, (*object)[3]);
}
Example #20
0
// check whether the two field-vectors v1 and v2 have an overlap
bool fieldsCollide(IntVector v1, IntVector v2)
{
    for(unsigned int i = 0; i < v1.size(); i++)
    {
        int idx1 = v1[i];
        for(unsigned int j = 0; j < v2.size(); j++)
        {
            int idx2 = v2[j];
            if(idx1 == idx2)
            {
                return true;
            }
        }
    }

    return false;
}
Example #21
0
// Lambda?
static void initializeTargetsRandomly(std::parallel_context& context,
	IntVector& targets, int totalNodes)
{
	assert(context.thread_id_in_context() < targets.size());
	
	targets[context.thread_id_in_context()] =
		std::parallel_uniform_random<int>(0, totalNodes);
}
Example #22
0
unsigned
getPreviousMin(IntVector const& s, unsigned i)
{
	//we have to compute min number of coins for i, knowing solution for 0..i-1
	//subtract each coin from i (x = i - coin(j)) and get minimum from s[x]
	unsigned diff = i - coins.at(0);
	if (diff > s.size())
	{
		std::cerr<<"diff: "<<diff<<"\n";
		throw std::logic_error("Invalid diff");
	}
	unsigned min = s.at(diff);	//start with this
	
	unsigned found_coin = 0;
	unsigned prev_idx = diff;
	
	for (unsigned j = 1; j < coins.size(); ++j)
	{
		//std::cout<<"Coin at j :"<<coins.at(j)<<"\n";
		if (i > coins.at(j))
		{
			diff = i - coins.at(j);
			if (diff > s.size())
			{
				std::cerr<<"diff2: "<<diff<<"\n";
				throw std::logic_error("Invalid diff");
			}
			
			if (min > s.at(diff))
			{
				min = s.at(diff);
				found_coin = j;
				prev_idx = diff;
			}
		}
	}
	
	IntVector tmp = dyn_solution.at(prev_idx);
	tmp.push_back(coins.at(found_coin));
	dyn_solution.push_back(tmp);
	
	//std::cout<<"For i: "<<i<<" found min: "<<min<<" at :"<<diff<<"\n";
	//std::cout<<"Found coin: "<<coins.at(found_coin)<<"\n";
	//printVector(tmp);
	return min;
}
Example #23
0
File: main.cpp Project: ztenv/linux
void print(const char * name,IntVector &v)
{
    cout<<name<<"[]=";
    for(size_t i=0;i<v.size();++i)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
Example #24
0
/**
 * push() tests
 */
void testPush() {
  IntVector v;
  v.insert(0, 0);
  v.push(5);
  
  assert(v.size() == 2);
  assert(v[0] == 0);
  assert(v[1] == 5);
}
Example #25
0
/**
 * unshift() tests
 */
void testUnshift() {
  IntVector v;
  v.push(0);
  v.unshift(5);
  
  assert(v.size() == 2);
  assert(v[0] == 5);
  assert(v[1] == 0);
}
Example #26
0
 ArrayVector forward(const ArrayVector &input)
 {
     mData.resize(mNodeSizes.size());
     mData[0] = input;
     for (int i = 0; i < (int)mNodes.size(); i++) {
         mData[i + 1] = mNodes[i]->forward(mData[i]);
     }
     return mData.back();
 }
Example #27
0
/**
 * append() tests
 */
void testAppend() {
  IntVector v;
  v.push(0);
  v.append(5);
  
  assert(v.size() == 2);
  assert(v[0] == 0);
  assert(v[1] == 5);
}
Example #28
0
 void chain(const IntVector &path)
 {
   if(n_chains_found_ <= ncols_ && path.size()<=IntVector::size_type(nrows_))
   {
     const IntVector::size_type path_length(path.size());
     std::memcpy(chains_ + n_chains_found_ * nrows_, &path[0],
                 path_length*sizeof(IntVector::value_type));
     n_chains_found_ += 1;
   }
   else
   {
     DEBUG(Rprintf("Chains storage space exceeded\n"));
     DEBUG(Rprintf("nrows [%d] ncols [%d]\n", nrows_, ncols_));
     DEBUG(Rprintf("n_chains_found_ [%d]\n", n_chains_found_));
     DEBUG(Rprintf("path length [%d]\n", path.size()));
     throw CheddarException("Chains storage space exceeded");
   }
 }
Example #29
0
	double ImageUtils::estimateLineThickness(Image &bwimg, int grid)
	{
		int w = bwimg.getWidth();
		int h = bwimg.getHeight();
		int d = grid;

		IntVector lthick;

		if(w < d)
			d = std::max<int>(w >>1, 1) ; 
		{
			int startseg = -1;
			for(int i = 0; i < w ; i += d)
			{
				for(int j = 0; j < h; j++)
				{
					byte val = bwimg.getByte(i, j);
					if(val == 0 && (startseg == -1))
						startseg = j;
					if((val > 0 || j==(h-1)) && startseg != -1)
					{
						lthick.push_back(j - startseg + 1);
						startseg = -1;
					}
				}
			}
		}

		if(h > d)
			d = grid;
		else
			d = std::max<int>(h >>1, 1) ; 

		{
			int startseg = -1;
			for(int j = 0; j< h; j+=d)
			{
				for(int i = 0; i < w; i++)
				{
					byte val = bwimg.getByte(i, j);
					if(val == 0 && (startseg == -1))
						startseg = i;
					if((val > 0 || i==(w-1)) && startseg != -1)
					{
						lthick.push_back(i - startseg + 1);
						startseg = -1;
					}
				}
			}
		}
		std::sort(lthick.begin(), lthick.end());
		double thickness = 0;
		if(lthick.size() > 0)
			thickness = StatUtils::interMean(lthick.begin(), lthick.end());
	
		return thickness;
	}
Example #30
0
void writeIntVector(ContainerNode &node,
                    const string &array_name,
                    const IntVector &v) throw(Error)
{
    ContainerNode array_node = node.writeNewArray(array_name);
    for (unsigned i=0; i<v.size(); ++i) {
	array_node.writeNumber("", (float)v[i]);
    }
}