示例#1
0
void tst_storage::tst_rawEvents()
{
  // TODO: Should split tests if making more cases outside storage
  auto event = KCalCore::Event::Ptr(new KCalCore::Event);
  // NOTE: no other events should be made happening this day
  QDate startDate(2010, 12, 1);
  event->setDtStart(KDateTime(startDate, QTime(12, 0), KDateTime::ClockTime));
  event->setDtEnd(KDateTime(startDate, QTime(13, 0), KDateTime::ClockTime));

  KCalCore::Recurrence *recurrence = event->recurrence();
  recurrence->setDaily(1);
  recurrence->setStartDateTime(event->dtStart());

  m_calendar->addEvent(event, NotebookId);
  m_storage->save();
  QString uid = event->uid();
  reloadDb();

  auto fetchEvent = m_calendar->event(uid);
  QVERIFY(fetchEvent);
  KCalCore::Recurrence *fetchRecurrence = fetchEvent->recurrence();
  QVERIFY(fetchRecurrence);

  // should return occurrence for both days
  mKCal::ExtendedCalendar::ExpandedIncidenceList events
      = m_calendar->rawExpandedEvents(startDate, startDate.addDays(1), false, false, KDateTime::Spec(KDateTime::LocalZone));

  QCOMPARE(events.size(), 2);
}
示例#2
0
// Exporting Event data to map. Using the same
// encoding as ODateBookAccessBackend_xml does..
// Thus, we could remove the stuff there and use this
// for it and for all other places..
// Encoding should happen at one place, only ! (eilers)
QMap<int, QString> OEvent::toMap()const {
    QMap<int, QString> retMap;

    retMap.insert( OEvent::FUid, QString::number( uid() ) );
    retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ));
    retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) );
    retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) );
    retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" );
    OPimAlarm alarm = notifiers().alarms()[0];
    retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo(  startDateTime() ) / 60 ) );
    retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" );

    OTimeZone zone(  timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
    retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime(  startDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime(  endDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) );
    retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
    if( parent() )
	    retMap.insert( OEvent::FRecParent, QString::number( parent() ) );
    if( children().count() ){
            QArray<int> childr = children();
	    QString buf;
            for ( uint i = 0; i < childr.count(); i++ ) {
		    if ( i != 0 ) buf += " ";
		    buf += QString::number( childr[i] );
            }
	    retMap.insert( OEvent::FRecChildren, buf );
    }

    // Add recurrence stuff
    if( hasRecurrence() ){
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
	    retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] );
	    retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] );
	    retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] );
	    retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] );
	    retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] );
	    retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] );
	    retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] );
    } else {
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
    }

    return retMap;
}
void Basis_HGRAD_LINE_Hermite_FEM<Scalar,ArrayScalar>::legendre_d( ArrayScalar &P,
                                                                   ArrayScalar &Px, 
                                                                   const int m, 
                                                                   const Scalar x ) const {
  // Compute P,P'
  recurrence(P,Px,x);

  int C = this->getCardinality();

  // Loop over derivative orders
  for( int k=1;k<m;++k) {
    P = Px;

    // Loop over polynomial indices
    for( int j=0; j<C; ++j ) {
 
     if( j<k ) {
        Px(j) = 0;         
      }

      else {
        Px(j) = (j+k)*P(j-1) + x*Px(j-1);
      }
    }
  }

} // legendre_d()
示例#4
0
void tst_storage::tst_alldayRecurrence()
{
  auto event = KCalCore::Event::Ptr(new KCalCore::Event);

  QDate startDate(2013, 12, 1);
  event->setDtStart(KDateTime(startDate, QTime(), KDateTime::ClockTime));
  event->setAllDay(true);

  KCalCore::Recurrence *recurrence = event->recurrence();
  recurrence->setWeekly(1);
  recurrence->setStartDateTime(event->dtStart());

  m_calendar->addEvent(event, NotebookId);
  m_storage->save();
  QString uid = event->uid();
  reloadDb();

  auto fetchEvent = m_calendar->event(uid);
  QVERIFY(fetchEvent);
  KCalCore::Recurrence *fetchRecurrence = fetchEvent->recurrence();
  QVERIFY(fetchRecurrence);
  KDateTime match = recurrence->getNextDateTime(KDateTime(startDate));
  QCOMPARE(match, KDateTime(startDate.addDays(7), QTime(), KDateTime::ClockTime));
}
示例#5
0
int main(void)
{
    /* Compile input program */
    struct asmbuf *buf = asmbuf_create();
    asmbuf_ins(buf, 3, 0x4889f8); // mov %rdi, %rax
    int c;
    while ((c = fgetc(stdin)) != '\n' && c != EOF) {
        if (c == ' ')
            continue;
        char operator = c;
        long operand;
        scanf("%ld", &operand);
        asmbuf_ins(buf, 2, 0x48bf);         // movq  operand, %rdi
        asmbuf_immediate(buf, 8, &operand);
        switch (operator) {
        case '+':
            asmbuf_ins(buf, 3, 0x4801f8);   // add   %rdi, %rax
            break;
        case '-':
            asmbuf_ins(buf, 3, 0x4829f8);   // sub   %rdi, %rax
            break;
        case '*':
            asmbuf_ins(buf, 4, 0x480fafc7); // imul  %rdi, %rax
            break;
        case '/':
            asmbuf_ins(buf, 3, 0x4831d2);   // xor   %rdx, %rdx
            asmbuf_ins(buf, 3, 0x48f7ff);   // idiv  %rdi
            break;
        }
    }
    asmbuf_ins(buf,  1, 0xc3); // retq
    asmbuf_finalize(buf);

    long init;
    unsigned long term;
    scanf("%ld %lu", &init, &term);
    long (*recurrence)(long) = (void *)buf->code;
    for (unsigned long i = 0, x = init; i <= term; i++, x = recurrence(x))
        fprintf(stderr, "Term %lu: %ld\n", i, x);

    asmbuf_free(buf);
    return 0;
}
void Basis_HGRAD_LINE_Hermite_FEM<Scalar,ArrayScalar>::setupVandermonde( bool factor  ) {

    initializeTags();

    int nBf = this->getCardinality();
    int n   = nBf/2;

    V_.shape(nBf,nBf);

    // Make containers to store the Legendre polynomials and their derivatives
    // at a given point 
    ArrayScalar P ( nBf );
    ArrayScalar Px( nBf );

    // Loop over grid points
    for( int i=0; i<n; ++i ) {

      recurrence(P,Px,latticePts_(i,0));
      
      // Loop over basis functions     
      for(int j=0; j<nBf; ++j ) {
        V_(j, i  ) = P (j);
        V_(j, i+n) = Px(j); 
      }
    }

    solver_.setMatrix(Teuchos::rcpFromRef(V_));

    if(factor) {
      solver_.factorWithEquilibration(true);
      solver_.factor();
      isFactored_ = true;
    }
    else {
      isFactored_ = false;
    }

}
示例#7
0
/**
 * set the start date
 * @param date the new start date
 */
void ORecurranceWidget::setStartDate( const QDate& date ) {
    setRecurrence( recurrence(), date );
}
void Basis_HGRAD_LINE_Hermite_FEM<Scalar, ArrayScalar>::getValues(ArrayScalar &        outputValues,
                                                                  const ArrayScalar &  inputPoints,
                                                                  const EOperator      operatorType) const {
  
  // Verify arguments
#ifdef HAVE_INTREPID_DEBUG
  Intrepid::getValues_HGRAD_Args<Scalar, ArrayScalar>(outputValues,
                                                      inputPoints,
                                                      operatorType,
                                                      this -> getBaseCellTopology(),
                                                      this -> getCardinality() );
#endif
  // Number of evaluation points = dim 0 of inputPoints
  int nPts = inputPoints.dimension(0);  
  int nBf  = this->getCardinality();  

  int n = nBf/2;

  // Legendre polynomials and their derivatives evaluated on inputPoints
  SerialDenseMatrix legendre(nBf,nPts); 

  // Hermite interpolants evaluated on inputPoints
  SerialDenseMatrix hermite(nBf,nPts);
    
  ArrayScalar P (nBf);
  ArrayScalar Px(nBf);
         
  int derivative_order;
  int derivative_case = static_cast<int>(operatorType);

  if( derivative_case == 0 ) {
    derivative_order = 0;
  }
  else if( derivative_case > 0 && derivative_case < 5 ) {
    derivative_order = 1;
  }
  else {
    derivative_order = derivative_case - 3;
  }
  
  try {
    // GRAD,CURL,DIV, and D1 are all the first derivative
    switch (operatorType) {
      case OPERATOR_VALUE: 
      { 
        for( int i=0; i<nPts; ++i ) { 
          recurrence( P, Px, inputPoints(i,0) );
          for( int j=0; j<nBf; ++j ) {
             legendre(j,i) = P(j);
          }
        }
        break; 
      }
      case OPERATOR_GRAD:
      case OPERATOR_DIV:
      case OPERATOR_CURL:
      case OPERATOR_D1:
      {
        for( int i=0; i<nPts; ++i ) { 
          recurrence( P, Px, inputPoints(i,0) );
          for( int j=0; j<nBf; ++j ) {
             legendre(j,i) = Px(j);
          }
        }
        break;
      }  
      case OPERATOR_D2:
      case OPERATOR_D3:
      case OPERATOR_D4:
      case OPERATOR_D5:
      case OPERATOR_D6:
      case OPERATOR_D7:
      case OPERATOR_D8:
      case OPERATOR_D9:
      case OPERATOR_D10:
      {
        for( int i=0; i<nPts; ++i ) {
          legendre_d( P, Px, derivative_order, inputPoints(i,0));
          for( int j=0; j<nBf; ++j ) {
            legendre(j,i) = Px(j); 
          }
        }
        break;
      }
      default:
        TEUCHOS_TEST_FOR_EXCEPTION( !( Intrepid::isValidOperator(operatorType) ), std::invalid_argument,
                            ">>> ERROR (Basis_HGRAD_LINE_Hermite_FEM): Invalid operator type");

    } // switch(operatorType)
  }
  catch (std::invalid_argument &exception){
    TEUCHOS_TEST_FOR_EXCEPTION( true , std::invalid_argument,
                        ">>> ERROR (Basis_HGRAD_LINE_Hermite_FEM): Operator failed");    
  }

  if( !isFactored_ ) {
    solver_.factorWithEquilibration(true);
    solver_.factor();
  }

  solver_.setVectors(Teuchos::rcpFromRef(hermite),Teuchos::rcpFromRef(legendre));
  solver_.solve();

  if(derivative_order > 0)
  {
    for( int i=0; i<n; ++i ) {
      for( int j=0; j<nPts; ++j ) {
        outputValues(2*i,  j,0)  = hermite(i,  j);
        outputValues(2*i+1,j,0)  = hermite(i+n,j);
      } 
    }
  }
  else {
    for( int i=0; i<n; ++i ) {
      for( int j=0; j<nPts; ++j ) {
        outputValues(2*i  ,j)   = hermite(i,  j);
        outputValues(2*i+1,j)   = hermite(i+n,j);
      } 
    }
  }
     
} // getValues()