Exemplo n.º 1
0
void test_dynamic_view_sort(unsigned int n )
{
  typedef typename ExecutionSpace::memory_space memory_space ;
  typedef Kokkos::Experimental::DynamicView<KeyType*,ExecutionSpace> KeyDynamicViewType;
  typedef Kokkos::View<KeyType*,ExecutionSpace> KeyViewType;

  const size_t upper_bound = 2 * n ;

  typename KeyDynamicViewType::memory_pool
    pool( memory_space()
        , n * sizeof(KeyType) * 1.2
        ,     500 /* min block size in bytes */
        ,   30000 /* max block size in bytes */
        , 1000000 /* min superblock size in bytes */
        );

  KeyDynamicViewType keys("Keys",pool,upper_bound);

  keys.resize_serial(n);

  KeyViewType keys_view("KeysTmp", n );

  // Test sorting array with all numbers equal
  Kokkos::deep_copy(keys_view,KeyType(1));
  Kokkos::Experimental::deep_copy(keys,keys_view);
  Kokkos::sort(keys, 0 /* begin */ , n /* end */ );

  Kokkos::Random_XorShift64_Pool<ExecutionSpace> g(1931);
  Kokkos::fill_random(keys_view,g,Kokkos::Random_XorShift64_Pool<ExecutionSpace>::generator_type::MAX_URAND);

  Kokkos::Experimental::deep_copy(keys,keys_view);

  double sum_before = 0.0;
  double sum_after = 0.0;
  unsigned int sort_fails = 0;

  Kokkos::parallel_reduce(n,sum<ExecutionSpace, KeyType>(keys_view),sum_before);

  Kokkos::sort(keys, 0 /* begin */ , n /* end */ );

  Kokkos::Experimental::deep_copy( keys_view , keys );

  Kokkos::parallel_reduce(n,sum<ExecutionSpace, KeyType>(keys_view),sum_after);
  Kokkos::parallel_reduce(n-1,is_sorted_struct<ExecutionSpace, KeyType>(keys_view),sort_fails);

  double ratio = sum_before/sum_after;
  double epsilon = 1e-10;
  unsigned int equal_sum = (ratio > (1.0-epsilon)) && (ratio < (1.0+epsilon)) ? 1 : 0;

  if ( sort_fails != 0 || equal_sum != 1 ) {
    std::cout << " N = " << n
              << " ; sum_before = " << sum_before
              << " ; sum_after = " << sum_after
              << " ; ratio = " << ratio
              << std::endl ;
  }

  ASSERT_EQ(sort_fails,0);
  ASSERT_EQ(equal_sum,1);
}
Exemplo n.º 2
0
DecodeOrderSampleMap::reverse_iterator_range DecodeOrderSampleMap::findDependentSamples(MediaSample* sample)
{
    ASSERT(sample);
    reverse_iterator currentDecodeIter = reverseFindSampleWithDecodeKey(KeyType(sample->decodeTime(), sample->presentationTime()));
    reverse_iterator nextSyncSample = findSyncSamplePriorToDecodeIterator(currentDecodeIter);
    return reverse_iterator_range(currentDecodeIter, nextSyncSample);
}
Exemplo n.º 3
0
void test_1D_sort(unsigned int n,bool force_kokkos) {
  typedef Kokkos::View<KeyType*,ExecutionSpace> KeyViewType;
  KeyViewType keys("Keys",n);

  // Test sorting array with all numbers equal
  Kokkos::deep_copy(keys,KeyType(1));
  Kokkos::sort(keys,force_kokkos);

  Kokkos::Random_XorShift64_Pool<ExecutionSpace> g(1931);
  Kokkos::fill_random(keys,g,Kokkos::Random_XorShift64_Pool<ExecutionSpace>::generator_type::MAX_URAND);

  double sum_before = 0.0;
  double sum_after = 0.0;
  unsigned int sort_fails = 0;

  Kokkos::parallel_reduce(n,sum<ExecutionSpace, KeyType>(keys),sum_before);

  Kokkos::sort(keys,force_kokkos);

  Kokkos::parallel_reduce(n,sum<ExecutionSpace, KeyType>(keys),sum_after);
  Kokkos::parallel_reduce(n-1,is_sorted_struct<ExecutionSpace, KeyType>(keys),sort_fails);

  double ratio = sum_before/sum_after;
  double epsilon = 1e-10;
  unsigned int equal_sum = (ratio > (1.0-epsilon)) && (ratio < (1.0+epsilon)) ? 1 : 0;

  ASSERT_EQ(sort_fails,0);
  ASSERT_EQ(equal_sum,1);
}
Exemplo n.º 4
0
static int BdfP_FinishTextField(struct bdf_dlg *bd) {
    if ( bd->active ) {
	char *text = GGadgetGetTitle8(bd->tf);
	char *pt, *end;
	int val;
	struct bdf_dlg_font *cur = bd->cur;
	BDFFont *bdf = cur->bdf;

	for ( pt=text; *pt; ++pt )
	    if ( *pt&0x80 ) {
		ff_post_error(_("Not ASCII"),_("All characters in the value must be in ASCII"));
		free(text);
return( false );
	    }
	val = strtol(text,&end,10);
	if ( NumericKey(bdf->props[cur->sel_prop].name) ) {
	    if ( *end!='\0' ) {
		ff_post_error(_("Bad Number"),_("Must be a number"));
		free(text);
return( false );
	    }
	}
	if ( (bdf->props[cur->sel_prop].type&~prt_property)==prt_string ||
		(bdf->props[cur->sel_prop].type&~prt_property)==prt_atom )
	    free(bdf->props[cur->sel_prop].u.str);
	if ( UnknownKey(bdf->props[cur->sel_prop].name) ) {
	    if ( *end!='\0' ) {
		bdf->props[cur->sel_prop].type = prt_string | prt_property;
		bdf->props[cur->sel_prop].u.str = copy(text);
	    } else {
		if ( bdf->props[cur->sel_prop].type != (prt_uint | prt_property ))
		    bdf->props[cur->sel_prop].type = prt_int | prt_property;
		bdf->props[cur->sel_prop].u.val = val;
	    }
	} else if ( NumericKey(bdf->props[cur->sel_prop].name) ) {
	    bdf->props[cur->sel_prop].type = KeyType(bdf->props[cur->sel_prop].name);
	    bdf->props[cur->sel_prop].u.val = val;
	} else {
	    bdf->props[cur->sel_prop].type = KeyType(bdf->props[cur->sel_prop].name);
	    bdf->props[cur->sel_prop].u.str = copy(text);
	}
	free(text);	    
	bd->active = false;
	GGadgetSetVisible(bd->tf,false);
    }
return( true );
}
Exemplo n.º 5
0
 BasicPtree() :
     _key(KeyType()),
     _data(DataType()),
     _children(ChildrenList()),
     _meta_data(NULL),
     _data_cmp(PredEqualData()),
     _key_cmp(PredEqualKey())
      {}
Exemplo n.º 6
0
std::wstring Dictionary::Lookup(const std::string& section, const std::string& key) const
{
  DataType::const_iterator it = data.find(KeyType(section, key));
  if (it == data.end())
    return L"### MISSING STRING [" + ToUtf16String(section) + L", " + ToUtf16String(key) + L"] ###";

  return it->second;
}
Exemplo n.º 7
0
void BaseWindow::SetHandle(HWND handle) {
    ASSERT(handle != NULL);
    mHandle = handle;

    KeyType const key = KeyType(handle);
    Pair const new_mapping(key, this); 
    InsertResult const ins_result = msMap.insert(new_mapping);
    bool const success = ins_result.second;
    ASSERT(success);
}
Exemplo n.º 8
0
 inline void extendTo(KeyType x) {
    Int i;
    if(Graph1d<ValueType, KeyType, Int>::N<1)
      {
	Graph1d<ValueType, KeyType, Int>::N=1;
	Graph1d<ValueType, KeyType, Int>::minX=x-0.5*Graph1d<ValueType, KeyType, Int>::delta;
	Graph1d<ValueType, KeyType, Int>::maxX=Graph1d<ValueType, KeyType, Int>::minX+Graph1d<ValueType, KeyType, Int>::delta;
        Graph1d<ValueType, KeyType, Int>::y.resize(Graph1d<ValueType, KeyType, Int>::N);
        if(k>0)
        {
          M.resize(Graph1d<ValueType, KeyType, Int>::N);
          for(int i=0; i<k; i++) m[i].resize(Graph1d<ValueType, KeyType, Int>::N);
        }
      } else
      {
	i=this->idx(x);
	if(i<0)
	  {
            Graph1d<ValueType, KeyType, Int>::y.resize(Graph1d<ValueType, KeyType, Int>::N-i);
            if(k>0)
            {
              M.resize(Graph1d<ValueType, KeyType, Int>::N-i);
              for(int ii=0; ii<k; ii++) m[ii].resize(Graph1d<ValueType, KeyType, Int>::N-i);
            }
	    for(Int j=Graph1d<ValueType, KeyType, Int>::N-1; j>=0; j--)
            {
              Graph1d<ValueType, KeyType, Int>::y[j-i]=Graph1d<ValueType, KeyType, Int>::y[j];
              Graph1d<ValueType, KeyType, Int>::y[j]=ValueType(0);
              if(k>0)
              {
                M[j-i]=M[j];
                M[j]=0;
                for(int ii=0; ii<k; ii++)
                {
                  m[ii][j-i]=m[ii][j];
                  m[ii][j]=ValueType(0);
                }
              }
            }
	    Graph1d<ValueType, KeyType, Int>::N=Graph1d<ValueType, KeyType, Int>::N-i; Graph1d<ValueType, KeyType, Int>::minX+=KeyType(i)*Graph1d<ValueType, KeyType, Int>::delta;
	    i=0;
	  } else if(i>=Graph1d<ValueType, KeyType, Int>::N)
	  {
	    Int n=i-Graph1d<ValueType, KeyType, Int>::N+1;
            Graph1d<ValueType, KeyType, Int>::y.resize(i+1,ValueType(0));
            if(k>0)
            {
              M.resize(i+1,0);
              for(int ii=0; ii<k; ii++) m[ii].resize(i+1,ValueType(0));
            }
	    Graph1d<ValueType, KeyType, Int>::N=i+1;
            Graph1d<ValueType, KeyType, Int>::maxX+=KeyType(n)*Graph1d<ValueType, KeyType, Int>::delta;
	  }
      } }
Exemplo n.º 9
0
Parameters::ValueType& Parameters::get(KeyViewType name) noexcept
{
    auto ptr = find(m_data, name);

    if (ptr)
        return *ptr;

    // Insert
    m_data.emplace_back(Record{KeyType(name), ValueType{}});

    return m_data.back().value;
}
Exemplo n.º 10
0
DecodeOrderSampleMap::reverse_iterator DecodeOrderSampleMap::findSyncSamplePriorToPresentationTime(const MediaTime& time, const MediaTime& threshold)
{
    PresentationOrderSampleMap::reverse_iterator reverseCurrentSamplePTS = m_presentationOrder.reverseFindSampleBeforePresentationTime(time);
    if (reverseCurrentSamplePTS == m_presentationOrder.rend())
        return rend();

    const RefPtr<MediaSample>& sample = reverseCurrentSamplePTS->second;
    reverse_iterator reverseCurrentSampleDTS = reverseFindSampleWithDecodeKey(KeyType(sample->decodeTime(), sample->presentationTime()));

    reverse_iterator foundSample = findSyncSamplePriorToDecodeIterator(reverseCurrentSampleDTS);
    if (foundSample == rend())
        return rend();
    if (foundSample->second->presentationTime() < time - threshold)
        return rend();
    return foundSample;
}
Exemplo n.º 11
0
/* static */ BaseWindow* BaseWindow::Lookup(HWND handle) {
    KeyType const key = KeyType(handle);
    ConstIterator const i_window = msMap.find(key);

    BaseWindow* result = NULL;
    if (i_window != msMap.end()) {
        result = i_window->second;
        ASSERT(result != NULL);
    } else if (mspNewlyCreatedWindow != NULL) {
        result = mspNewlyCreatedWindow;
        mspNewlyCreatedWindow = NULL;
        result->SetHandle(handle);
    }

    return result;
}
Exemplo n.º 12
0
DecodeOrderSampleMap::iterator DecodeOrderSampleMap::findSyncSampleAfterPresentationTime(const MediaTime& time, const MediaTime& threshold)
{
    PresentationOrderSampleMap::iterator currentSamplePTS = m_presentationOrder.findSampleOnOrAfterPresentationTime(time);
    if (currentSamplePTS == m_presentationOrder.end())
        return end();

    const RefPtr<MediaSample>& sample = currentSamplePTS->second;
    iterator currentSampleDTS = findSampleWithDecodeKey(KeyType(sample->decodeTime(), sample->presentationTime()));
    
    MediaTime upperBound = time + threshold;
    iterator foundSample = std::find_if(currentSampleDTS, end(), SampleIsRandomAccess());
    if (foundSample == end())
        return end();
    if (foundSample->second->presentationTime() > upperBound)
        return end();
    return foundSample;
}
Exemplo n.º 13
0
void tst_QCache::axioms_on_key_type()
{
    QCache<KeyType, ValueType> foo;
    foo.setMaxCost(1);
    foo.clear();
    foo.insert(KeyType(123), new ValueType(123));
    foo.object(KeyType(123));
    foo.contains(KeyType(456));
    foo[KeyType(456)];
    foo.remove(KeyType(456));
    foo.remove(KeyType(123));
    foo.take(KeyType(789));
// If this fails, contact the maintaner
    QVERIFY(sizeof(QHash<int, int>) == sizeof(void *));
}
Exemplo n.º 14
0
      static Result apply(const std::string& prefix_str, const std::string& data_str)
      {
         using data_type = typename KeyType::data_type;
         using wrapper = checksummed_data<data_type>;
         constexpr auto prefix = Prefixes[Position];

         if (prefix == prefix_str) {
            auto bin = fc::from_base58(data_str);
            FC_ASSERT(bin.size() >= sizeof(data_type) + sizeof(uint32_t));
            auto wrapped = fc::raw::unpack<wrapper>(bin);
            auto checksum = wrapper::calculate_checksum(wrapped.data, prefix);
            FC_ASSERT(checksum == wrapped.check);
            return Result(KeyType(wrapped.data));
         }

         return base58_str_parser_impl<Result, Prefixes, Position + 1, Rem...>::apply(prefix_str, data_str);
      }
Exemplo n.º 15
0
// restore from serialization
void
ReadGroupStatsSet::
load(
    const char* filename)
{
    clear();

    assert(NULL != filename);
    std::ifstream ifs(filename);
    boost::archive::xml_iarchive ia(ifs);

    int numGroups;
    ia >> boost::serialization::make_nvp("numGroups", numGroups);
    ReadGroupStatsExporter se;
    for (int i=0; i<numGroups; i++)
    {
        ia >> boost::serialization::make_nvp("bogus", se);

        setStats(KeyType(se.bamFile.c_str(), se.readGroup.c_str()), se.groupStats);
    }
}
Exemplo n.º 16
0
bool Dictionary::ReadDictionary(const std::wstring& basePath, const std::wstring& locale)
{
  std::ifstream stream(basePath + locale + L".ini");
  if (stream.fail())
    return false;

  std::string section;
  while (!stream.eof())
  {
    std::string line;
    std::getline(stream, line);
    if (stream.fail())
      return false;

    line = ::TrimString(line);
    if (line.size() >= 2 && line[0] == '[' && line[line.size() - 1] == ']')
    {
      // Section header
      section = line.substr(1, line.size() - 2);
    }
    else if (line.size() >= 1 && line[0] == '#')
    {
      // Comment
      continue;
    }
    else
    {
      // Value
      size_t pos = line.find('=');
      if (pos != std::string::npos)
      {
        std::string key = ::TrimString(line.substr(0, pos));
        std::string value = ::TrimString(line.substr(pos + 1));
        data[KeyType(section, key)] = ToUtf16String(value);
      }
    }
  }
  return true;
}
Exemplo n.º 17
0
 explicit lru_list(const KeyType& k = KeyType(), const ValueType &v = ValueType()) : key(k), value(v) {
 }
Exemplo n.º 18
0
 KeyType          GetKeyType()    const { return KeyType(keyOID_); }
Exemplo n.º 19
0
VBM3D_Process_Base::Pos3PairCode VBM3D_Process_Base::BlockMatching(
    const std::vector<const FLType *> &ref, PCType j, PCType i) const
{
    // Skip block matching if GroupSize is 1 or thMSE is not positive,
    // and take the reference block as the only element in the group
    if (d.para.GroupSize == 1 || d.para.thMSE <= 0)
    {
        return Pos3PairCode(1, Pos3Pair(KeyType(0), Pos3Type(cur, j, i)));
    }

    int f;
    Pos3PairCode matchCode;
    PosPairCode frameMatch;
    PosCode prePosCode;

    // Get reference block from the reference plane in current frame
    block_type refBlock(ref[cur], ref_stride[0], d.para.BlockSize, d.para.BlockSize, PosType(j, i));

    // Block Matching in current frame
    f = cur;

    frameMatch = refBlock.BlockMatchingMulti(ref[f],
        ref_height[0], ref_width[0], ref_stride[0], FLType(1),
        d.para.BMrange, d.para.BMstep, d.para.thMSE, 1, d.para.GroupSize, true);

    matchCode.resize(matchCode.size() + frameMatch.size());
    std::transform(frameMatch.begin(), frameMatch.end(),
        matchCode.end() - frameMatch.size(), [&](const PosPair &x)
    {
        return Pos3Pair(x.first, Pos3Type(x.second, f));
    });

    PCType nextPosNum = Min(d.para.PSnum, static_cast<PCType>(frameMatch.size()));
    PosCode curPosCode(nextPosNum);
    std::transform(frameMatch.begin(), frameMatch.begin() + nextPosNum,
        curPosCode.begin(), [](const PosPair &x)
    {
        return x.second;
    });

    PosCode curSearchPos = refBlock.GenSearchPos(curPosCode,
        ref_height[0], ref_width[0], d.para.PSrange, d.para.PSstep);

    // Predictive Search Block Matching in backward frames
    f = cur - 1;

    for (; f >= 0; --f)
    {
        if (f == cur - 1)
        {
            frameMatch = refBlock.BlockMatchingMulti(ref[f], ref_stride[0], FLType(1),
                curSearchPos, d.para.thMSE, d.para.GroupSize, true);
        }
        else
        {
            PCType nextPosNum = Min(d.para.PSnum, static_cast<PCType>(frameMatch.size()));
            prePosCode.resize(nextPosNum);
            std::transform(frameMatch.begin(), frameMatch.begin() + nextPosNum,
                prePosCode.begin(), [](const PosPair &x)
            {
                return x.second;
            });

            PosCode searchPos = refBlock.GenSearchPos(prePosCode,
                ref_height[0], ref_width[0], d.para.PSrange, d.para.PSstep);
            frameMatch = refBlock.BlockMatchingMulti(ref[f], ref_stride[0], FLType(1),
                searchPos, d.para.thMSE, d.para.GroupSize, true);
        }

        matchCode.resize(matchCode.size() + frameMatch.size());
        std::transform(frameMatch.begin(), frameMatch.end(),
            matchCode.end() - frameMatch.size(), [&](const PosPair &x)
        {
            return Pos3Pair(x.first, Pos3Type(x.second, f));
        });
    }

    // Predictive Search Block Matching in forward frames
    f = cur + 1;

    for (; f < frames; ++f)
    {
        if (f == cur + 1)
        {
            frameMatch = refBlock.BlockMatchingMulti(ref[f], ref_stride[0], FLType(1),
                curSearchPos, d.para.thMSE, d.para.GroupSize, true);
        }
        else
        {
            PCType nextPosNum = Min(d.para.PSnum, static_cast<PCType>(frameMatch.size()));
            prePosCode.resize(nextPosNum);
            std::transform(frameMatch.begin(), frameMatch.begin() + nextPosNum,
                prePosCode.begin(), [](const PosPair &x)
            {
                return x.second;
            });

            PosCode searchPos = refBlock.GenSearchPos(prePosCode,
                ref_height[0], ref_width[0], d.para.PSrange, d.para.PSstep);
            frameMatch = refBlock.BlockMatchingMulti(ref[f], ref_stride[0], FLType(1),
                searchPos, d.para.thMSE, d.para.GroupSize, true);
        }

        matchCode.resize(matchCode.size() + frameMatch.size());
        std::transform(frameMatch.begin(), frameMatch.end(),
            matchCode.end() - frameMatch.size(), [&](const PosPair &x)
        {
            return Pos3Pair(x.first, Pos3Type(x.second, f));
        });
    }

    // Limit the number of matched code to GroupSize
    if (d.para.GroupSize > 0 && static_cast<PCType>(matchCode.size()) > d.para.GroupSize)
    {
        std::partial_sort(matchCode.begin() + 1, matchCode.begin() + d.para.GroupSize, matchCode.end());
        matchCode.resize(d.para.GroupSize);
    }

    return matchCode;
}