예제 #1
0
bool findArgument(int s)
{
	bool ret = 0;
	memset(tag, 0, sizeof(tag));
	memset(fa, 0, sizeof(fa));
	for (int i = 1; i <= n; i++) f[i] = i;
	queue<int> q;
	q.push(s);
	tag[s] = S;
	while (!q.empty())
	{
		int u = q.front(); q.pop();
		for (int v = 1; v <= n; v++) if (G[u][v] && v != matched[u] && find(u) != find(v) && tag[v] != T)
		{
			if (tag[v] == S) // meet a S node
			{
				int p = findLCA(u, v);
				// important
				if (find(u) != p) fa[u] = v;
				if (find(v) != p) fa[v] = u;
				// important order 
				contract(u, p, q);
				contract(v, p, q);
			}
			else if (!matched[v]) // find a free node
			{
				argument(u, v);
				return 1;
			}
			else // find a matched node
				expand(u, v, q);
		}
	}
	return 0;
}
예제 #2
0
 long numCol(const Graph & g)
 {
     long n = order(g);
     if (n == 1 || minDegree(g) == n-1)
     {
         return 1;
     }
     typedef std::pair<vertex_iter, vertex_iter> p_vertex_iter;
     vertex u,v;
     bool nonEdgeFound = false;
     for (p_vertex_iter vp = vertices(g); vp.first != vp.second && !nonEdgeFound; ++vp.first)
     {
         for (vertex_iter w = vp.first+1; w != vp.second && !nonEdgeFound; ++w)
         {
             if (!edge(*vp.first, *w, g).second)
             {
                 u = *vp.first;
                 v = *w;
                 nonEdgeFound = true;
             }
         }
     }
     Graph g1 = contract(u, v, g);
     long num = numCol(g1);
     Graph g2(g);
     add_edge(u,v,g2);
     num += numCol(g2);
     return num;
 }
예제 #3
0
SubPaving* Paver::pave(const IntervalVector& init_box) {

	SubPaving* paving=new SubPaving[ctc.size()];

	buffer.flush();

	Cell* root=new Cell(init_box);

	// add data required by the contractors
//	for (int i=0; i<ctc.size(); i++) {
//		ctc[i].init_root(*root);
//	}
	// add data required by the bisector
	bsc.add_backtrackable(*root);

	buffer.push(root);

	while (!buffer.empty()) {
		Cell* c=buffer.top();

		if (trace) cout << buffer << endl;

		contract(*c, paving);

		Timer::check(timeout);
		check_capacity(paving);

		if (c->box.is_empty()) delete buffer.pop();
		else bisect(*c);
	}

	return paving;
}
예제 #4
0
template <> bool DataOutputNode<lbfloat>::mat_write(std::string file_path, std::string var_name)
{
    //Copy data to buffer
    lbfloat* buf = nullptr;
    size_t buf_size;
    contract(buf,buf_size,false);

    std::cout << "Output matrix will be [" << _n_samples << "] x [" << _n_channels << "]." << std::endl;

    //setup the output
    mat_t *mat;
    matvar_t *matvar;
    size_t dims[2] = {_n_samples,_n_channels};

    mat = Mat_Open(file_path.c_str(),MAT_ACC_RDWR);
    if(mat)
    {
        //output matrix
        matvar = Mat_VarCreate(var_name.c_str(),MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,buf,0);
        Mat_VarWrite(mat, matvar, MAT_COMPRESSION_NONE);
        Mat_Close(mat);
        Mat_VarFree(matvar);
        std::cout << "Output data to " << var_name << " variable in file " << file_path << "!" << std::endl;
        delete [] buf;
        return true;
    }
    std::cerr << "Couldn't output to file." << std::endl;
    delete [] buf;
    return false;
}
예제 #5
0
template <> bool DataOutputNode<lbfloat>::dat_write(std::string file_path)
{
    //Copy data to buffer
    lbfloat* buf = nullptr;
    size_t buf_size;
    contract(buf,buf_size,false);

    std::cout << "Output matrix will be [" << _n_samples << "] x [" << _n_channels << "]." << std::endl;

    //setup the output
    std::ofstream ofs;
    ofs.open(file_path.c_str());

    for(size_t sa=0; sa<_n_samples; ++sa)
    {
        for(size_t ch=0; ch<_n_channels; ++ch)
        {
            ofs << buf[ch*_n_samples+sa] << "\t";
        }
        ofs << std::endl;
    }

    ofs.close();
    std::cout << "Output data to file " << file_path << "!" << std::endl;
    delete [] buf;
    return true;
}
void path(int st){
  Q.clear();
  for(int i=0;i<=n;i++) fa[i] = i, inQ[i] = typ[i] = frm[i] = 0;
  typ[st] = inQ[st] = 1; Q.pb(st);
  while(sz(Q)){
    int u = Q.front(); Q.pop_front(); inQ[u] = 0;
    for(int i=0;i<sz(E[u]);i++){
      int v = E[u][i];
      if(v != wife[u] && rt(u)!=rt(v) && typ[v]!=2){
        if(typ[v]==1) contract(u, v);
        else if(!wife[v]){
          frm[v] = u;
          for(int tv = v, tu = frm[tv], chW; tu && tv; tv = chW, tu = frm[tv]){
            chW = wife[tu];
            wife[tu] = tv, wife[tv] = tu;
            wife[chW] = 0;
          }
          return ;
        }else{
          frm[v] = u, typ[v] = 2;
          inQ[wife[v]] = typ[wife[v]] = 1; Q.pb(wife[v]);
        }
      }
    }
  }
}
예제 #7
0
void srcfss(stack *st, value cur) {

	#ifdef TREEDOT
	st->id = count;
	printf("ID = %zu\n", st->id);
	if (st->id) fprintf(st->dot, "\t%zu -> %zu;\n", (st - 1)->id, st->id);
	printcs(st);
	#endif
	count++;

	if (cur < min) { min = cur; sol = *st; }

	#ifdef LIMIT
	if (!stop) {
		gettimeofday(&t2, NULL);
		if ((double)(t2.tv_usec - t1.tv_usec) / 1e6 + t2.tv_sec - t1.tv_sec > LIMIT) stop = true;
	}
	#ifndef COMPLETEFRONTIER
	else return;
	#endif
	#endif

	#ifdef BOUND
	const value b = bound(st);
	#ifdef LIMIT
	if (stop) { if (b < bou) bou = b; return; }
	else
	#endif
	if (b >= min - MINGAIN) return;
	#endif

	chunk tmp[C], rt[C];
	memcpy(tmp, st->c, sizeof(chunk) * C);
	MASKAND(tmp, st->r, tmp, C);
	edge popc = MASKPOPCNT(tmp, C);

	for (edge i = 0, e = MASKFFS(tmp, C); !stop && i < popc; i++, e = MASKCLEARANDFFS(tmp, e, C)) {

		agent v1 = X(st->a, e);
		agent v2 = Y(st->a, e);

		// At least one of the two coalitions must be a car
		if (!(st->dr[v1] + st->dr[v2])) continue;

		memcpy(rt, st->r, sizeof(chunk) * C);
		CLEAR(st->r, st->g[v1 * N + v2]);
		CLEAR(tmp, st->g[v1 * N + v2]);

		// Must not exceed the number of seats and the maximum number of drivers
		if (X(st->s, v1) + X(st->s, v2) > K || st->dr[v1] + st->dr[v2] > MAXDRIVERS) continue;

		CLEAR(st->c, st->g[v1 * N + v2]);
		st[1] = st[0];
		memcpy(st[1].r, rt, sizeof(chunk) * C);
		merge(st + 1, v1, v2);
		contract(st + 1, v1, v2);
		st[1].l[v1] = minpath(st[1].cs + Y(st[1].s, v1), X(st[1].s, v1), st[1].dr[v1], st->sp);
		srcfss(st + 1, cur + COST(v1, st[1].dr, st[1].l) - COST(v1, st->dr, st->l) - COST(v2, st->dr, st->l));
	}
}
예제 #8
0
bool PeerRequest::validate(const Lock& lock) const
{
    bool validNym = false;

    if (nym_) {
        validNym = nym_->VerifyPseudonym();
    } else {
        otErr << __FUNCTION__ << ": invalid nym." << std::endl;
    }

    const bool validSyntax = proto::Validate(contract(lock), VERBOSE);

    if (!validSyntax) {
        otErr << __FUNCTION__ << ": invalid syntax." << std::endl;
    }

    if (1 > signatures_.size()) {
        otErr << __FUNCTION__ << ": Missing signature." << std::endl;

        return false;
    }

    bool validSig = false;
    auto& signature = *signatures_.cbegin();

    if (signature) { validSig = verify_signature(lock, *signature); }

    if (!validSig) {
        otErr << __FUNCTION__ << ": invalid signature." << std::endl;
    }

    return (validNym && validSyntax && validSig);
}
예제 #9
0
Sprite *Sprite::backShow(bool fast) {
	expand();
	show(2);
	show(1);
	if (fast)
		show(0);
	contract();
	return this;
}
예제 #10
0
void contract(
   const _T& alpha,
   const TArray<_T, L, Q>& A, const std::string& labelA,
   const TArray<_T, M, Q>& B, const std::string& labelB,
   const _T& beta,
         TArray<_T, N, Q>& C, const std::string& labelC)
{
   contract(alpha, A, Index<L>(labelA), B, Index<M>(labelB), beta, C, Index<N>(labelC));
}
예제 #11
0
void contractor_ibex_fwdbwd::prune(contractor_status & cs) {
    DREAL_LOG_DEBUG << "contractor_ibex_fwdbwd::prune";
    auto ctc = get_ctc(std::this_thread::get_id(), true);
    if (!ctc) {
        return;
    }

    DREAL_THREAD_LOCAL static box old_box(cs.m_box);
    if (cs.m_config.nra_proof) {
        old_box = cs.m_box;
    }
    if (m_numctr->f.nb_arg() == 0) {
        auto eval_result = m_ctr->eval(cs.m_box);
        if (eval_result.first == l_False) {
            cs.m_box.set_empty();
            return;
        } else {
            return;
        }
    }
    DREAL_THREAD_LOCAL static ibex::IntervalVector old_iv(cs.m_box.get_values());
    old_iv = cs.m_box.get_values();
    assert(m_numctr->f.nb_arg() >= 0 &&
           static_cast<unsigned>(m_numctr->f.nb_arg()) <= cs.m_box.size());
    DREAL_LOG_DEBUG << "Before pruning using ibex_fwdbwd(" << *m_numctr << ")";
    DREAL_LOG_DEBUG << cs.m_box;
    DREAL_LOG_DEBUG << "ibex interval = " << cs.m_box.get_values() << " (before)";
    DREAL_LOG_DEBUG << "function = " << ctc->f;
    DREAL_LOG_DEBUG << "domain   = " << ctc->d;
    ctc->contract(cs.m_box.get_values());
    DREAL_LOG_DEBUG << "ibex interval = " << cs.m_box.get_values() << " (after)";
    // cerr << output.empty() << used_constraints.empty() << " ";
    auto & new_iv = cs.m_box.get_values();
    bool changed = false;
    for (unsigned i = 0; i < cs.m_box.size(); ++i) {
        if (get_input().contain(i) && old_iv[i] != new_iv[i]) {
            cs.m_output.add(i);
            changed = true;
        }
    }
    if (changed || cs.m_box.is_empty()) {
        // only add used_constraints if there is any change
        cs.m_used_constraints.insert(m_ctr);
    }
    DREAL_LOG_DEBUG << "After pruning using ibex_fwdbwd(" << *m_numctr << ")";
    DREAL_LOG_DEBUG << cs.m_box;
    if (cs.m_config.nra_proof) {
        // ======= Proof =======
        DREAL_THREAD_LOCAL static ostringstream ss;
        Enode const * const e = m_ctr->get_enode();
        ss << (e->getPolarity() == l_False ? "!" : "") << e;
        output_pruning_step(old_box, cs, ss.str());
        ss.str(string());
    }
    return;
}
예제 #12
0
파일: strict.cpp 프로젝트: Mesh89/FACT
tree strictConsensus(){
	//Initialising T[0]
	T[0].precompute();
	for(int i=1;i<=T[0].N;++i) T[0].good[i] = (T[0].H[i] >= 0);
	//Determining which nodes in T[0] exist in all the trees. These nodes will form the strict consensus tree
	for(int i=1;i<numTrees;++i) days(T[0],T[i]);
	//Contract the tree so that it only contains vertices identified in the previous step
	tree ret = contract(T[0]);
	return ret;
}
예제 #13
0
bool isModelExist(string model){
  ifstream contract("data.contract");
  string line;
  while(getline(contract,line)){
    if (strstr(line.c_str(),model.c_str())){
      //cout << "Found the Model" << endl;
      return true;
    }
  }
  return true;
}
예제 #14
0
void CDlgAccount::updatePortfolio(IDispatch* dispContract, int position,
								  double marketPrice, double marketValue,
								  double averageCost, double unrealizedPNL,
								  double realizedPNL, const CString& accountName)
{
	CComQIPtr<IContract> contract(dispContract);

	if (!contract) {
		return;
	}

	int     conId;
	CString symbol;
	CString secType;
	CString expiry;
	double strike;
	CString right;
	CString multiplier;
	CString primaryExchange;
	CString currency;
	CString localSymbol;
	CString tradingClass;

	typedef CComPropAccessor<IContract> Props;

#define GET_PROP(Prop) \
	Props::Get(Prop, contract, &IContract::get_##Prop);

	GET_PROP(conId);
	GET_PROP(symbol);
	GET_PROP(secType);
	GET_PROP(expiry);
	GET_PROP(strike);
	GET_PROP(right);
	GET_PROP(multiplier);
	GET_PROP(primaryExchange);
	GET_PROP(currency);
	GET_PROP(localSymbol);
	GET_PROP(tradingClass);

#undef GET_PROP

    CString str;
	str.Format( "conId=%i symbol=%s  secType=%s  expiry=%s  strike=%f right=%s multiplier=%s primaryExchange=%s currency=%s localSymbol=%s tradingClass=%s"
		" position=%i mktPrice=%f mktValue=%f averageCost=%f unrealizedPNL=%f realizedPNL=%f account name=%s",
		conId, (const char *)symbol, (const char *)secType, (const char *)expiry, strike, (const char *)right,
		(const char*)multiplier, (const char*)primaryExchange, (const char *)currency, (const char *)localSymbol, (const char *)tradingClass,
		position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL,
		accountName);

    if ( m_portfolio.m_hWnd != NULL ) {
	    m_portfolio.InsertString(0, str);
    }
}
예제 #15
0
 void PretzelColorPicker::mouseDown(const ci::vec2 &pos){
     if( !bExpanded && mCollapsedRect.contains( pos - mOffset ) ){
         expand();
     }else if(bExpanded && mCollapsedRect.contains( pos - mOffset )){
         contract();
     }else if( bExpanded && mColorSwatchRect.contains(pos - mOffset)){
         bDragging = true;
     }else if( bExpanded && mHueStripRect.contains(pos - mOffset) ){
         bDraggingHue = true;
     }
 }
SystemObject* VectorSysObj::remove(ID id){
	if(vector[id] == NULL)
		return NULL;
	SystemObject *temp = vector[id];
	ocupied--;
	vector[id] = NULL;
	lastOcupiedID = getLastOcupiedID();
	if(shouldContract())
		contract();
	return temp;
}
예제 #17
0
void* pop(List* p_List,int index)
{ // Elimina de la lista el elemento index y retorna su referencia
	void* returnAux;
	if (p_List->size > index)
	{
		returnAux = p_List->pElements[index];
		contract(p_List, index);
		p_List->size--;
		return returnAux;
	}
	return NULL;
}
예제 #18
0
bool isMakeExist(string make){
  ifstream contract("data.contract");
  string line;
  while(getline(contract,line)){
    if (strstr(line.c_str(),make.c_str())){
      //cout << "Found the Make" << endl;
      return true;
    }
  }

  return false;
}
예제 #19
0
/** \brief  Remove an element by index
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (-1) if Error [pList is NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int al_remove(ArrayList* pList,int index)
{
    int returnAux = -1;

    if(pList != NULL && index >= 0 && index < pList->size)
    {
       // *((pList->pElements)+index)  = NULL;
       contract(pList,index);
      //  pList->size = pList->size -1;
        returnAux = 0;
    }

    return returnAux;
}
예제 #20
0
//----------------------------------------------------------------------------------------------------------------
void CtcPixelMap::contract(IntervalVector& box) {

    assert(box.size() == I.ndim);
    if(box.is_empty()) return;

    // Convert world coordinates into pixel coordinates
    world_to_grid(box);

    // Contractor the box
    if( I.ndim == 2) {
        contract(pixel_coords[0],pixel_coords[1],pixel_coords[2],pixel_coords[3]);
    } else if ( I.ndim == 3){
        contract(pixel_coords[0],pixel_coords[1],pixel_coords[2],pixel_coords[3],pixel_coords[4],pixel_coords[5]);        
    }
    // Check the result
    if(pixel_coords[0] == -1) {
        box.set_empty();
        return;
    }

    // Convert pixel coordinates into world coordinates
    grid_to_world(box);
}
예제 #21
0
파일: Hash.cpp 프로젝트: myucel/cashlib
hash_t Hash::hash(const char* data, size_t len,
                  const alg_t alg, const string &key, const int hashType)
{
	if (hashType == Hash::TYPE_PLAIN) {
		return hash(data, len, alg, key);
	} else if (hashType == Hash::TYPE_MERKLE) {
		MerkleContract contract(key, alg);
		MerkleTree tree(data, len, contract);
		return tree.getRoot();
	} else {
		throw CashException(CashException::CE_HASH_ERROR,
							"[Hash::hash] Unknown hash type used");
	}
}
예제 #22
0
파일: SliceSampler.cpp 프로젝트: cran/Boom
 Vector SliceSampler::draw(const Vector &theta) {
   last_position_ = theta;
   initialize();
   find_limits();
   Vector candidate;
   double logp_candidate = log_p_slice_ - 1;
   do {
     double lambda = runif_mt(rng(), -lo_, hi_);
     candidate = last_position_ + lambda * random_direction_;
     logp_candidate = logp_(candidate);
     if (logp_candidate < log_p_slice_) contract(lambda, logp_candidate);
   } while (logp_candidate < log_p_slice_);
   scale_ = hi_ + lo_;  // both hi_ and lo_ > 0
   return candidate;
 }
예제 #23
0
static void right_shift( huge *h1 )
{
  int i;
  unsigned int old_carry, carry = 0;

  i = 0;
  do
  {
    old_carry = carry;
    carry = ( h1->rep[ i ] & 0x01 ) << 7;
    h1->rep[ i ] = ( h1->rep[ i ] >> 1 ) | old_carry;
  }
  while ( ++i < h1->size );

  contract( h1 );
}
예제 #24
0
/** \brief  Remove an element by index
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (-1) if Error [pList is NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int al_remove(ArrayList* pList,int index)
{
    int returnAux = -1;
    int i;
    if (pList!=NULL &&  index >=0 && index<pList->size)
    {
//        for (i=index; i<pList->size; i++)
//        {
//            *((pList->pElements)+index)=*((pList->pElements)+index+1);
//        }
        contract(pList,index);
//        pList->size--;
        returnAux=0;
    }
    return returnAux;
}
예제 #25
0
/** \brief Remove the item at the given position in the list, and return it.
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (NULL) if Error [pList is NULL pointer or invalid index]
 *                  - ( element pointer) if Ok
 */
void* al_pop(ArrayList* pList,int index)
{
    void* returnAux = NULL;


    if(pList != NULL && index>=0 && index <= pList->size)
    {
        //returnAux = malloc(sizeof(void *));
        returnAux = pList->get(pList,index);
        //pList->remove(pList,index);
        contract(pList,index);

    }

    return returnAux;
}
예제 #26
0
/** \brief  Remove an element by index
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (-1) if Error [pList is NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int al_remove(ArrayList* pList,int index)
{
    int returnAux = -1;

    if(pList != NULL && index >= 0 && index < pList->len(pList))
    {
       pList->pElements[index] = NULL;// HAY QUE HACER ESTO?

       contract(pList,index);

       pList->size = pList->size - 1;
       returnAux = 0;
    }

    return returnAux;
}
예제 #27
0
	int TWS_TLWM::SendOrder(TLOrder o)
	{
		// check our order
		if (!o.isValid()) return GOTNULLORDER;
		if (o.symbol=="") return UNKNOWNSYM;

		// create broker-specific objects here
		Order* order(new Order);
		order->auxPrice = o.stop;
		order->lmtPrice = o.price;
		order->orderType = (o.stop!=0) ? "STP" : (o.price!=0 ? "LMT" : "MKT");
		order->totalQuantity = (long)o.size;
		order->action = (o.side) ? "BUY" : "SELL";
		order->account = o.account;
		order->tif = o.TIF;
		order->outsideRth = true;
		if (o.id!=0) // if ID is provided, keep it
			order->orderId = o.id;
		else // otherwise just get the next id
			order->orderId = getNextOrderId(o.account);
		order->transmit = true;

		Contract* contract(new Contract);
		contract->symbol = o.symbol;
		contract->localSymbol = o.localsymbol;
		if (o.exchange=="")
			o.exchange = "SMART";
		contract->exchange = o.exchange;
		contract->secType = o.security;
		contract->currency = o.currency;

		// get the TWS session associated with our account
		EClient* client;
		if (o.account=="") // if no account specified, get default
			client = m_link[this->validlinkids[0]];
		else // otherwise get the session our account is logged into
			client	= GetOrderSink(o.account);

		// place our order
		if (client!=NULL)
			client->placeOrder(order->orderId,*contract,*order);

		delete order;
		delete contract;

		return OK;
	}
예제 #28
0
	int TWS_TLServer::SendOrder(TLOrder o)
	{
		// check our order
		if (o.symbol=="") return UNKNOWN_SYMBOL;
		if (!o.isValid()) return INVALID_ORDERSIZE;


		// create broker-specific objects here
		Order* order(new Order);
		order->auxPrice = o.isTrail() ? o.trail : o.stop;
		order->lmtPrice = o.price;
		order->orderType = (o.isStop()) ? "STP" : (o.isLimit() ? "LMT" : (o.isTrail() ? "TRAIL" : "MKT"));
		order->totalQuantity = (long)o.size;
		order->action = (o.side) ? "BUY" : "SELL";
		order->account = o.account;
		order->tif = o.TIF;
		order->outsideRth = true;
		order->orderId = newOrder(o.id,o.account);
		order->transmit = true;

		Contract* contract(new Contract);
		contract->symbol = o.symbol;
		contract->localSymbol = o.localsymbol!="" ? o.localsymbol : o.symbol;
		if (o.exchange=="")
			o.exchange = "SMART";
		contract->exchange = o.exchange;
		contract->secType = o.security;
		contract->currency = o.currency;

		// get the TWS session associated with our account
		EClient* client;
		if (o.account=="") // if no account specified, get default
			client = m_link[this->validlinkids[0]];
		else // otherwise get the session our account is logged into
			client	= GetOrderSink(o.account);

		// place our order
		if (client!=NULL)
			client->placeOrder(order->orderId,*contract,*order);

		delete order;
		delete contract;

		return OK;
	}
예제 #29
0
void ImplAAFTypeDefCharacter::externalize(const OMByte* internalBytes,
                                 OMUInt32 ANAME(internalBytesSize),
                                 OMByte* externalBytes,
                                 OMUInt32 externalBytesSize,
                                 OMByteOrder byteOrder) const
{
  TRACE("ImplAAFTypeDefCharacter::externalize");
  PRECONDITION("Valid internal bytes", internalBytes != 0);
  PRECONDITION("Valid internal bytes size",
          internalBytesSize >= internalSize(externalBytes, externalBytesSize));
  PRECONDITION("Valid external bytes", externalBytes != 0);
  PRECONDITION("Valid external bytes size",
          externalBytesSize >= externalSize(internalBytes, internalBytesSize));

  if (sizeof(aafCharacter) == kExternalCharacterSize)
    copy(internalBytes, externalBytes, externalBytesSize);
  else
    contract(internalBytes, sizeof(aafCharacter), externalBytes, kExternalCharacterSize, byteOrder);
}
예제 #30
0
template <> bool DataOutputNode<lbcomplex>::mat_write(std::string file_path, std::string var_name)
{
    //Copy data to buffer
    lbcomplex* buf = nullptr;

    size_t buf_size;
    contract(buf,buf_size,false);

    std::cout << "Output matrix will be [" << _n_samples << "] x [" << _n_channels << "]." << std::endl;

    //setup the output
    mat_t *mat;
    matvar_t *matvar;
    mat_complex_split_t data;

    data.Re = malloc(buf_size*sizeof(lbfloat));
    data.Im = malloc(buf_size*sizeof(lbfloat));

    for(size_t ii=0; ii<buf_size; ++ii)
    {
        reinterpret_cast<lbfloat*>(data.Re)[ii] = std::real(buf[ii]);
        reinterpret_cast<lbfloat*>(data.Im)[ii] = std::imag(buf[ii]);
    }

    size_t dims[2] = {_n_samples,_n_channels};

    mat = Mat_Open(file_path.c_str(),MAT_ACC_RDWR);
    if(mat)
    {
        //output matrix
        matvar = Mat_VarCreate(var_name.c_str(),MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,&data,MAT_F_COMPLEX);
        Mat_VarWrite(mat, matvar, MAT_COMPRESSION_NONE);
        Mat_Close(mat);
        Mat_VarFree(matvar);
        std::cout << "Output data to " << var_name << " variable in file " << file_path << "!" << std::endl;
        delete [] buf;
        return true;
    }
    std::cerr << "Couldn't output to file." << std::endl;
    delete [] buf;
    return false;
}