Beispiel #1
0
//Returns new vector, multiplying elements with the same index
int64_t* vector_mul(int64_t* vector_a, int64_t* vector_b)
{
	if (g_vec_properties[arg1][0] == UNIFORM)
	{
		if (vector_a[0] == 0)
			return cloned(zerovector);
		if (vector_a[0] == 1)
			return cloned(vector_b);
	}
	if (g_vec_properties[arg2][0] == UNIFORM)
	{
		if (vector_b[0] == 0)
			return cloned(zerovector);
		if (vector_a[0] == 1)
			return cloned(vector_a);
	}

	int64_t* result = new_vector();
	if (g_length > PARAFLOOR)
	{
		para_vector_mul (vector_a, vector_b, result);
		return result;
	}

	for (int64_t i = 0; i < g_length; i++) {
		result[i] = vector_a[i] * vector_b[i];
	}

	return result;
}
Beispiel #2
0
//Returns new vector, adding elements with the same index
int64_t* vector_add(int64_t* vector_a, int64_t* vector_b)
{
	//Returns vector_b if a is all 0s
	if (g_vec_properties[arg1][0] == UNIFORM && vector_a[0] == 0)
		return cloned(vector_b);

	//Returns vector_a if b is all 0s
	else if (g_vec_properties[arg2][0] == UNIFORM && vector_b[0] == 0)
		return cloned(vector_a);

	//Returns an array of 0s if the two are uniform inverses
	else if (g_vec_properties[arg1][0] == UNIFORM && g_vec_properties[arg2][0] == UNIFORM &&
			vector_a[0] == -vector_b[0])
		return cloned(zerovector);

	int64_t* result = new_vector();

	//Parallelise if above a certain threshold for g_length
	if (g_length > PARAFLOOR)
	{
		//If both vectors are sequences - no memory reading of either is required for the result
		if ((g_vec_properties[arg1][0] == SEQUP || g_vec_properties[arg1][0] == SEQDOWN) &&
				(g_vec_properties[arg2][0] == SEQUP || g_vec_properties[arg2][0] == SEQDOWN))
		{
			para_vector_add (vecAdd_worker_2SEQ, vector_a, vector_b, result);
			return result;
		}

		//If only one vector is a sequence - only the non-seq needs to be read
		if (g_vec_properties[arg1][0] == SEQUP || g_vec_properties[arg1][0] == SEQDOWN)
		{
			para_vector_add(vecAdd_worker_ASEQ, vector_a, vector_b, result);
			return result;
		}

		if (g_vec_properties[arg2][0] == SEQDOWN || g_vec_properties[arg1][0] == SEQUP)
		{
			para_vector_add(vecAdd_worker_BSEQ, vector_a, vector_b, result);
			return result;
		}

		para_vector_add (vecAdd_worker, vector_a, vector_b, result);
		return result;
	}

	//Simply sequential
	for (int64_t i = 0; i < g_length; i++) {
		result[i] = vector_a[i] + vector_b[i];
	}

	return result;
}
void InstantiationVisitor::visit(BehaviourInstantiation& b)
{
	std::vector<std::unique_ptr<DeclarationStmt>> decls;
	std::vector<std::unique_ptr<SyntheticEndpoint>> endpoints;
	std::vector<std::unique_ptr<OnBlock>> onBlocks;

	for (auto& decl : b.baseClass()->variables())
		decls.emplace_back(cloneCast<DeclarationStmt>(*decl));

	for (auto& ep : b.baseClass()->endpoints()) {
		auto readBlock = ep->readBlock() ? cloneCast<BlockStmt>(*ep->readBlock()) : nullptr;
		auto readValue = ep->readValue() ? clone(*ep->readValue()) : nullptr;
		auto write = ep->write() ? cloneCast<BlockStmt>(*ep->write()) : nullptr;

		std::unique_ptr<SyntheticEndpoint> cloned(
			new SyntheticEndpoint(
				ep->sloc(), ep->name(), ep->type(), std::move(readBlock), std::move(readValue), std::move(write)));
		endpoints.emplace_back(std::move(cloned));
	}

	for (auto& on : b.baseClass()->onBlocks())
		onBlocks.emplace_back(clone(*on));

	b.instantiation(
		std::unique_ptr<BehaviourDefinition>(
			new BehaviourDefinition(
				b.sloc(), b.name(), b.device(), std::move(decls), std::move(endpoints), std::move(onBlocks))));
}
void BufferView::setBuffer(IrcBuffer* buffer)
{
    if (d.buffer != buffer) {
        d.buffer = buffer;

        IrcChannel* channel = qobject_cast<IrcChannel*>(buffer);
        d.listView->setChannel(channel);
        d.listView->setVisible(channel);

        d.titleBar->setBuffer(buffer);
        d.textInput->setBuffer(buffer);
        if (buffer) {
            TextDocument* doc = 0;
            QList<TextDocument*> documents = d.buffer->findChildren<TextDocument*>();
            // there might be multiple clones, but at least one instance
            // must always remain there to avoid losing history...
            Q_ASSERT(!documents.isEmpty());
            foreach (TextDocument* d, documents) {
                if (!d->isVisible())
                    doc = d;
            }
            if (!doc) {
                doc = documents.first()->clone();
                emit cloned(doc);
            }
            d.textBrowser->setDocument(doc);
        } else {
Beispiel #5
0
ActorFeaturePtr Destroyable::clone()
{
  DestroyablePtr cloned(new Destroyable);
  cloned->_dropRules = _dropRules;

  return cloned;
}
Beispiel #6
0
EffectPtr DamageEffect::clone()
{
  EffectPtr cloned( new DamageEffect );
  cloned->load( toParams() );

  return cloned;
}
Beispiel #7
0
    void ShardingState::donateChunk( const string& ns , const BSONObj& min , const BSONObj& max , ChunkVersion version ) {
        scoped_lock lk( _mutex );

        CollectionMetadataMap::const_iterator it = _collMetadata.find( ns );
        verify( it != _collMetadata.end() ) ;
        CollectionMetadataPtr p = it->second;

        // empty shards should have version 0
        version =
                ( p->getNumChunks() > 1 ) ?
                        version : ChunkVersion( 0, 0, p->getCollVersion().epoch() );

        ChunkType chunk;
        chunk.setMin( min );
        chunk.setMax( max );
        string errMsg;

        CollectionMetadataPtr cloned( p->cloneMigrate( chunk, version, &errMsg ) );
        // uassert to match old behavior, TODO: report errors w/o throwing
        uassert( 16855, errMsg, NULL != cloned.get() );

        // TODO: a bit dangerous to have two different zero-version states - no-metadata and
        // no-version
        _collMetadata[ns] = cloned;
    }
Beispiel #8
0
ActorFeaturePtr Scroll::clone()
{
  ScrollPtr cloned( new Scroll );

  Pickable::clone( cloned.get() );

  return cloned;
}
Beispiel #9
0
MaskSequenceFx MaskSequenceFx::clone() const
{
	MaskSequenceFx cloned(_size.size_x, _size.size_y);

	for (uint t = 0; t < _size.size_t; t++) {
		cloned.add(_frames[t].clone());
	}

	return cloned;
}
void WordFixFormattedStringVisitor::visit(const FormattedStringTextBlock * const formattedStringTextBlock)
{
	cloned(make_unique<FormattedStringTextBlock>(
		fixWords(formattedStringTextBlock->content()),
		formattedStringTextBlock->bold(),
		formattedStringTextBlock->italic(),
		formattedStringTextBlock->underline(),
		formattedStringTextBlock->color()
	));
}
Beispiel #11
0
Sequence<T> Sequence<T>::clone() const
{
	Sequence<T> cloned(_size.size_x, _size.size_y);

	for (uint t = 0; t < _size.size_t; t++) {
		cloned.add(_frames[t].clone());
	}

	return cloned;
}
Beispiel #12
0
QCodeCompletionEngine * CCompletion::clone()
{
    CCompletion *e = new CCompletion();

    foreach ( QString t, triggers() )
        e->addTrigger(t);

    emit cloned(e);

    return e;
}
void MultiModifierTest::testClone() {
        ims::MultiModifier<peaklist_t> modifier;
        modifier.addModifier(std::auto_ptr<ims::Modifier<peaklist_t> >(
                new ims::SortModifier<peaklist_t>));
        modifier.addModifier(std::auto_ptr<ims::Modifier<peaklist_t> >(
                new ims::UnificationModifier<peaklist_t>));

        std::auto_ptr<ims::Modifier<peaklist_t> > cloned(modifier.clone());
        cloned->modify(peaklist);
        assertHelp();
}
Beispiel #14
0
IMPLEMENT_TEST(TextObjectUnitTests, clone) {
    TextObject object("object", TextObjectTestData::getObjRef());

    U2OpStatusImpl os;
    GObject *clonedGObj = object.clone(TextObjectTestData::getDbiRef(), os);
    QScopedPointer<TextObject> cloned(dynamic_cast<TextObject*>(clonedGObj));
    CHECK_NO_ERROR(os);

    cloned->setText("cloned text");

    CHECK_TRUE("text" == object.getText(), "text");
    CHECK_TRUE("cloned text" == cloned->getText(), "cloned text");
}
Beispiel #15
0
    void ShardingState::donateChunk( const string& ns , const BSONObj& min , const BSONObj& max , ShardChunkVersion version ) {
        scoped_lock lk( _mutex );

        ChunkManagersMap::const_iterator it = _chunks.find( ns );
        assert( it != _chunks.end() ) ;
        ShardChunkManagerPtr p = it->second;

        // empty shards should have version 0
        version = ( p->getNumChunks() > 1 ) ? version : ShardChunkVersion( 0 , 0 );

        ShardChunkManagerPtr cloned( p->cloneMinus( min , max , version ) );
        _chunks[ns] = cloned;
    }
Beispiel #16
0
ActorFeaturePtr Wearer::clone()
{
  WearerPtr cloned( new Wearer );

  for(auto i : _itemSlots)
  {
    cloned->_itemSlots[ i.first ] = nullptr;
  }

  cloned->_equippedItems = std::dynamic_pointer_cast<Container>(_equippedItems->clone());
  assignItemsToSlots(cloned);

  return cloned;
}
Beispiel #17
0
ActorFeaturePtr Wearer::clone()
{
  WearerPtr cloned( new Wearer );

  for(auto i : _itemSlots)
  {
    cloned->_itemSlots[ i.first ] = std::make_pair(nullptr, false);
  }

  cloned->_equippedItems = _equippedItems->clone();
  cloned->assignItemsToSlots();

  return cloned;
}
Beispiel #18
0
    void ShardingState::donateChunk( const string& ns , const BSONObj& min , const BSONObj& max , ChunkVersion version ) {
        scoped_lock lk( _mutex );

        ChunkManagersMap::const_iterator it = _chunks.find( ns );
        verify( it != _chunks.end() ) ;
        ShardChunkManagerPtr p = it->second;

        // empty shards should have version 0
        version = ( p->getNumChunks() > 1 ) ? version : ChunkVersion( 0 , OID() );

        ShardChunkManagerPtr cloned( p->cloneMinus( min , max , version ) );
        // TODO: a bit dangerous to have two different zero-version states - no-manager and
        // no-version
        _chunks[ns] = cloned;
    }
Beispiel #19
0
/**
 * Returns new matrix with elements in ascending order
 */
uint32_t* sorted(const uint32_t* matrix) {
    
    uint32_t* result = cloned(matrix);
    
    /*
     to do
     
     1 0    0 0
     0 1 => 1 1
     
     4 3    1 2
     2 1 => 3 4
     */
    
    return result;
}
Beispiel #20
0
//Returns new vector, with elements ordered in reverse
int64_t* reversed(int64_t* vector) 
{

	int64_t* result = new_vector();
	if (g_vec_properties[arg1][0] == UNIFORM)
		return cloned(vector);
	else if (g_length > PARAFLOOR)
	{
		para_reverse(result, vector);
		return result;
	}

	for (int64_t i = 0; i < g_length; i++) {
		result[i] = vector[g_length - 1 - i];
	}

	return result;
}
Beispiel #21
0
//Returns new vector, with elements ordered from largest to smallest
int64_t* descending(int64_t* vector) 
{
	int64_t* result = cloned(vector);

	if (g_vec_properties[arg1][0] == DOWN || g_vec_properties[arg1][0] == UNIFORM || g_vec_properties[arg1][0] == SEQDOWN)
	{
		return result;
	}
	else if (g_vec_properties[arg1][0] == UP || g_vec_properties[arg1][0] == SEQUP ||
			g_vec_properties[arg1][0] == PRIME)
	{
		free(result);
		return reversed(vector);
	}

	qsort(result, g_length, sizeof(int64_t), int64Descend);
	return result;
}
Beispiel #22
0
    bool ShardingState::forgetPending( const string& ns,
                                       const BSONObj& min,
                                       const BSONObj& max,
                                       const OID& epoch,
                                       string* errMsg ) {
        scoped_lock lk( _mutex );

        CollectionMetadataMap::const_iterator it = _collMetadata.find( ns );
        if ( it == _collMetadata.end() ) {

            *errMsg = str::stream() << "no need to forget pending chunk "
                                    << "[" << min << "," << max << ")"
                                    << " because the local metadata for " << ns << " has changed";

            return false;
        }

        CollectionMetadataPtr metadata = it->second;

        // This can currently happen because drops aren't synchronized with in-migrations
        // The idea for checking this here is that in the future we shouldn't have this problem
        if ( metadata->getCollVersion().epoch() != epoch ) {

            *errMsg = str::stream() << "no need to forget pending chunk "
                                    << "[" << min << "," << max << ")"
                                    << " because the epoch for " << ns << " has changed from "
                                    << epoch << " to " << metadata->getCollVersion().epoch();

            return false;
        }

        ChunkType chunk;
        chunk.setMin( min );
        chunk.setMax( max );

        CollectionMetadataPtr cloned( metadata->cloneMinusPending( chunk, errMsg ) );
        if ( !cloned ) return false;

        _collMetadata[ns] = cloned;
        return true;
    }
Beispiel #23
0
    void ShardingState::mergeChunks( const string& ns,
                                     const BSONObj& minKey,
                                     const BSONObj& maxKey,
                                     ChunkVersion mergedVersion ) {

        scoped_lock lk( _mutex );

        CollectionMetadataMap::const_iterator it = _collMetadata.find( ns );
        verify( it != _collMetadata.end() );

        string errMsg;

        CollectionMetadataPtr cloned( it->second->cloneMerge( minKey,
                                                              maxKey,
                                                              mergedVersion,
                                                              &errMsg ) );
        // uassert to match old behavior, TODO: report errors w/o throwing
        uassert( 17004, errMsg, NULL != cloned.get() );

        _collMetadata[ns] = cloned;
    }
/**
 * Returns new matrix, powering the matrix to the exponent
 */
uint32_t* matrix_pow(const uint32_t* matrix, uint32_t exponent) 
{

    uint32_t* result = cloned(matrix);

    if(exponent==0)
    {
        result = identity_matrix();
    }
    
    else
    {
        for (int c=0; c<exponent-1 && exponent!=0; c++)
        {
            result = matrix_mul(result, matrix);
        }
    }

    

    return result;
}
Beispiel #25
0
    void ShardingState::splitChunk( const string& ns,
                                    const BSONObj& min,
                                    const BSONObj& max,
                                    const vector<BSONObj>& splitKeys,
                                    ChunkVersion version )
    {
        scoped_lock lk( _mutex );

        CollectionMetadataMap::const_iterator it = _collMetadata.find( ns );
        verify( it != _collMetadata.end() ) ;

        ChunkType chunk;
        chunk.setMin( min );
        chunk.setMax( max );
        string errMsg;

        CollectionMetadataPtr cloned( it->second->cloneSplit( chunk, splitKeys, version, &errMsg ) );
        // uassert to match old behavior, TODO: report errors w/o throwing
        uassert( 16857, errMsg, NULL != cloned.get() );

        _collMetadata[ns] = cloned;
    }
void UnificationModifierTest::testClone() {
	ims::UnificationModifier<peaklist_t> modifier;
	std::auto_ptr<ims::Modifier<peaklist_t> > cloned(modifier.clone());
	cloned->modify(peaklist);
	assertHelp();
}
Beispiel #27
0
/**
 * Set command
 */
void command_set(const char* line) {

    char cmd[MAX_BUFFER];
    char key[MAX_BUFFER];
    char func[MAX_BUFFER];
    char arg1[MAX_BUFFER];
    char arg2[MAX_BUFFER];

    int argc = sscanf(line, "%s %s = %s %s %s", cmd, key, func, arg1, arg2);
    if (argc < 3) {
        puts("invalid arguments");
        return;
    }

    uint32_t* matrix = NULL;

    switch (argc) {
        case 3:
            if (strcasecmp(func, "identity") == 0) {
                matrix = identity_matrix();
            } else {
                goto invalid;
            }
            break;

        case 4:
            if (strcasecmp(func, "random") == 0) {
                uint32_t seed = atoll(arg1);
                matrix = random_matrix(seed);
            } else if (strcasecmp(func, "uniform") == 0) {
                uint32_t value = atoll(arg1);
                matrix = uniform_matrix(value);
            } else if (strcasecmp(func, "cloned") == 0) {
                MATRIX_GUARD(arg1);
                matrix = cloned(m);
            } else if (strcasecmp(func, "reversed") == 0) {
                MATRIX_GUARD(arg1);
                matrix = reversed(m);
            } else if (strcasecmp(func, "transposed") == 0) {
                MATRIX_GUARD(arg1);
                matrix = transposed(m);
            } else {
                goto invalid;
            }
            break;

        case 5:
            if (strcasecmp(func, "sequence") == 0) {
                uint32_t start = atoll(arg1);
                uint32_t step = atoll(arg2);
                matrix = sequence_matrix(start, step);
            } else if (strcasecmp(func, "scalar#add") == 0) {
                MATRIX_GUARD(arg1);
                uint32_t value = atoll(arg2);
                matrix = scalar_add(m, value);
            } else if (strcasecmp(func, "scalar#mul") == 0) {
                MATRIX_GUARD(arg1);
                uint32_t value = atoll(arg2);
                matrix = scalar_mul(m, value);
            } else if (strcasecmp(func, "matrix#add") == 0) {
                MATRIX_GUARD_PAIR(arg1, arg2);
                matrix = matrix_add(m1, m2);
            } else if (strcasecmp(func, "matrix#mul") == 0) {
                MATRIX_GUARD_PAIR(arg1, arg2);
                matrix = matrix_mul(m1, m2);
            } else if (strcasecmp(func, "matrix#pow") == 0) {
                MATRIX_GUARD(arg1);
                uint32_t exponent = atoll(arg2);
                matrix = matrix_pow(m, exponent);
            } else {
                goto invalid;
            }
            break;
    }

    entry* e = find_entry(key);
    if (e == NULL) {
        e = add_entry(key);
    } else {
        free(e->matrix);
    }

    e->matrix = matrix;

    puts("ok");
    return;

invalid:
    puts("invalid arguments");
}
Beispiel #28
0
 std::unique_ptr<Sampler> clone() const {
     std::unique_ptr<Independent> cloned(new Independent());
     cloned->m_sampleCount = m_sampleCount;
     cloned->m_random = m_random;
     return std::move(cloned);
 }
Beispiel #29
0
  bool SaveJPEG(File* file, Image* image) {
    COR_GUARD("SaveJPEG");

    if (!image) {
      return false;
    }

    //Hack for now
    FILE* filePtr = (FILE*)file->GetFilePtr();
    if(!filePtr)
    {
      return false;
    }

    // If the image format isn't supported directly by this function,
    // clone to a supported format and try to save with that.
    switch (image->getFormat()) {
      case PF_R8G8B8:
	      break;
      default: {
	      COR_LOG("Unsupported pixel format... cloning");
	      std::auto_ptr<Image> cloned(CloneImage(image, PF_R8G8B8));
	      return SaveJPEG(file, cloned.get());
      }
    }

    const int width  = image->getWidth();
    const int height = image->getHeight();

   	jpeg_compress_struct cinfo;
	  jpeg_error_mgr jerr;

	  cinfo.err = jpeg_std_error(&jerr);
	  jpeg_create_compress(&cinfo);

	  int nChannels = 3;

	  cinfo.in_color_space = JCS_RGB;
	  jpeg_set_defaults(&cinfo);

	  cinfo.input_components = nChannels;
	  cinfo.num_components   = nChannels;
	  cinfo.image_width  = width;
	  cinfo.image_height = height;
	  cinfo.data_precision = 8;
	  cinfo.input_gamma = 1.0;

	  jpeg_set_quality(&cinfo, 75, FALSE);
    
	  jpeg_stdio_dest(&cinfo, filePtr);
	  jpeg_start_compress(&cinfo, TRUE);

	  unsigned char *curr_scanline = (unsigned char *)image->getPixels();

	  for (int y = 0; y < height; y++){
		  jpeg_write_scanlines(&cinfo, &curr_scanline, 1);
		  curr_scanline += nChannels * width;
	  }

	  jpeg_finish_compress(&cinfo);
	  jpeg_destroy_compress(&cinfo);

    return true;
  }
Beispiel #30
0
//Returns the most frequently occuring element
//or -1 if there is no such unique element
int64_t get_mode(int64_t* vector) 
{

	if (g_existCalcs[arg1].modeFlag == 1)
		return g_existCalcs[arg1].mode;
	g_existCalcs[arg1].modeFlag = 1;

	//Mode of a uniform vector is any element within it
	if (g_length == 1 || g_vec_properties[arg1][0] == UNIFORM)
	{
		g_existCalcs[arg1].mode = vector[0];
		return vector[0];
	}

	//All vectors with unique values have no mode
	else if (g_vec_properties[arg1][0] == SEQUP || g_vec_properties[arg1][0] == SEQDOWN ||
			g_vec_properties[arg1][0] == PRIME)
	{
		g_existCalcs[arg1].mode = -1;
		return -1;
	}

	int64_t max = get_maximum(vector);
	int64_t min = get_minimum(vector);
	if ((max - min) <   2147483648) //16gb can hold 2147483648 int64s
		//12gb can hold 1610612736 int64s
		//8gb  can hold 1073741824 int64s
		//4gb  can hold 536870912  int64s
		return fast_mode(vector, max, min);

	int64_t* result = cloned(vector);
	qsort(result, g_length, sizeof(int64_t), int64Ascend);

	int64_t curSpanCount = 0, hiSpanCount = 0, 
			currentCheck = 0, repeatCount = 0, mode = 0;

	for (int64_t i = 0; i < g_length; i++)
	{
		if (currentCheck != result[i])
		{
			currentCheck = result[i];
			curSpanCount = 0;
		}
		curSpanCount++;

		if (curSpanCount > hiSpanCount)
		{
			repeatCount = 0;
			hiSpanCount = curSpanCount;
			mode = currentCheck;   
		}
		else if (currentCheck != result[i+1] && curSpanCount == hiSpanCount)
		{
			repeatCount = 1;
		}
	}

	if (repeatCount > 0)
	{
		g_existCalcs[arg1].mode = -1;
		return -1;
	}

	g_existCalcs[arg1].mode = mode;
	return mode;
}