int main(int argc, char* argv[]) {
    if (argc == 4) 
        optimize(Contract(argv[1]), std::atol(argv[2]), std::atol(argv[3]));
    else if (argc == 3) 
        Contract(argv[1]).findAllTrades(std::atol(argv[2]), true);
    else 
        std::cerr << "incorrect number of commandline arguments\n";
    return 0;
} 
Example #2
0
void TMIDICue::Init()
{

	// Editor is closed
	fEditorOpen = false;

	// Set up default settings
	fIsLocked                       = false;
	fIsSelected             = false;
	fLowColor                       = kWhite;
	fHighColor              = kBlack;
	fIsPrepared             = false;
	fIsPlaying              = false;
	fIsVisible                      = false;
	fHasDuration            = true;
	fCanLoop                        = true;
	fCanStretch             = true;
	fCanEnvelope            = true;
	fHasEditor              = true;
	fCanWindow                      = true;
	fCanTransition          = false;
	fCanPath                        = false;

	// Default initialization
	TCueView::Init();

	// Create MIDIStore and MIDIEngine
	fMIDIStore = new BMidiStore();
	assert(fMIDIStore);
	fMIDIStore->Import(&fFileRef);
	fMIDIEngine = new TMIDIEngine(fMIDIStore);

	// Set cues fFile to point to the fMIDIFile
	fFile = fMIDIFile;

	// Calcaluate duration
	CalcDuration();

	// Adjust bounds based on cue duration
	int32 newWidth = TimeToPixels(fDuration, GetCurrentTimeFormat(), GetCurrentResolution());
	ResizeBy( newWidth - Bounds().Width(), 0);

	// Add the cue to the cue channel
	if ( fChannel->CanInsertCue(this, fInsertTime, true)) {
		fChannel->InsertCue(this, fInsertTime);
		Select();

		// We are now fully instantiated
		fIsInstantiated = true;
	}

	// Set expanded status
	if (fChannel->IsExpanded()) {
		fIsExpanded = false;
		Expand();
	} else {
		fIsExpanded = true;
		Contract();
	}
}
void TransposeAxpyContract
( T alpha, const ElementalMatrix<T>& A,
  ElementalMatrix<T>& B, bool conjugate )
{
    EL_DEBUG_CSE
    const Dist U = B.ColDist();
    const Dist V = B.RowDist();
    if( A.ColDist() == V && A.RowDist() == U )
    {
        TransposeAxpy( alpha, A, B, conjugate );
    }
    else if( (A.ColDist() == V && A.RowDist() == Partial(U)) ||
             (A.ColDist() == V && A.RowDist() == Collect(U)) ||
             (A.RowDist() == U && A.ColDist() == Partial(V)) ||
             (A.RowDist() == U && A.ColDist() == Collect(V)) )
    {
        unique_ptr<ElementalMatrix<T>>
                                    ASumFilt( B.ConstructTranspose(B.Grid(),B.Root()) );
        if( B.ColConstrained() )
            ASumFilt->AlignRowsWith( B, true );
        if( B.RowConstrained() )
            ASumFilt->AlignColsWith( B, true );
        Contract( A, *ASumFilt );
        if( !B.ColConstrained() )
            B.AlignColsWith( *ASumFilt, false );
        if( !B.RowConstrained() )
            B.AlignRowsWith( *ASumFilt, false );

        // We should have ensured that the alignments are compatible
        TransposeAxpy( alpha, ASumFilt->LockedMatrix(), B.Matrix(), conjugate );
    }
    else
        LogicError("Incompatible distributions");
}
void ClusterHierarchyBuilder::RunAlgorithm()
{
	Node *lastContraction = 0;
	while(mEdgesHeap.Peek())
	{
		Edge *edge = static_cast<Edge*>(mEdgesHeap.Peek());
		mEdgesHeap.Pop();
		
		// This edge is adjacent to two triangles. This vertex returns the missing
		// vertex for each triangle.
		
		int numNodes = 0;
		Node *nodes[4];
		nodes[numNodes++] = edge->mFrom;
		nodes[numNodes++] = edge->mTo;
		
/*		if(first close enough)
		{
			nodes[numNodes++] = adj.first;
		}
		
		if(second close enough)
		{
			nodes[numNodes++] = adj.second;
		}*/
		
		lastContraction = Contract(nodes,numNodes);
	}
	
	mRoot = lastContraction;
}
Example #5
0
void TransposeContract
( const BlockMatrix<T>& A,
        BlockMatrix<T>& B, bool conjugate )
{
    EL_DEBUG_CSE
    const Dist U = B.ColDist();
    const Dist V = B.RowDist();
    if( A.ColDist() == V && A.RowDist() == Partial(U) )
    {
        Transpose( A, B, conjugate );
    }
    else
    {
        unique_ptr<BlockMatrix<T>> 
            ASumFilt( B.ConstructTranspose(B.Grid(),B.Root()) );
        if( B.ColConstrained() )
            ASumFilt->AlignRowsWith( B, true );
        if( B.RowConstrained() )
            ASumFilt->AlignColsWith( B, true );
        Contract( A, *ASumFilt );
        if( !B.ColConstrained() )
            B.AlignColsWith( *ASumFilt, false );
        if( !B.RowConstrained() )
            B.AlignRowsWith( *ASumFilt, false );
        // We should have ensured that the alignments match
        B.Resize( A.Width(), A.Height() );
        Transpose( ASumFilt->LockedMatrix(), B.Matrix(), conjugate );
    }
}
void CTestHostlet::DescribeServiceL(CSenXmlServiceDescription& aSD) 
    { 
    if( ip2DescribeServiceL ) 
    	{
   		(*ip2DescribeServiceL)(aSD);
    	}
        else
            {
            aSD.SetEndPointL(Endpoint());
            aSD.SetContractL(Contract()); 
            aSD.SetFrameworkIdL(FrameworkId());	
            }
    }
Example #7
0
//******************************************************************************
//Name:     ScalProd                                                           *
//                                                                             *
//Purpose:  To calculate the Euclidean scalar product between two              *
//          one-dimensional tensors/arrays                                     *
//                                                                             *
//Takes:   const address of the desired tensors                                *
//******************************************************************************
double tensor::ScalProd(tensor const &A)
{
   double ret_val;


   if (  ( p->num_indices != 1 ) || ( A.p->num_indices != 1 ) )
      error("Vmag error:","only defined for vectors");

   ret_val =  Contract(A,0,0).Val(0);

   return ret_val;

}
Example #8
0
/*-------------------------------------------------------
	nClass번째 클래스에 속하는 박스에 대해 overlap 테스트해서 축소하는 함수

	pBox(입력) : 박스
	nClass(입력) : 클래스 번호(0부터 시작), pBox가 속한 클래스
-------------------------------------------------------*/
void CFMMNN::TestBox(MINMAX* pBox, int nClass)
{
	register MINMAX* p1 = pBox;

	for(register int i = 0; i < m_nClass; i ++)
	{
		if(i == nClass)
			continue;

		for(register int j = 0; j < m_nBox[i]; j ++)
		{
			register MINMAX* p2 = &m_pBox[i][j];
			register int nDir, nCase;
			if(TestOverlap(p1, p2, nDir, nCase))
				Contract(p1, p2, nDir, nCase);
		}
	}
}
//----------------------------------------------------------------------
box observer::SIVIA(box& X0,box& Psecours)	{
        int NbissectMax = N_Bissect_0;
	if (phase==0) NbissectMax=N_Bissect_0;
	if (phase==1) NbissectMax=N_Bissect_k;
	int Nbissect=0;
	Psecours = box(4);Psecours[1] = 5;Psecours[2] = 5;Psecours[3] = 0;Psecours[4] = 0;
	vector<box> Result;
	list<box> L;
	L.push_back(X0);
	box P;
	//Form1->R1.image->Refresh();
	while (!L.empty())	{
		P=L.front();
		//Form1->R1.DrawCadre(P,clBlue,psSolid,1,2,1);
		L.pop_front();
		bool sortie=false;
		while (!sortie)	{
			box Pold(P);
			Contract(P);
			if (P.IsEmpty()) sortie=true;
			if (decrease(Pold,P)<0.05) sortie=true;
		}
		if (!P.IsEmpty())	{
			if (Nbissect>NbissectMax)	{
				//Form1->R1.DrawBox(P,clRed,clRed,bsSolid,1,2);
				//Form1->R2.image->Refresh();
				Result.push_back(P);
			}
			else	{
				box P1,P2;
				Bisect(P,P1,P2);
                                Psecours=P;
				Nbissect++;
				L.push_back(P1);
				L.push_back(P2);
			}
		}
	}
	box R=Union(Result);
	//Form1->R1.DrawCadre(R,clGreen,psSolid,1,2,1);
	L.clear();

	return R;
}
Example #10
0
void SUMMA_NTB
( Orientation orientB,
  T alpha,
  const AbstractDistMatrix<T>& APre,
  const AbstractDistMatrix<T>& BPre,
        AbstractDistMatrix<T>& CPre )
{
    EL_DEBUG_CSE
    const Int m = CPre.Height();
    const Int bsize = Blocksize();
    const Grid& g = APre.Grid();

    DistMatrixReadProxy<T,T,MC,MR> AProx( APre );
    DistMatrixReadProxy<T,T,MC,MR> BProx( BPre );
    DistMatrixReadWriteProxy<T,T,MC,MR> CProx( CPre );
    auto& A = AProx.GetLocked();
    auto& B = BProx.GetLocked();
    auto& C = CProx.Get();

    // Temporary distributions
    DistMatrix<T,MR,STAR> A1Trans_MR_STAR(g);
    DistMatrix<T,STAR,MC> D1_STAR_MC(g);
    DistMatrix<T,MR,MC> D1_MR_MC(g);

    A1Trans_MR_STAR.AlignWith( B );
    D1_STAR_MC.AlignWith( B );

    for( Int k=0; k<m; k+=bsize )
    {
        const Int nb = Min(bsize,m-k);
        auto A1 = A( IR(k,k+nb), ALL );
        auto C1 = C( IR(k,k+nb), ALL );

        // D1[*,MC] := alpha A1[*,MR] (B[MC,MR])^T
        //           = alpha (A1^T)[MR,*] (B^T)[MR,MC]
        Transpose( A1, A1Trans_MR_STAR );
        LocalGemm( TRANSPOSE, orientB, alpha, A1Trans_MR_STAR, B, D1_STAR_MC );

        // C1[MC,MR] += scattered & transposed D1[*,MC] summed over grid rows
        Contract( D1_STAR_MC, D1_MR_MC );
        Axpy( T(1), D1_MR_MC, C1 );
    }
}
Example #11
0
void SUMMA_TNA
( Orientation orientA,
  T alpha,
  const AbstractDistMatrix<T>& APre,
  const AbstractDistMatrix<T>& BPre,
        AbstractDistMatrix<T>& CPre )
{
    DEBUG_CSE
    const Int n = CPre.Width();
    const Int bsize = Blocksize();
    const Grid& g = APre.Grid();

    DistMatrixReadProxy<T,T,MC,MR> AProx( APre );
    DistMatrixReadProxy<T,T,MC,MR> BProx( BPre );
    DistMatrixReadWriteProxy<T,T,MC,MR> CProx( CPre );
    auto& A = AProx.GetLocked();
    auto& B = BProx.GetLocked();
    auto& C = CProx.Get();

    // Temporary distributions
    DistMatrix<T,MC,STAR> B1_MC_STAR(g);
    DistMatrix<T,MR,STAR> D1_MR_STAR(g);
    DistMatrix<T,MR,MC  > D1_MR_MC(g);

    B1_MC_STAR.AlignWith( A );
    D1_MR_STAR.AlignWith( A );

    for( Int k=0; k<n; k+=bsize )
    {
        const Int nb = Min(bsize,n-k);
        auto B1 = B( ALL, IR(k,k+nb) );
        auto C1 = C( ALL, IR(k,k+nb) );

        // D1[MR,*] := alpha (A1[MC,MR])^T B1[MC,*]
        //           = alpha (A1^T)[MR,MC] B1[MC,*]
        B1_MC_STAR = B1; 
        LocalGemm( orientA, NORMAL, alpha, A, B1_MC_STAR, D1_MR_STAR );

        // C1[MC,MR] += scattered & transposed D1[MR,*] summed over grid cols
        Contract( D1_MR_STAR, D1_MR_MC );
        Axpy( T(1), D1_MR_MC, C1 );
    }
}
Example #12
0
void KernelHeap::Free(void *p)
{
	// Exit gracefully for null pointers.
	if (p == 0)
		return;

	// Get the header and footer associated with this pointer.
	header_t *header = (header_t*) ( (DWORD)p - sizeof(header_t) );
	footer_t *footer = (footer_t*) ( (DWORD)header + header->size - sizeof(footer_t) );

	// Sanity checks.
	//ASSERT(header->magic == HEAP_MAGIC);
	//ASSERT(footer->magic == HEAP_MAGIC); 

	// Make us a hole.
	header->is_hole = 1;

	// Do we want to add this header into the 'free holes' index?
	char do_add = 1; 

	// Unify left
	// If the thing immediately to the left of us is a footer...
	footer_t *test_footer = (footer_t*) ( (DWORD)header - sizeof(footer_t) );
	if (test_footer->magic == HEAP_MAGIC_FOOT &&
		test_footer->header->is_hole == 1)
	{
		DWORD cache_size = header->size; // Cache our current size.
		header = test_footer->header;     // Rewrite our header with the new one.
		footer->header = header;          // Rewrite our footer to point to the new header.
		header->size += cache_size;       // Change the size.
		do_add = 0;                       // Since this header is already in the index, we don't want to add it again.
	} 

	// Unify right
	// If the thing immediately to the right of us is a header...
	header_t *test_header = (header_t*) ( (DWORD)footer + sizeof(footer_t) );
	if (test_header->magic == HEAP_MAGIC_HEAD &&
		test_header->is_hole)
	{
		header->size += test_header->size; // Increase our size.
		test_footer = (footer_t*) ( (DWORD)test_header + // Rewrite it's footer to point to our header.
										test_header->size - sizeof(footer_t) );
		footer = test_footer;
		// Find and remove this header from the index.
		DWORD iterator = 0;
		while ( (iterator < m_index->Size()) &&
			(m_index->Lookup(iterator) != test_header) )
				iterator++;

		// Make sure we actually found the item.
		//ASSERT(iterator < heap->index.size);
		// Remove it.
		m_index->Remove(iterator);
	} 

	// If the footer location is the end address, we can contract.
	if ( (DWORD)footer+sizeof(footer_t) == m_end_address)
	{
		DWORD old_length = m_end_address - m_start_address;
		DWORD new_length = Contract( (DWORD)header - m_start_address);
		// Check how big we will be after resizing.
		if (header->size - (old_length - new_length) > 0)
		{
			// We will still exist, so resize us.
			header->size -= old_length-new_length;
			footer = (footer_t*) ( (DWORD)header + header->size - sizeof(footer_t) );
			footer->magic = HEAP_MAGIC_FOOT;
			footer->header = header;
		}
		else
		{
			// We will no longer exist :(. Remove us from the index.
			DWORD iterator = 0;
			while ( (iterator < m_index->Size()) &&
				(m_index->Lookup(iterator) != test_header) )
					iterator++;
			// If we didn't find ourselves, we have nothing to remove.
			if (iterator < m_index->Size())
				m_index->Remove(iterator);
		}
	}

	if (do_add == 1)
		m_index->Insert(header);
}