Exemplo n.º 1
0
double Stats::mean() const {
    DEBUG_SINVARIANT(checkInvariants());
    if (number == 0) {
	return 0.0;
    } else {
	return double(sum)/double(number);
    }
};
Exemplo n.º 2
0
/* implicit */ AliasIdSet::AliasIdSet(uint32_t id) {
  if (id <= BitsetMax) {
    m_bits = Empty | (1ull << id);
  } else {
    m_bits = id;
  }
  assertx(checkInvariants());
}
Exemplo n.º 3
0
void PackedArray::OnSetEvalScalar(ArrayData* ad) {
  assert(checkInvariants(ad));
  auto ptr = packedData(ad);
  auto const stop = ptr + ad->m_packedCap;
  for (; ptr != stop; ++ptr) {
    tvAsVariant(ptr).setEvalScalar();
  }
}
Exemplo n.º 4
0
int main(void){

  WDTCTL = WDTPW | WDTHOLD;  // Stop watchdog timer
  PM5CTL0 &= ~LOCKLPM5;
  initializeHardware();
  reboots++;
  DINO_RESTORE_CHECK();

  DINO_TASK_BOUNDARY(START_TASK,NULL);
  if( finished == 0xBEEE ){
#if defined(WISP5)
    PJOUT |= BIT6;
#elif defined(BREADBOARD)
    P4OUT |= BIT4;
#endif
    while( 1 ){ }
  }

  if( inErrorState == 0xBEEE ){

    abortWithError();

  }

  initializeNVData();
  

  while( numSamples < (NUM_ITERS * SAMPLES_PER_ITER) ){

    int r;
    for(r = 0; r < SAMPLES_PER_ITER; r++){

      DINO_TASK_BOUNDARY(SAMPLE_TASK,NULL);
      unsigned samp = getOneSample();
      DINO_TASK_BOUNDARY(BIN_TASK,NULL);
      addToBin(samp);
      numSamples++;

    }

    DINO_TASK_BOUNDARY(SORT_TASK,NULL);
    sortBinsByFrequency();

    DINO_TASK_BOUNDARY(CHECK_TASK,NULL);
    checkInvariants();

  }

  finished = 0xBEEE;
#if defined(WISP5)
  PJOUT |= BIT6;
#elif defined(BREADBOARD)
  P4OUT |= BIT4;
#endif
  while( 1 ){ }

}
Exemplo n.º 5
0
void Stats::reset() {
    DEBUG_SINVARIANT(checkInvariants());
    StatsBase::reset();
    number = 0;
    sum = 0.0;
    sumsq = 0.0;
    min_value = Double::Inf;
    max_value = -Double::Inf;
}
Exemplo n.º 6
0
VectorEpetra<T>::VectorEpetra ( Epetra_FEVector const * v )
    :
    super( v->Map().NumGlobalElements(), v->Map().NumMyElements() ),
    M_emap( v->Map() ),
    M_vec( *v )
{
    this->init( M_emap, true );
    checkInvariants();
}
Exemplo n.º 7
0
VectorEpetra<T>::VectorEpetra ( Epetra_BlockMap const& emap )
    :
    super( emap.NumGlobalElements(), emap.NumMyElements() ),
    M_emap( emap ),
    M_vec( M_emap )
    //M_destroy_vec_on_exit( true )
{
    this->init( M_emap, true );
    checkInvariants();
}
Exemplo n.º 8
0
VectorEpetra<T>::VectorEpetra ( VectorEpetra const& v )
    :
    super( v ),
    M_emap( v.Map() ),
    M_vec( v.vec() )

{
    this->M_is_initialized = true;
    checkInvariants();
}
Exemplo n.º 9
0
NEVER_INLINE
ArrayData* PackedArray::Grow(ArrayData* old) {
  assert(checkInvariants(old));
  assert(old->m_size == old->m_packedCap);

  DEBUG_ONLY auto const oldPos  = old->m_pos;

  auto const oldCap  = old->m_packedCap;
  auto const cap     = oldCap * 2;
  if (UNLIKELY(cap >= kMaxPackedCap)) return nullptr;

  auto const ad = static_cast<ArrayData*>(
    MM().objMallocLogged(sizeof(ArrayData) + cap * sizeof(TypedValue))
  );

  auto const oldSize        = old->m_size;
  auto const oldPosUnsigned = uint64_t{static_cast<uint32_t>(old->m_pos)};

  ad->m_kindAndSize = uint64_t{oldSize} << 32 | cap;
  ad->m_posAndCount = oldPosUnsigned;
  if (UNLIKELY(strong_iterators_exist())) {
    move_strong_iterators(ad, old);
  }

  // Steal the old array payload.  At the time of this writing, it was
  // better not to reuse the memcpy return value here because gcc had
  // `ad' in a callee saved register anyway.  The reg-to-reg move was
  // smaller than subtracting sizeof(ArrayData) from rax to return.
  old->m_size = 0;
  std::memcpy(packedData(ad), packedData(old), oldSize * sizeof(TypedValue));

  // TODO(#2926276): it would be good to refactor callers to expect
  // our refcount to start at 1.

  assert(ad->m_kind == ArrayData::kPackedKind);
  assert(ad->m_pos == oldPos);
  assert(ad->m_count == 0);
  assert(ad->m_packedCap == cap);
  assert(ad->m_size == oldSize);
  assert(checkInvariants(ad));
  return ad;
}
Exemplo n.º 10
0
std::string Stats::debugString() const {
    DEBUG_SINVARIANT(checkInvariants());

    if (count() == 0) {
	return "count 0";
    } else {
	return str(boost::format("count %d mean %G stddev %G var %G 95%%conf %G rel95%%conf %G"
				 " min %G max %G") % count() % mean() % stddev() % variance()
		   % conf95() % relconf95() % min() % max());
    }
};
Exemplo n.º 11
0
double StatsBase::stddev() const {
    DEBUG_SINVARIANT(checkInvariants());
    double sigsq = variance();

    if (sigsq <= 0.0) {
	return 0.0;
    }

    DEBUG_SINVARIANT(sigsq > 0.0);
    return sqrt(sigsq);
}
Exemplo n.º 12
0
std::string AliasIdSet::toString() const {
  assertx(checkInvariants());

  if (isBigInteger()) {
    return folly::to<std::string>(m_bits);
  }
  if (empty()) return "None";
  if (isAny()) return "Any";

  std::string result;

  // Try to print the slots by grouping them, expect output like
  // '0~4,9,10,50~...'
  auto first = true;         // whether to avoid priting the separator
  int32_t begin = -1;        // starting bit of the consecutive range.

  // Append slots [begin, end) to result string.
  auto const appendRange = [&] (uint32_t end) {
    assertx(end > begin);
    result += folly::to<std::string>(begin);
    if (end == begin + 1) return;
    if (end == begin + 2) {
      result += folly::to<std::string>(",", begin + 1);
    } else {
      result += folly::to<std::string>("~", end - 1);
    }
  };

  for (uint32_t i = 0; i <= BitsetMax; ++i) {
    if (test(i)) {
      if (begin < 0) begin = static_cast<int32_t>(i);
      else continue;
    } else {
      if (begin < 0) continue;
      if (!first) result += ",";
      appendRange(i);
      begin = -1;
      first = false;
    }
  }

  if (hasUpperRange()) {
    if (!first) result += ",";
    if (begin < 0) begin = BitsetMax + 1;
    result += folly::to<std::string>(begin, "~...");
  } else if (begin >= 0) {
    // Append [begin, BitsetMax].
    appendRange(BitsetMax + 1);
  }

  return result;
}
Exemplo n.º 13
0
void APCHandle::deleteShared() {
  assert(checkInvariants());
  switch (m_kind) {
    case APCKind::Uninit:
    case APCKind::Null:
    case APCKind::Bool:
      return;
    case APCKind::Int:
    case APCKind::Double:
    case APCKind::StaticString:
    case APCKind::StaticArray:
    case APCKind::StaticVec:
    case APCKind::StaticDict:
    case APCKind::StaticKeyset:
      delete APCTypedValue::fromHandle(this);
      return;

    case APCKind::SharedString:
    case APCKind::SerializedArray:
    case APCKind::SerializedVec:
    case APCKind::SerializedDict:
    case APCKind::SerializedKeyset:
    case APCKind::SerializedObject:
      APCString::Delete(APCString::fromHandle(this));
      return;

    case APCKind::SharedPackedArray:
    case APCKind::SharedArray:
    case APCKind::SharedVec:
    case APCKind::SharedDict:
    case APCKind::SharedKeyset:
      APCArray::Delete(this);
      return;

    case APCKind::SharedObject:
      APCObject::Delete(this);
      return;

    case APCKind::SharedCollection:
      APCCollection::Delete(this);
      return;

    case APCKind::UncountedArray:
    case APCKind::UncountedVec:
    case APCKind::UncountedDict:
    case APCKind::UncountedKeyset:
    case APCKind::UncountedString:
      assert(false);
      return;
  }
  not_reached();
}
Exemplo n.º 14
0
ArrayData* PackedArray::PlusEq(ArrayData* adIn, const ArrayData* elems) {
  assert(checkInvariants(adIn));
  auto const neededSize = adIn->size() + elems->size();
  auto const mixed = ToMixedCopyReserve(adIn, neededSize);
  try {
    auto const ret = MixedArray::PlusEq(mixed, elems);
    assert(ret == mixed);
    assert(!mixed->hasMultipleRefs());
    return ret;
  } catch (...) {
    MixedArray::Release(mixed);
    throw;
  }
}
Exemplo n.º 15
0
ArrayData* PackedArray::RemoveInt(ArrayData* adIn, int64_t k, bool copy) {
  assert(checkInvariants(adIn));
  if (size_t(k) < adIn->m_size) {
    // Escalate to mixed for correctness; unset preserves m_nextKI.
    //
    // TODO(#2606310): if we're removing the /last/ element, we
    // probably could stay packed, but this needs to be verified.
    auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(adIn);
    auto pos = mixed->findForRemove(k, false);
    if (validPos(pos)) mixed->erase(pos);
    return mixed;
  }
  // Key doesn't exist---we're still packed.
  return copy ? Copy(adIn) : adIn;
}
Exemplo n.º 16
0
bool PackedArray::AdvanceMArrayIter(ArrayData* ad, MArrayIter& fp) {
  assert(checkInvariants(ad));
  if (fp.getResetFlag()) {
    fp.setResetFlag(false);
    fp.m_pos = ArrayData::invalid_index;
  } else if (fp.m_pos == ArrayData::invalid_index) {
    return false;
  }
  fp.m_pos = IterAdvance(ad, fp.m_pos);
  if (fp.m_pos == ArrayData::invalid_index) {
    return false;
  }
  // To conform to PHP behavior, we need to set the internal
  // cursor to point to the next element.
  ad->m_pos = IterAdvance(ad, fp.m_pos);
  return true;
}
Exemplo n.º 17
0
ArrayData* PackedArray::LvalNew(ArrayData* adIn, Variant*& ret, bool copy) {
  assert(checkInvariants(adIn));
  auto const ad = copy ? CopyAndResizeIfNeeded(adIn)
                       : ResizeIfNeeded(adIn);
  if (UNLIKELY(!ad)) {
    auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(ad);
    return MixedArray::LvalNew(mixed, ret, copy);
  }

  if (ad->m_pos == ArrayData::invalid_index) {
    ad->m_pos = ad->m_size;
  }
  auto& tv = packedData(ad)[ad->m_size++];
  tv.m_type = KindOfNull;
  ret = &tvAsVariant(&tv);
  return ad;
}
Exemplo n.º 18
0
ArrayData* PackedArray::SetRefInt(ArrayData* adIn,
                                  int64_t k,
                                  Variant& v,
                                  bool copy) {
  assert(checkInvariants(adIn));

  if (size_t(k) == adIn->m_size) return AppendRef(adIn, v, copy);
  if (size_t(k) < adIn->m_size) {
    auto const ad = copy ? Copy(adIn) : adIn;
    tvBind(v.asRef(), &packedData(ad)[k]);
    return ad;
  }

  // todo t2606310: key can't exist.  use add/findForNewInsert
  auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(adIn);
  mixed->updateRef(k, v);
  return mixed;
}
Exemplo n.º 19
0
NEVER_INLINE
void PackedArray::Release(ArrayData* ad) {
  assert(checkInvariants(ad));
  assert(ad->isRefCounted());

  auto const size = ad->m_size;
  auto const data = packedData(ad);
  auto const stop = data + size;
  for (auto ptr = data; ptr != stop; ++ptr) {
    tvRefcountedDecRef(*ptr);
  }
  if (UNLIKELY(strong_iterators_exist())) {
    free_strong_iterators(ad);
  }

  auto const cap = ad->m_packedCap;
  MM().objFreeLogged(ad, sizeof(ArrayData) + sizeof(TypedValue) * cap);
}
Exemplo n.º 20
0
ArrayData* PackedArray::Append(ArrayData* adIn, const Variant& v, bool copy) {
  assert(checkInvariants(adIn));
  auto const ad = copy ? CopyAndResizeIfNeeded(adIn)
                       : ResizeIfNeeded(adIn);
  if (UNLIKELY(!ad)) {
    auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(adIn);
    return MixedArray::Append(mixed, v, copy);
  }

  if (ad->m_pos == ArrayData::invalid_index) {
    ad->m_pos = ad->m_size;
  }
  auto& dst = packedData(ad)[ad->m_size++];
  cellDup(*v.asCell(), dst);
  // TODO(#3888164): restructure this so we don't need KindOfUninit checks.
  if (dst.m_type == KindOfUninit) dst.m_type = KindOfNull;
  return ad;
}
Exemplo n.º 21
0
AliasClass AliasClass::unionData(rep newBits, AliasClass a, AliasClass b) {
  assertx(a.m_stag == b.m_stag);
  switch (a.m_stag) {
  case STag::None:
    break;
  case STag::Frame:
  case STag::Prop:
  case STag::ElemI:
  case STag::ElemS:
  case STag::MIState:
  case STag::Ref:
    assertx(!a.equivData(b));
    break;

  case STag::Stack:
    {
      auto const stkA = a.m_stack;
      auto const stkB = b.m_stack;

      // If two AStack have different bases, we can't union them any better
      // than AStackAny, since we don't know where they are relative to each
      // other.  We know two AStacks with different FramePtr bases can't alias,
      // but that doesn't help us represent a union of them.
      if (stkA.base != stkB.base) return AliasClass{newBits};

      // Make a stack range big enough to contain both of them.
      auto const highest = std::max(stkA.offset, stkB.offset);
      auto const lowest = std::min(lowest_offset(stkA), lowest_offset(stkB));
      auto const newStack = AStack {
        stkA.base,
        highest,
        highest - lowest
      };
      auto ret = AliasClass{newBits};
      new (&ret.m_stack) AStack(newStack);
      ret.m_stag = STag::Stack;
      assertx(ret.checkInvariants());
      assertx(a <= ret && b <= ret);
      return ret;
    }
  }

  return AliasClass{newBits};
}
Exemplo n.º 22
0
VectorEpetra<T>::VectorEpetra ( Epetra_Vector const * v )
    :
    super( v->Map().NumGlobalElements(), v->Map().NumMyElements() ),
    M_emap( v->Map() ),
    M_vec ( M_emap )
{
    this->init( M_emap, true );
    //double** V;
    //v->ExtractView(&V);
    //printf("first val : %f\n",V[0][0]);


    M_vec.Update( 1.0,*v,1.0 );

    //for( size_type i = 0; i < this->localSize(); ++i )
    //    {
    //        this->set( i,  V[ 0 ][i] );
    //    }
    checkInvariants();
}
Exemplo n.º 23
0
ArrayData* PackedArray::AppendWithRef(ArrayData* adIn,
                                      const Variant& v,
                                      bool copy) {
  assert(checkInvariants(adIn));
  auto const ad = copy ? CopyAndResizeIfNeeded(adIn)
                       : ResizeIfNeeded(adIn);
  if (UNLIKELY(!ad)) {
    auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(adIn);
    // XXX: constness
    return MixedArray::AppendRef(mixed, const_cast<Variant&>(v), copy);
  }

  if (ad->m_pos == ArrayData::invalid_index) {
    ad->m_pos = ad->m_size;
  }
  auto& dst = packedData(ad)[ad->m_size++];
  dst.m_type = KindOfNull;
  tvAsVariant(&dst).setWithRef(v);
  return ad;
}
Exemplo n.º 24
0
ArrayData* PackedArray::AppendRef(ArrayData* adIn,
                                  Variant& v,
                                  bool copy) {
  assert(checkInvariants(adIn));
  auto const ad = copy ? CopyAndResizeIfNeeded(adIn)
                       : ResizeIfNeeded(adIn);
  if (UNLIKELY(!ad)) {
    auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(adIn);
    return MixedArray::AppendRef(mixed, v, copy);
  }

  if (ad->m_pos == ArrayData::invalid_index) {
    ad->m_pos = ad->m_size;
  }
  auto& dst = packedData(ad)[ad->m_size++];
  dst.m_data.pref = v.asRef()->m_data.pref;
  dst.m_type = KindOfRef;
  dst.m_data.pref->incRefCount();
  return ad;
}
Exemplo n.º 25
0
void Stats::printRome(int depth, std::ostream &out) const {
    DEBUG_SINVARIANT(checkInvariants());

    std::string spaces;
    for(int i = 0; i < depth; i++) {
	spaces += " ";
    }

    out << spaces << "{ count " << countll() << " }\n";
    if (count() > 0) {
	out << spaces << "{ min " << min() << " }\n";
	out << spaces << "{ max " << max() << " }\n";
	out << spaces << "{ mean " << mean() << " }\n";
	out << spaces << "{ stddev " << stddev() << " }\n";
	out << spaces << "{ variance " << variance() << " }\n";
	out << spaces << "{ conf95 " << conf95() << " }\n";
	out << spaces << "{ total " << total() << " }\n";
	out << spaces << "{ total_sq " << total_sq() << " }\n";
    }
}
Exemplo n.º 26
0
AliasIdSet AliasIdSet::operator|=(const AliasIdSet rhs) {
  if (*this == rhs || rhs.empty()) return *this;
  if (empty()) {
    m_bits = rhs.m_bits;
    return *this;
  }

  if (isBigInteger() || rhs.isBigInteger()) {
    // Result contains a big integer, as well as one other integer, so we
    // must use bitset mode.
    setUpperRange();
  }

  if (rhs.isBitset()) {
    // Both are bitsets.
    m_bits |= rhs.m_bits;
  }

  assertx(checkInvariants());
  return *this;
}
Exemplo n.º 27
0
ArrayData* PackedArray::LvalInt(ArrayData* adIn,
                                int64_t k,
                                Variant*& ret,
                                bool copy) {
  assert(checkInvariants(adIn));

  if (LIKELY(size_t(k) < adIn->m_size)) {
    auto const ad = copy ? Copy(adIn) : adIn;
    ret = &tvAsVariant(&packedData(ad)[k]);
    return ad;
  }

  // We can stay packed if the index is m_size, and the operation does
  // the same thing as LvalNew.
  if (size_t(k) == adIn->m_size) return LvalNew(adIn, ret, copy);

  // Promote-to-mixed path, we know the key is new and should be using
  // findForNewInsert but aren't yet TODO(#2606310).
  auto const mixed = copy ? ToMixedCopy(adIn) : ToMixed(adIn);
  return mixed->addLvalImpl(k, ret);
}
bool KisZoomAndPanTest::checkZoomWithWheel(ZoomAndPanTester &t, const QPoint &widgetPoint, qreal zoomCoeff, bool limitedZoom)
{
    QPoint oldOffset = t.coordinatesConverter()->documentOffset();
    QPointF oldPrefCenter = t.canvasController()->preferredCenter();
    qreal oldZoom = t.zoomController()->zoomAction()->effectiveZoom();
    QSize oldDocumentSize = t.canvasController()->documentSize();

    t.canvasController()->zoomRelativeToPoint(widgetPoint, zoomCoeff);

    QPointF newTopLeft = t.coordinatesConverter()->imageRectInWidgetPixels().topLeft();

    return checkInvariants(oldOffset + widgetPoint,
                           oldOffset,
                           oldPrefCenter,
                           oldZoom,
                           t.coordinatesConverter()->documentOffset(),
                           t.canvasController()->preferredCenter(),
                           limitedZoom ? oldZoom : zoomCoeff * oldZoom,
                           newTopLeft,
                           oldDocumentSize);
}
bool KisZoomAndPanTest::checkZoomWithAction(ZoomAndPanTester &t, qreal newZoom, bool limitedZoom)
{
    QPoint oldOffset = t.coordinatesConverter()->documentOffset();
    QPointF oldPrefCenter = t.canvasController()->preferredCenter();
    qreal oldZoom = t.zoomController()->zoomAction()->effectiveZoom();
    QSize oldDocumentSize = t.canvasController()->documentSize();

    t.zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom);

    QPointF newTopLeft = t.coordinatesConverter()->imageRectInWidgetPixels().topLeft();

    return checkInvariants(oldPrefCenter,
                           oldOffset,
                           oldPrefCenter,
                           oldZoom,
                           t.coordinatesConverter()->documentOffset(),
                           t.canvasController()->preferredCenter(),
                           limitedZoom ? oldZoom : newZoom,
                           newTopLeft,
                           oldDocumentSize);
}
Exemplo n.º 30
0
MixedArray* StructArray::ToMixedCopy(const StructArray* old) {
  auto const oldSize = old->size();
  auto const ad      = ToMixedHeader(oldSize + 1);
  auto const srcData = old->data();
  auto shape         = old->shape();

  memset(ad->hashTab(), static_cast<uint8_t>(MixedArray::Empty),
    sizeof(int32_t) * ad->hashSize());

  for (auto i = 0; i < oldSize; ++i) {
    auto key = const_cast<StringData*>(shape->keyForOffset(i));
    auto& e = ad->addKeyAndGetElem(key);
    tvDupFlattenVars(&srcData[i], &e.data, old);
  }

  ad->m_pos = old->m_pos;
  assert(ad->checkInvariants());
  assert(!ad->isFull());
  assert(ad->hasExactlyOneRef());
  return ad;
}