TEST(SparseMatrixSpecialValues, Z3determined)
{
	typedef FiniteFieldParam<ZPlusRing32>::Module<3> Param;
	Param::Matrix m;
	const auto E = m.ElementConstructor();
	{//1x1 non-identity
		m.Clear();
		m.AddRow();
		m.AddElement(0, 2u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 2u)}));
	}
	{//first column is fixed by others with different coef relations
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(0, 2u);
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
	 	m.AddElement(2, 2u);
	 	m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(3, 1u);
	 	m.AddRow();
		m.AddElement(0, 2u);
		m.AddElement(4, 2u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(1, 1u), E(2, 1u), E(3, 2u), E(4, 2u)}));
	}
}
예제 #2
0
static int tfNetSemGive(integer4 *isp1,
			integer8 *kx,
			integer4 *irtc) {
  integer8 ia;
  real8 vx;
  int status, semaphore;

  if(isp != *isp1 + 2) {
    *irtc = itfmessage(9, "General::narg", "\"2\"");
    return -1;
  }

  if(ktfnonstringq(ktastk( *isp1 + 1))) {
    *irtc = itfmessage(9, "General::wrongtype", "\"Character-string for #1\"");
    return -1;
  }

  if(ktfnonrealq(ktastk( isp))) {
    *irtc = itfmessage(9, "General::wrongtype", "\"Real Number for #2\"");
    return -1;
  }

  ia = ktfaddr(ktastk(*isp1 + 1));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif
  semaphore = rtastk( isp);

  status = netSemGive(&jlist(1, ia + 1), semaphore);

  vx  = status;
  *kx = kfromr(vx);
  *irtc = 0;
  return 0;
}
예제 #3
0
파일: tfPyInter_.c 프로젝트: KatsOide/SAD
/* SADScript function definition of PyInter stuff */
int tfPyEvalString(integer4 *isp1,
		   integer4 *kx,
		   integer4 *irtc) {
  integer8 ia;
  char *argv = argv0;

  if(!initialized) { /* Initialize the Python interpreter if required. */
    initialized = 1;
    Py_Initialize();
    PySys_SetArgv(1, &argv);
  }

  if(isp != *isp1 + 1) {
    *irtc = itfmessage(9, "General::narg", "\"1\"");
    return -1;
  }

  if((ktfmask & ktastk(isp)) != ktfstring) {
    *irtc = itfmessage(9, "General::wrongtype", "\"Character-string\"");
    return -1;
  }

  ia = (ktamask & ktastk(isp));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif

  /* Execute some Python statements (in module __main__) */
  PyRun_SimpleString(&jlist(1, ia + 1));
  *kx = ktfoper + mtfnull;
  *irtc = 0;
  return 0;
}
예제 #4
0
void interpret( INSTRUCTION *start_adr, INSTRUCTION *end_adr )
{
jmp_buf my_env;
jmp_buf *sav_envp0 = envp0;
/*   return; <<< */
   ins_ptr = start_adr;
   if( setjmp( my_env ) != 0 ) {
      /* a jump has occurred from an inner block.
      ** if its destination is outside this block,
      ** jump to the next outer block
      */
      if( ( ins_ptr < start_adr ) || ( ins_ptr > end_adr ) ) {
         iprintf(( "jump out of block\n" ));
         assert( sav_envp0 != NULL ); /* illegal if outermost block */
         longjmp( *sav_envp0, 1 );
      } /* if */
   } /* if */
   envp0 = &my_env;

   assert( ins_ptr <= end_adr );
   while( ins_ptr < end_adr ) {	/* don't execute end instruction */
      if(!LISTING) {
        ibug();
        (*ifunc[*ins_ptr++])();
      }
      else {
         ins_ptr = ilist( ins_ptr );
	 putchar( '\n' );
      } /* if */
   } /* while */
   envp0 = sav_envp0;
} /* interpret() */
예제 #5
0
int main() 
{
	int ia[] =  { 0,1,1,2,3,5,8,13 };
	int ia2[] = { 0,1,1,2,4,6,10   };
		
	pair<int*,int*> pair_ia = mismatch( ia, ia+7, ia2 );

// generates: first mismatched pair: ia: 3 and ia2: 4

        cout << "first mismatched pair: ia: "
	     << *pair_ia.first << " and ia2: "
             << *pair_ia.second << endl;
		
	list<int,allocator> ilist(  ia,  ia+7  );
	list<int,allocator> ilist2( ia2, ia2+7 );
		
	typedef list<int,allocator>::iterator iter;
	pair<iter,iter> pair_ilist =
		mismatch( ilist.begin(),  ilist.end(),
			  ilist2.begin(), equal_and_odd() );
		
// generates: first mismatched pair either not equal or not odd: 
//                  ilist: 2 and ilist2: 2

        cout << "first mismatched pair either not equal or not odd: \n\tilist: "
	     << *pair_ilist.first << " and ilist2: "
	     << *pair_ilist.second << endl;
		
	return 0;
}
예제 #6
0
파일: alg1.C 프로젝트: jiayuehua/cpp-primer
int main()
{
	int ia[] = { 1, 1, 2, 3, 5, 8 };

	list<int,allocator> ilist(ia, ia+6);
	list<int,allocator> ilist_result(ilist.size());


	adjacent_difference(ilist.begin(), ilist.end(), 
			    ilist_result.begin() );
		
	// generates output: 1 0 1 1 2 3 
	copy( ilist_result.begin(), ilist_result.end(),
	      ostream_iterator<int>(cout," "));
		
	cout << endl;

	adjacent_difference(ilist.begin(), ilist.end(), 
			    ilist_result.begin(), times<int>() );

	// generates output: 1 1 2 6 15 40
	copy( ilist_result.begin(), ilist_result.end(),
	      ostream_iterator<int>(cout," "));

	return 0;
}
예제 #7
0
파일: tfFileIO_.c 프로젝트: KatsOide/SAD
static int ReadLink(integer4 *isp1,
		    integer8 *kx,
		    integer4 *irtc) {
  integer8 ia;
  integer4 nc;
  char *expanded, buf[MAXPATHLEN];

  if(isp != *isp1 + 1) {
    *irtc = itfmessage(9, "General::narg", "\"1\"");
    return -1;
  }
  if((ktfmask & ktastk( *isp1 + 1)) != ktfstring) {
    *irtc = itfmessage(9, "General::wrongtype", "\"String\"");
    return -1;
  }

  ia = (ktamask & ktastk(*isp1 + 1));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif

  expanded = expand_tilde(&jlist(1, ia + 1));
  if(expanded == NULL) {
    *kx = ktfoper + mtfnull;;
    *irtc = 0;
#ifdef SAD_THROW_EXCEPTION
    switch(errno) {
    case ENOMEM:
      *irtc = itfsyserr(9);
      break;

    default:
      *irtc = itfmessage(9, "System::error",
			 "\"No such home directory\"");
    }
#ifdef SAD_NOBREAK_EXCEPTION
    *irtc = 0;
#endif
#endif
    return 1;
  }

  nc = readlink(expanded, buf, sizeof(buf)); free(expanded);
  if(nc < 0) {
    *kx = ktfoper + mtfnull;;
    *irtc = 0;
#ifdef SAD_THROW_EXCEPTION
    *irtc = itfsyserr(9);
#ifdef SAD_NOBREAK_EXCEPTION
    *irtc = 0;
#endif
#endif
    return 1;
  }

  *kx = ktfstring + ktsalocbl(-1, buf, nc);
  *irtc = 0;
  return 0;
}
예제 #8
0
InstructionList compile(Expression *expr) {
   InstructionList ilist(10);
   Expression *root = new Expression(strdup("root"), expr, new Expression(0));
   initialize();
   _compile(ilist, root, 0);
   cout << "Generated compiled code:" << endl;
   cout << ilist << endl;
   return ilist;
}
예제 #9
0
파일: 11-22.cpp 프로젝트: bondyuan/exercise
int main(int argc, char const *argv[])
{
	int array[] = {0,1,2,3,4,5,6,7,8,9};
	std::vector<int> ivec(array, array + 10);
	std::list<int> ilist(ivec.rbegin() + 3, ivec.rend() - 2);
	for (std::list<int>::iterator it = ilist.begin(); it != ilist.end(); ++it)
	{
		std::cout << *it << std::endl;
	}
	return 0;
}
예제 #10
0
파일: scope_ascom.cpp 프로젝트: rwg0/phd2
wxArrayString ScopeASCOM::EnumAscomScopes()
{
    wxArrayString list;

    try
    {
        DispatchObj profile;
        if (!profile.Create(L"ASCOM.Utilities.Profile"))
            throw ERROR_INFO("ASCOM Scope: could not instantiate ASCOM profile class ASCOM.Utilities.Profile. Is ASCOM installed?");

        Variant res;
        if (!profile.InvokeMethod(&res, L"RegisteredDevices", L"Telescope"))
            throw ERROR_INFO("ASCOM Scope: could not query registered telescope devices: " + ExcepMsg(profile.Excep()));

        DispatchClass ilist_class;
        DispatchObj ilist(res.pdispVal, &ilist_class);

        Variant vcnt;
        if (!ilist.GetProp(&vcnt, L"Count"))
            throw ERROR_INFO("ASCOM Scope: could not query registered telescopes: " + ExcepMsg(ilist.Excep()));

        // if we made it this far ASCOM is installed and apprears sane, so add the chooser
        list.Add(_T("ASCOM Telescope Chooser"));

        unsigned int const count = vcnt.intVal;
        DispatchClass kvpair_class;

        for (unsigned int i = 0; i < count; i++)
        {
            Variant kvpres;
            if (ilist.GetProp(&kvpres, L"Item", i))
            {
                DispatchObj kvpair(kvpres.pdispVal, &kvpair_class);
                Variant vkey, vval;
                if (kvpair.GetProp(&vkey, L"Key") && kvpair.GetProp(&vval, L"Value"))
                {
                    wxString ascomName = vval.bstrVal;
                    wxString displName = displayName(ascomName);
                    wxString progid = vkey.bstrVal;
                    s_progid[displName] = progid;
                    list.Add(displName);
                }
            }
        }
    }
    catch (const wxString& msg)
    {
        POSSIBLY_UNUSED(msg);
    }

    return list;
}
예제 #11
0
파일: tfFileIO_.c 프로젝트: KatsOide/SAD
static int MkSecureTemp(integer4 *isp1,
			integer8 *kx,
			integer4 *irtc) {
  integer8 ka1, ka2 = 0;
  int fd, nc, slen;
  char *template;

  if(!(*isp1 < isp && isp < *isp1 + 3)) {
    *irtc = itfmessage(9, "General::narg", "\"1 or 2\"");
    return -1;
  }
  if((ktfmask & ktastk(*isp1 + 1)) != ktfstring) {
    *irtc = itfmessage(9, "General::wrongtype", "\"String\"");
    return -1;
  }

  ka1 = ktamask & ktastk(*isp1 + 1);
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ka1) + 1, ka1 + 1) = '\0';
#endif
  nc = itastk(1, ka1);
  slen = 0;
  if(nc < 1) {
    *kx = kxfailed;
    *irtc = 0;
    return -1;
  }

  if(isp == *isp1 + 2) {
    if((ktfmask & ktastk(*isp1 + 2)) != ktfstring) {
      *irtc = itfmessage(9, "General::wrongtype", "\"String\"");
      return -1;
    }
    ka2 = (ktamask & ktastk(*isp1 + 2));
#if SAD_REQUIRE_STRING_TERMINATION
    jlist(ilist(1, ka2) + 1, ka2 + 1) = '\0';
#endif
    slen = ktastk(ka2);
  }
예제 #12
0
static void fdef( void )
{
register uint8 fnr = pop();

   iprintf(( "defining func %d\n", fnr ));
   assert( fnr < maxpp->maxFunctionDefs );
   fTable[fnr].start_address = ins_ptr;
   while( *ins_ptr != 0x2d ) { 	/* ENDF */
#if LISTING
   INSTRUCTION *ip0 = ilist( ins_ptr );
       putchar( '\n' );
#endif
       ins_ptr = iscan( ins_ptr );
#if LISTING
       assert( ins_ptr == ip0 );
#endif
   } /* while */
#if LISTING
   ilist( ins_ptr ); iprintf( "\n\n" );	/* ENDF ins */
#endif
   fTable[fnr].end_address = ins_ptr;
   ins_ptr++;
} /* fdef() */
예제 #13
0
void KMDriverDbWidget::slotManufacturerSelected(const QString &name)
{
    m_model->clear();
    QDict< KMDBEntryList > *models = KMDriverDB::self()->findModels(name);
    if(models)
    {
        QStrIList ilist(true);
        QDictIterator< KMDBEntryList > it(*models);
        for(; it.current(); ++it)
            ilist.append(it.currentKey().latin1());
        ilist.sort();
        m_model->insertStrList(&ilist);
        m_model->setCurrentItem(0);
    }
}
예제 #14
0
void
assembleTransposeMatrix ( MatrixEpetra<Real>&   globalMatrix,
                          Real                  coefficient,
                          MatrixElemental&              localMatrix,
                          const CurrentFE&      currentFE1,
                          const CurrentFE&      currentFE2,
                          const DofType1&       dof1,
                          const DofType2&       dof2,
                          Int                   iblock,
                          Int                   jblock,
                          Int                   iOffset ,
                          Int                   jOffset )

{
    MatrixElemental::matrix_type localView (localMatrix.block ( jblock, iblock ) );
    localView *= coefficient;

    Int i, j;
    UInt k1, k2;

    UInt elementID1 = currentFE1.currentLocalId();
    UInt elementID2 = currentFE2.currentLocalId();

    std::vector<Int> ilist (currentFE1.nbFEDof() );
    std::vector<Int> jlist (currentFE2.nbFEDof() );

    std::vector<Real*> matPtr (currentFE1.nbFEDof() );

    for ( k1 = 0 ; k1 < currentFE1.nbFEDof() ; k1++ )
    {
        i =  k1;
        ilist[k1] = dof1.localToGlobalMap ( elementID1, i ) + iOffset ;
        matPtr[k1] = & (localView (0, i) );
    }

    for ( k2 = 0 ; k2 < currentFE2.nbFEDof() ; k2++ )
    {
        j = k2;
        jlist[k2]  = dof2.localToGlobalMap ( elementID2, j ) + jOffset ;
    }

    assert (localView.indexij ( Int (1), Int (0) ) == 1);

    globalMatrix.addToCoefficients ( currentFE1.nbFEDof(), currentFE2.nbFEDof(),
                                     ilist, jlist, &matPtr[0], Epetra_FECrsMatrix::ROW_MAJOR );

}
예제 #15
0
int main()
{
  	int search_value;
  	int ia[ 6 ] = { 27, 210, 12, 47, 109, 83 };
  	list<int> ilist( ia, ia+6 );

  	cout << "enter search value: ";
  	cin >> search_value;

  	list<int>::iterator presult;
  	presult = find( ilist.begin(), ilist.end(), search_value );

  	cout << "The value " << search_value
     		<< (presult == ilist.end()
      			? " is not present" : " is present" )
       		<< endl;
}
예제 #16
0
파일: alg6.C 프로젝트: jiayuehua/cpp-primer
int main() 
{
	int ia[] = {0,1,1,2,3,5,8,13,21,34};
	list< int,allocator > ilist( ia, ia+10 );
		
        /*
         * unsupported in current implementation
         *****************************************************
	 typedef 
	    iterator_traits<InputIterator>::distance_type
	    distance_type;
	
	    distance_type ia_count, list_count;
		
	    // count even elements: 4 
	    ia_count = count_if( &ia[0], &ia[10], Even() );
	    list_count = count_if( ilist.begin(), ilist_end(),
			           bind2nd(less<int>(),10) );
	  ******************************************************
	  */

	int ia_count = 0;
        count_if( &ia[0], &ia[10], Even(), ia_count );

	// generates: 
	//   count_if(): there are 4 elements that are even.

	cout << "count_if(): there are "
	     << ia_count << " elements that are even.\n";

	int list_count = 0;
        count_if( ilist.begin(), ilist.end(),
	          bind2nd(less<int>(),10), list_count );


	// generates: 
	//   count_if(): there are 7 elements that are less than 10.

	cout << "count_if(): there are "
	     << list_count 
	     << " elements that are less than 10.\n";
		
	return 0;
}
예제 #17
0
파일: alg7.C 프로젝트: jiayuehua/cpp-primer
int main() 
{
	int ia[] =  { 0,1,1,2,3,5,8,13 };
	int ia2[] = { 0,1,1,2,3,5,8,13,21,34 };

	bool res;
		
        // true: both are equal to the length of ia. 
	// generates: int ia[7] equal to int ia2[9]? true.

	res = equal( &ia[0], &ia[7], &ia2[0] );
	cout << "int ia[7] equal to int ia2[9]? "
	     << ( res ? "true" : "false" ) << ".\n";
		
        // false: not equal to the length of ia2. 
	// note: dangerous since ia[8] and ia[9] do not exist!
	// generates: int ia2[9] equal to int ia[7]? false.

	res = equal( &ia2[0], &ia2[9], &ia[0] );
	cout << "int ia2[9] equal to int ia[7]? "
	     << ( res ? "true" : "false" ) << ".\n";

	list< int, allocator > ilist(  ia,  ia+7  );
	list< int, allocator > ilist2( ia2, ia2+9 );
		
	// generates: list ilist equal to ilist2? true.

	res = equal( ilist.begin(), ilist.end(), ilist2.begin() );
	cout << "list ilist equal to ilist2? "
	     << ( res ? "true" : "false" ) << ".\n";

  	// false: 0, 2, 8 are not equal and odd
	// generates: list ilist equal_and_odd() to ilist2? false.

	res = equal( ilist.begin(), ilist.end(),
		     ilist2.begin(), equal_and_odd() );

	cout << "list ilist equal_and_odd() to ilist2? "
	     << ( res ? "true" : "false" ) << ".\n";
		
	return 0;
}
예제 #18
0
파일: tfFileIO_.c 프로젝트: KatsOide/SAD
/* SADScript function definition of FileIO stuff */
static int ExpandTilde(integer4 *isp1,
		       integer8 *kx,
		       integer4 *irtc) {
  integer8 ia;
  char *expanded;

  if(isp != *isp1 + 1) {
    *irtc = itfmessage(9, "General::narg", "\"1\"");
    return -1;
  }

  if((ktfmask & ktastk(*isp1 + 1)) != ktfstring) {
    *irtc = itfmessage(9, "General::wrongtype", "\"String\"");
    return -1;
  }

  ia = (ktamask & ktastk(*isp1 + 1));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif

  expanded = expand_tilde(&jlist(1, ia + 1));
  if(expanded == NULL) {
    switch(errno) {
    case ENOMEM:
      *irtc = itfsyserr(9);
      break;

    default:
      *irtc = itfmessage(9, "System::error",
			 "\"No such home directory\"");
    }
    return 1;
  }

  *kx = ktfstring + ktsalocb(-1, expanded); free(expanded);
  *irtc = 0;
  return 0;
}
예제 #19
0
int main()
{
        list< int, allocator > ilist( 10 );
        void (*pfi)( int ) = print_elements;

	generate_n( ilist.begin(), ilist.size(), even_by_twos() );

	// generates:
	// generate_n with even_by_twos():
	// 2 4 6 8 10 12 14 16 18 20 

	cout << "generate_n with even_by_twos():\n";
	for_each( ilist.begin(), ilist.end(), pfi ); cout << "\n";

	generate_n( ilist.begin(), ilist.size(), even_by_twos( 100 ) );

	// generates:
	// generate_n with even_by_twos( 100 ):
	// 102 104 106 108 110 112 114 116 118 120

	cout << "generate_n with even_by_twos( 100 ):\n";
	for_each( ilist.begin(), ilist.end(), pfi );
}
예제 #20
0
void ibug( void )
{
char ch;
static int  i0;
int    i1;
int depth;
int32 *sp;
char s[32];
char s0[32];
char s1[32];
BOOL loop_flag = FALSE;
static INSTRUCTION *ip0;
INSTRUCTION   *ip1;
static char brk_ins[12];

   ip1 = ilist( ins_ptr );
   if( ((*go_adr_str == '\0') || (strcmp(go_adr_str, prg_str) == 0))
    && ((ip1 > go_adr) && (ins_ptr <= go_adr)) ) {
      printf( "reached go address\n" );
      go_flag = FALSE;
   } /* if */
   if( match( iname[*ins_ptr], brk_ins ) ) {
      printf( "reached break instruction %s at adr %d\n",
             iname[*ins_ptr], (int)(ins_ptr - prg_start) );
      go_flag = FALSE;
   } /* if */

  if( go_flag ) return;

   while( !loop_flag ) {
      ch = rdch(); putchar( '\b' );
      switch( ch ) {
      case '?':
	 printf( "\ng adr\t go til address\n"
	         "$\tshow stack elements\n"
		 "?\thelp\n"
		 "b instruction\tbreak \n"
		 "l [start][,end]\tlist from start..end\n"
		 "space\tstep\n" );
	 break;
      case 'b':
         printf( "\nb " );
	 fgets( brk_ins, sizeof(brk_ins), stdin );
	 break;
      case '$':
	 depth = stack_ptr - stack_Base;
	 printf( "\n$ stack[%d]: ", depth );
	 sp = stack_ptr - 1;
	 i1 = depth>10 ? 10 : depth;
	 while( i1>0 ) {
	    printf( " -> %ld", *sp );
	    sp--; i1--;
	 } /* for */
	 printf( "\n" );
	 break;
      case 'l':
	 printf( "\nl " ); fflush( stdout );
	 fgets( s, sizeof(s), stdin );
	 switch( sscanf( s, "%d, %d", &i0, &i1 ) ) {
	 default:
	    if( prev_ch != 'l' ) {
	       ip0 = ins_ptr;
	    } /* if */
	    ip1 = ip0+10;
	    break;
	 case 1:
	    ip0 = prg_start+i0;
	    ip1 = ip0+10;
	    break;
	 case 2:
	    ip0 = prg_start+i0;
	    ip1 = prg_start+i1;
	 } /* switch */
	 while( ip0<=ip1 ) {
	    ip0 = ilist( ip0 );
	    printf( "\n ");
	 } /* for */
	 break; /* case 'l' */
      case 'g':
	 printf( "\ng " ); fflush( stdout );
	 fgets( s, sizeof(s), stdin );
	 switch( sscanf( s, "%s.%d", s0, s1 ) ) {
	 case 1: 
	    go_adr = prg_start + atoi( s0 );
	    *go_adr_str = '\0';
	    break;
	 case 2:
	    go_adr = prg_start + atoi( s1 );
	    strcpy( go_adr_str, s0);
	    break;
	 } /* switch */
	 go_flag = TRUE;
	 loop_flag = TRUE;
	 break;
      default:
	 loop_flag = TRUE;
      } /* switch */
      prev_ch = ch;
   } /* while */

} /* ibug() */
예제 #21
0
static int tfNetSemInfo(integer4 *isp1,
			integer8 *kx,
			integer4 *irtc) {
  integer8 ia;
  real8 vx;
  int status, semaphore, select;
  char buffer[MSG_LEN];

  if(isp != *isp1 + 3) {
    *irtc = itfmessage(9, "General::narg", "\"3\"");
    return -1;
  }

  if(ktfnonstringq(ktastk( *isp1 + 1))) {
    *irtc = itfmessage(9, "General::wrongtype", "\"Character-string for #1\"");
    return -1;
  }

  if(ktfnonrealq(ktastk( *isp1 + 2))) {
    *irtc = itfmessage(9, "General::wrongtype", "\"Real Number for #2\"");
    return -1;
  }

  if(ktfrealq(ktastk(isp))){
    select = rtastk( isp);
  }
  else if(ktfstringq(ktastk(isp))){
    ia = ktfaddr(ktastk(isp));
#if SAD_REQUIRE_STRING_TERMINATION
    jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif
    if(strcmp("Owner", &jlist(1, ia + 1)) == 0) {
      select = OWNER; goto l1;
    }

    if(strcmp("Waiter", &jlist(1, ia + 1)) == 0) {
      select = WAITER; goto l1;
    }

    *irtc = itfmessage(9, "General::wrongtype", "\"Character-string "
		       "\\\"Owner\\\" or \\\"Waiter\\\" for #3\"");
    return -1;
  }
  else{
    *irtc = itfmessage(9, "General::wrongtype",
		       "\"Real Number or Character-string for #3\"");
    return -1;
  }

 l1:  ia = ktfaddr(ktastk(*isp1 + 1));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif
  semaphore = rtastk(*isp1 + 2);

  status = netSemInfo(&jlist(1, ia + 1), semaphore, select, buffer);

  if(status == 0) {
    *kx = ktfstring +ktsalocb(-1, buffer);
  } else {
    *kx = ktfoper + mtfnull;
  }
  *irtc = 0;
  return 0;
}
예제 #22
0
bool DictClient::parse(gchar *line, int status_code)
{
	g_debug("get %s\n", line);

	if (!cmd_.get()) {
		if (status_code == STATUS_CONNECT)
			is_connected_ = true;
		else if (status_code == STATUS_SERVER_DOWN ||
			 status_code == STATUS_SHUTDOWN) {
			gchar *mes =
				g_strdup_printf("Unable to connect to the "
						"dictionary server at '%s:%d'. "
						"The server replied with code"
						" %d (server down)",
						host_.c_str(), port_,
						status_code);
			on_error_.emit(mes);
			g_free(mes);
			return true;
		} else {
			gchar *mes =
				g_strdup_printf("Unable to parse the dictionary"
						" server reply: '%s'", line);
			on_error_.emit(mes);
			g_free(mes);
			return false;
		}
	}

	bool success = false;

	switch (status_code) {
	case STATUS_BAD_PARAMETERS:
	{
		gchar *mes = g_strdup_printf("Bad parameters for command '%s'",
					     cmd_->query().c_str());
		on_error_.emit(mes);
		g_free(mes);
		cmd_->state_ = DICT::Cmd::FINISH;
		break;
	}
	case STATUS_BAD_COMMAND:
	{
		gchar *mes = g_strdup_printf("Bad command '%s'",
					     cmd_->query().c_str());
		on_error_.emit(mes);
		g_free(mes);
		cmd_->state_ = DICT::Cmd::FINISH;
		break;
	}
	default:
		success = true;
		break;
	}

	if (cmd_->state_ == DICT::Cmd::START) {
		GError *err = NULL;
		cmd_->send(channel_, err);
		if (err) {
			on_error_.emit(err->message);
			g_error_free(err);
			return false;
		}
		return true;
	}

	if (status_code == STATUS_OK || cmd_->state_ == DICT::Cmd::FINISH ||
	    status_code == STATUS_NO_MATCH ||
	    status_code == STATUS_BAD_DATABASE ||
	    status_code == STATUS_BAD_STRATEGY ||
	    status_code == STATUS_NO_DATABASES_PRESENT ||
	    status_code == STATUS_NO_STRATEGIES_PRESENT) {
		defmap_.clear();
		const DICT::DefList& res = cmd_->result();
		if (simple_lookup_) {
			IndexList ilist(res.size());
			for (size_t i = 0; i < res.size(); ++i) {
				ilist[i] = last_index_;
				defmap_.insert(std::make_pair(last_index_++, res[i]));
			}
			last_index_ = 0;
			cmd_.reset(0);
			disconnect();
			on_simple_lookup_end_.emit(ilist);
		} else {
			StringList slist;
			for (size_t i = 0; i < res.size(); ++i)
				slist.push_back(res[i].word_);
			last_index_ = 0;
			cmd_.reset(0);
			disconnect();
			on_complex_lookup_end_.emit(slist);
		}

		return success;
	}

	if (!cmd_->parse(line, status_code))
		return false;


	return true;
}
예제 #23
0
void ConeSplitMerge<Item>::split_merge(std::vector<ProtoJet<Item> >& jcv,
				       float shared_ET_fraction,
				       float pT_min_leading_protojet, float pT_min_second_protojet,
				       int MergeMax, float pT_min_noMergeMax) 
{
  while(!_members.empty()) 
  {
    /*
    {
      std::cout << std::endl;
      std::cout << " ---------------  list of protojets ------------------ " <<std::endl;
      for ( PJMMAP::iterator it = _members.begin();
	    it != _members.end(); ++it)
      {
	std::cout << " pT y phi " << (*it).pT() << " " << (*it).y() << " " << (*it).phi() << " " << (*it).info().seedET() <<  " " << (*it).info().nbMerge() << " " << (*it).info().nbSplit() << std::endl;
      }
      std::cout << " ----------------------------------------------------- " <<std::endl;
    }
    */


    // select highest Et jet
    typename PJMMAP::iterator itmax= _members.begin();
    ProtoJet<Item> imax((*itmax).first);
    const std::list<const Item*>& ilist(imax.LItems());

    _members.erase(itmax);
 
    // does jet share items?
    bool share= false;
    float shared_ET = 0.;
    typename PJMMAP::iterator jtmax;
    typename PJMMAP::iterator jt;
    for(jt = _members.begin(); jt != _members.end(); ++jt) 
    {
      const std::list<const Item*>& jlist((*jt).first.LItems());
      typename std::list<const Item*>::const_iterator tk;
      int count;
      for(tk = ilist.begin(), count = 0; tk != ilist.end(); 
	  ++tk, ++count) 
      {
	typename std::list<const Item*>::const_iterator where= 
	  find(jlist.begin(),jlist.end(),*tk);   
	if(where != jlist.end()) 
	{
	  share= true;
	  shared_ET += (*tk)->pT();
	}
      }
      if(share) 
      {
	jtmax = jt;
	break;
      }
    }
    
    if(!share) {
      // add jet to the final jet list
      jcv.push_back(imax);
      //std::cout << " final jet " << imax.pT() << " "<< imax.info().nbMerge() << " " << imax.info().nbSplit() << std::endl; 
    }
    else 
    {
      // find highest Et neighbor
      ProtoJet<Item> jmax((*jtmax).first);

      // drop neighbor
      _members.erase(jtmax);


      //std::cout << " split or merge ? " << imax.pT() << " " << shared_ET << " " << jmax.pT() << " " << s << " " << (jmax.pT())*s << std::endl;

      // merge
      if( shared_ET > (jmax.pT())*shared_ET_fraction 
	  && (imax.pT() > pT_min_leading_protojet || jmax.pT() > pT_min_second_protojet)
	  && (imax.info().nbMerge() < MergeMax || imax.pT() > pT_min_noMergeMax))
	{
	  // add neighbor's items to imax
	  const std::list<const Item*>& jlist(jmax.LItems());
	  typename std::list<const Item*>::const_iterator tk;
	  typename std::list<const Item*>::const_iterator iend= ilist.end();
	  bool same = true; // is jmax just the same as imax ? 
	  for(tk = jlist.begin(); tk != jlist.end(); ++tk) 
	    {
	      typename std::list<const Item*>::const_iterator where= 
		find(ilist.begin(),iend,*tk);   
	      if(where == iend) 
		{
		  imax.addItem(*tk);
		  same = false;
		}
	    }
	  if ( ! same ) 
	    {
	      // recalculate
	      //float old_pT = imax.pT();
	      
	      imax.updateJet();
	      imax.merged();
	      //std::cout << " jet merge :: " << old_pT << " " << jmax.pT() << " " << imax.pT() << " "<< imax.info().nbMerge() << " " << imax.info().nbSplit() << std::endl; 
	    }
	}
      
      //split and assign removed shared cells from lowest pT protojet
      else if(shared_ET > (jmax.pT())*shared_ET_fraction)
      {
	// here we need to pull the lists, because there are items to remove                                                                           
	std::list<const Item*> ilist(imax.LItems());
	std::list<const Item*> jlist(jmax.LItems());

        typename std::list<const Item*>::iterator tk;
        for(tk = jlist.begin(); tk != jlist.end(); )
	  {
	    typename std::list<const Item*>::iterator where=
	      find(ilist.begin(),ilist.end(),*tk);
	    if(where != ilist.end()) {
	      tk = jlist.erase(tk);
	    }
	    else ++tk;
	  }
	
        jmax.erase();

        for ( typename std::list<const Item*>::const_iterator it = jlist.begin();
              it != jlist.end(); ++it) jmax.addItem(*it);

        // recalculated jet quantities 
        jmax.updateJet();
        jmax.splitted();
        //std::cout << " jet split 1 :: " << jmax.pT() << " "<< jmax.info().nbMerge() << " " << jmax.info().nbSplit() << std::endl;                         
        _members.insert(std::make_pair(jmax,jmax.pT()));
      }

      // split and assign shared cells to nearest protojet
      else 
      {
	// here we need to pull the lists, because there are items to remove
	std::list<const Item*> ilist(imax.LItems());
	std::list<const Item*> jlist(jmax.LItems());
	
	typename std::list<const Item*>::iterator tk;
	for(tk = jlist.begin(); tk != jlist.end(); ) 
	{
	  typename std::list<const Item*>::iterator where= 
	    find(ilist.begin(),ilist.end(),*tk);
	  if(where != ilist.end()) {
	    float yk   = (*tk)->y();
	    float phik = (*tk)->phi();
	    float di= RD2(imax.y(),imax.phi(),yk,phik);
	    float dj= RD2(jmax.y(),jmax.phi(),yk,phik);
	    if(dj > di) 
	    {
	      tk = jlist.erase(tk);
	      //std::cout << " shared item " << (*tk)->pT() << " removed from neighbour jet " << std::endl;
	    }
	    else
	    {
	      ilist.erase(where);
	      ++tk;
	      //std::cout << " shared item " << (*tk)->pT() << " removed from leading jet " << std::endl;
	    }
	  }
	  else ++tk;
	}
	// recalculate jets imax and jmax
	
	// first erase all items
	imax.erase();
	// put items that are left
	for ( typename std::list<const Item*>::const_iterator it = ilist.begin();
	      it != ilist.end(); ++it) imax.addItem(*it);
	// recalculated jet quantities
	imax.updateJet();
	imax.splitted();
	//std::cout << " jet split 2 :: " << imax.pT() << " "<< imax.info().nbMerge() << " " << imax.info().nbSplit() << std::endl; 


	// first erase all items
	jmax.erase();
	// put items that are left
	for ( typename std::list<const Item*>::const_iterator it = jlist.begin();
	      it != jlist.end(); ++it) jmax.addItem(*it);
	// recalculated jet quantities
	jmax.updateJet();
	jmax.splitted();
	//std::cout << " jet split " << jmax.pT() << " "<< jmax.info().nbMerge() << " " << jmax.info().nbSplit() << std::endl; 

	_members.insert(std::make_pair(jmax,jmax.pT()));
      }
      _members.insert(std::make_pair(imax,imax.pT()));
    }
  } // while
}
TEST(SparseMatrixSpecialValues, Z2determined)
{
	typedef FiniteFieldParam<ZPlusRing32>::Module<2> Param;
	Param::Matrix m;
	const auto E = m.ElementConstructor();
	{//zero matrix size 1
		m.Clear();
		m.AddRow();
		ExpectNoSolution(m);
	}
	{//zero matrix size 3
		m.Clear();
		m.AddRow();
		m.AddRow();
		m.AddRow();
		ExpectNoSolution(m);
	}
	{//identity matrix size 1
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u)}));
	}
	{//identity matrix size 3
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u)}));
	}
	{//matrix with only last column needed
		m.Clear();
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(2, 1u)}));
	}
	{//matrix with big column number
		m.Clear();
		m.AddRow();
		m.AddElement(42, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(42, 1u)}));
	}
	{//matrix with single zero column
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		ExpectNoSolution(m);
	}
	{//matrix with single columnwith ones
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		ExpectNoSolution(m);
	}
	{//matrix with single columnw eqaul to result, non-obviousely initialized
		m.Clear();
		m.AddRow();
		m.AddElement(0, 3u);
		m.AddRow();
		m.AddElement(0, 2u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u)}));
	}
	{//matrix with every column needed in sum
		m.Clear();
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(1, 1u), E(2, 1u), E(3, 1u)}));
	}
	{//matrix with every column needed in sum - other column order
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(1, 1u), E(2, 1u), E(3, 1u)}));
	}
	{//matrix with NOT every column needed in sum
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(2, 1u)}));
	}
	{//matrix with NOT every column needed in sum - other column order
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(1, 1u), E(3, 1u)}));
	}
	{//wide matrix with zero columns; wide matrix with non-zero columns would have non-determined result, so is not included in this test
		m.Clear();
		m.AddRow();
		m.AddElement(42, 1u);
		m.AddRow();
		m.AddElement(12, 1u);
		m.AddElement(32, 1u);
		m.AddElement(42, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddElement(32, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddElement(12, 1u);
		m.AddElement(32, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(2, 1u), E(32, 1u), E(42, 1u)}));
	}
	{//tall matrix
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddElement(4, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddElement(4, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(2, 1u), E(3, 1u), E(4, 1u)}));
	}
}
예제 #25
0
파일: tfFileIO_.c 프로젝트: KatsOide/SAD
static int FromFileDate(integer4 *isp1,
			integer8 *kx,
			integer4 *irtc) {
  integer8 ia;
  real8 vx;
  char *expanded;
  struct stat buf;

  if(isp != *isp1 + 1) {
    *irtc = itfmessage(9, "General::narg", "\"1\"");
    return -1;
  }
  if((ktfmask & ktastk( *isp1 + 1)) != ktfstring) {
    *irtc = itfmessage(9, "General::wrongtype", "\"String\"");
    return -1;
  }

  ia = (ktamask & ktastk(*isp1 + 1));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif

  expanded = expand_tilde(&jlist(1, ia + 1));
  if(expanded == NULL) {
*kx = ktfoper + mtfnull;;
    *irtc = 0;
#ifdef SAD_THROW_EXCEPTION
    switch(errno) {
    case ENOMEM:
      *irtc = itfsyserr(9);
      break;

    default:
      *irtc = itfmessage(9, "System::error",
			 "\"No such home directory\"");
    }
#ifdef SAD_NOBREAK_EXCEPTION
    *irtc = 0;
#endif
#endif
    return 1;
  }

  if(stat(expanded, &buf) != 0) {
    free(expanded);
    *kx = ktfoper + mtfnull;
    *irtc = 0;
#ifdef SAD_THROW_EXCEPTION
    *irtc = itfsyserr(9);
#ifdef SAD_NOBREAK_EXCEPTION
    *irtc = 0;
#endif
#endif
    return 1;
  }
  free(expanded);

  vx  = buf.st_mtime + SAD_EPOCH_OFFSET;
  *kx = kfromr(vx);
  *irtc = 0;
  return 0;
}