コード例 #1
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
static void CombinationWithDuplicatedElementsHelper(Array1D &array, int left, int k,
                                                    int times, Array1D &temp, Array2D &result)
{
    assert(left >= 0);

    if (array.size() - left < k) { return; }
    if (k == 0) {
        result.push_back(temp);
        return;
    }
    if (left == 0 || array[left] != array[left - 1]) {
        temp.push_back(array[left]);
        CombinationWithDuplicatedElementsHelper(array, left + 1, k - 1, 1, temp, result);
        temp.pop_back();
        CombinationWithDuplicatedElementsHelper(array, left + 1, k, 1, temp, result);
    }
    else {
        if (temp.size() >= times && temp[temp.size() - times] == array[left]) {
            temp.push_back(array[left]);
            CombinationWithDuplicatedElementsHelper(array, left + 1, k - 1, times + 1, temp, result);
            temp.pop_back();
        }
        CombinationWithDuplicatedElementsHelper(array, left + 1, k, times + 1, temp, result);
    }
}
コード例 #2
0
ファイル: BayesNetwork.C プロジェクト: bmajoros/BioMaLL
BayesNetwork::BayesNetwork(Array1D<Discretizer*> &discretizers)
  : parentIndex(discretizers.size()),
    probTables(discretizers.size()),
    discretizers(discretizers)
{
  parentIndex.setAllTo(-1);
}
コード例 #3
0
vector<Mat> SegmentDataByIDX(const Mat& data, const Mat& idx)
{
    assert(data.type() == CV_32F || data.type() == CV_64F);
    assert(data.rows > 0 && data.cols > 0 && idx.rows > 0 && idx.cols > 0);
    assert(data.cols == idx.cols);
    Array2D idx_hash;
    if (idx.type() != CV_32S) {
        Mat idx_tmp = idx;
        Mat_<int> tmp;
        idx_tmp.convertTo(tmp, CV_32S);
        idx_hash = ComputeIDX(tmp);
    } else{
        idx_hash = ComputeIDX(idx);
    }
    if (idx_hash.empty()) { return vector<Mat>(); }
    vector<Mat> result(idx_hash.size());
    for (int i = 0; i < idx_hash.size(); i++) {
        Array1D cur = idx_hash[i];
        if (cur.empty()) { return vector<Mat>(); }
        Mat temp(data.rows, cur.size(), data.type());
        Mat col(data.rows, 1, data.type());
        for (int j = 0; j < cur.size(); j++) {
            col = temp(Range(0, data.rows), Range(j, j + 1));
            data(Range(0, data.rows), Range(cur[j] - 1, cur[j])).copyTo(col);
        }
        result[i] = temp;
    }
    return result;
}
コード例 #4
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
static void CombinationWithDuplicatedElementsVer2Helper(Array1D &array, int left,
                                                        int k, int times,
                                                        Array1D &temp,
                                                        Array2D &result)
{
    if (array.size() - left < k) { return; }
    if (k == 0) {
        result.push_back(temp);
        return;
    }
    for (int i = left; i <= array.size(); i++) {
        if (i == 0 || array[i] != array[i - 1]) {
            times = 1;
            temp.push_back(array[i]);
            CombinationWithDuplicatedElementsVer2Helper(array, i + 1, k - 1, 1, temp, result);
            temp.pop_back();
        }
        else {
            times++;
            if (temp.size() >= times - 1 && temp[temp.size() - times + 1] == array[i]) {
                temp.push_back(array[i]);
                CombinationWithDuplicatedElementsVer2Helper(array, i + 1, k - 1, times, temp, result);
                temp.pop_back();
            }
        }
    }
}
コード例 #5
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
Array2D CombinationWithDuplicatedElementsByNonRecursion(Array1D array, int K)
{
    Array2D result;
    if (array.empty() || K <= 0) { return result; }
    if (array.size() < K) {
        result.push_back(array);  /** @warning maybe exclude it */
        return result;
    }

    std::sort(array.begin(), array.end());
    result.push_back(Array1D());
    int last = array[0], opt_result_num = 1;
    for (int i = 0; i < array.size(); i++) {
        if (array[i] != last) {
            last = array[i];
            opt_result_num = result.size();
        }
        Array2D::size_type result_size = result.size();
        for (int j = result_size - 1; j >= result_size - opt_result_num; j--) {
            result.push_back(result[j]);
            result.back().push_back(array[i]);
        }
    }
    return result;
}
コード例 #6
0
Array1D<T> zero_pad(const Array1D<T>& v, int n)
{
    it_assert(n>=v.size(), "zero_pad() cannot shrink the vector!");
    Array1D<T> v2(n);
    v2.set_subvector(0, v.size()-1, v);
    if (n > v.size())
	v2.set_subvector(v.size(), n-1, T(0));

    return v2;
}
コード例 #7
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
Array2D CombinationVer2(Array1D array, int K)
{
    Array2D result;
    if (array.empty() || K <= 0) { return result; }
    if (array.size() < K) {
        result.push_back(array);  /** @warning maybe exclude it */
        return result;
    }
    Array1D temp;
    CombinationVer2Helper(array, 0, array.size() - 1, K, temp, result);
}
コード例 #8
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
Array2D CombinationByDecrease(Array1D array, int K)
{
    Array2D result;
    if (array.empty() || K <= 0) { return result; }
    if (array.size() < K) {
        result.push_back(array);  /** @warning maybe exclude it */
        return result;
    }
    Array1D temp(K);
    CombinationByDecreaseHelper(array, array.size(), K, temp, result);
}
コード例 #9
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
Array2D Combination(Array1D array, int K) {
    Array2D result;
    if (array.empty() || K <= 0) { return result; }
    if (array.size() < K) {
        result.push_back(array);
        return result;
    }
    Array1D temp;
    CombinationHelper(array, 0, array.size() - 1, K, temp, result);
    return result;
}
コード例 #10
0
 void
 CDFBasis<d,dt>::evaluate
 (const unsigned int derivative,
  const RIndex& lambda,
  const Array1D<double>& points, Array1D<double>& values)
 {
   values.resize(points.size());
   for (unsigned int i(0); i < values.size(); i++) {
     values[i] = evaluate(derivative, lambda, points[i]);
   }
 }
コード例 #11
0
ファイル: permutation.cpp プロジェクト: xiejianhe/FindWork
static void PermutationHelper(Array1D &array, int index, Array2D &result)
{
    if (index == array.size()) {
        result.push_back(array);
        return;
    }
    for (int i = index; i < array.size(); ++i) {
        std::swap(array[index], array[i]);
        PermutationHelper(array, index + 1, result);
        std::swap(array[index], array[i]);
    }
}
コード例 #12
0
Array1D<T> cross(const Array1D<T>& v1, const Array1D<T>& v2)
{
    it_assert( v1.size() == 3 && v2.size() == 3, "cross: vectors should be of size 3");

    Array1D<T> r(3);

    r(0) = v1(1) * v2(2) - v1(2) * v2(1);
    r(1) = v1(2) * v2(0) - v1(0) * v2(2);
    r(2) = v1(0) * v2(1) - v1(1) * v2(0);
    
    return r;
}
コード例 #13
0
ファイル: permutation.cpp プロジェクト: xiejianhe/FindWork
static void PermutationUniqueHelper(Array1D &array, int index, Array2D &result)
{
    if (index == array.size()) {
        result.push_back(array);
        return;
    }
    for (int i = index; i < array.size(); i++) {
        if (HasSameElement(array, index, i, array[i])) {
            std::swap(array[index], array[i]);
            PermutationUniqueHelper(array, index + 1, result);
            std::swap(array[index], array[i]);
        }
    }
}
コード例 #14
0
ファイル: AlignmentBuilder.C プロジェクト: bmajoros/alignment
int AlignmentBuilder::getAlignmentLength(
  Array1D<Poset<ResidueAddress>::Vertex<ResidueAddress>*> &roots)
{
  int n=roots.size(), r=0;
  for(int i=0 ; i<n ; ++i)
    if(roots[i]->getData().hasLeafDescendents() || wantOrphans) ++r;
  return r;
}
コード例 #15
0
ファイル: gl_2_0.cpp プロジェクト: gatgui/pygl
static PyObject* py_glDrawBuffers(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 1);
  Array1D<Enum> buffers;
  if (buffers.fromPy(PyTuple_GetItem(args, 0))) {
    glDrawBuffers(buffers.size(), buffers);
  }
  Py_RETURN_NONE;
}
コード例 #16
0
ファイル: gl_2_0.cpp プロジェクト: gatgui/pygl
static PyObject* py_glShaderSource(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 2);
  Uint shader(PyTuple_GetItem(args, 0));
  Array1D<String> strings;
  if (strings.fromPy(PyTuple_GetItem(args, 1))) {
    glShaderSource(shader, strings.size(), strings, 0);
  }
  Py_RETURN_NONE;
}
コード例 #17
0
ファイル: score-content.C プロジェクト: ReddyLab/FBI
void Application::write(Array1D<double> &array,File &os,ostream &textStream)
{
  int L=array.size();
  os<<L;
  if(wantText) textStream<<L<<endl;
  for(int i=0 ; i<L ; ++i) {
    os<<array[i];
    if(wantText) textStream<<array[i]<<endl;
  }
}
コード例 #18
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
Array2D CombinationWithDuplicatedElementsVer2(Array1D array, int K)
{
    Array2D result;
    if (array.empty() || K <= 0) { return result; }
    if (array.size() < K) {
        result.push_back(array);  /** @warning maybe exclude it */
        return result;
    }
    Array1D temp;

}
コード例 #19
0
const Array2D inverse_quantise_transform_np(const Array2D& qCoeffs,
                                            const Array2D& qIndices,
                                            const Array1D& qMatrix) {
  // TO DO: Check numberOfSubbands=3n+1 ?
  BlockVector aQIndices(qMatrix.ranges());
  const int numberOfSubbands = qMatrix.size();
  for (char band=0; band<numberOfSubbands; ++band) {
    aQIndices[band] = adjust_quant_indices(qIndices, qMatrix[band]);
  }
  return inverse_quantise_subbands_np(qCoeffs, aQIndices);
}
コード例 #20
0
ファイル: permutation.cpp プロジェクト: xiejianhe/FindWork
/**
 * @brief find all permutation of array
 * @brief array has some repeating elements
 */
Array2D PermutationUnique(Array1D array)
{
    Array2D result;
    if (array.empty()) { return result; }
    if (array.size() == 1) {
        result.push_back(array);
        return result;
    }
    PermutationUniqueHelper(array, 0, result);
    return result;
}
コード例 #21
0
const Array2D inverse_quantise_transform_np(const Array2D& qCoeffs,
                                            const int qIndex,
                                            const Array1D& qMatrix) {
  // TO DO: Check numberOfSubbands=3n+1 ?
  const int numberOfSubbands = qMatrix.size();
  const int waveletDepth = (numberOfSubbands-1)/3;
  BlockVector subbands = split_into_subbands(qCoeffs, waveletDepth);
  for (int band=0; band<numberOfSubbands; ++band) {
    const int aQIndex = adjust_quant_index(qIndex, qMatrix[band]);
    subbands[band] = inverse_quantise_block(subbands[band], aQIndex);
  }
  return merge_subbands(subbands);
}
コード例 #22
0
double Application::recompute(double t)
{
  SubstitutionMatrix &M=*Q->instantiate(t);
  Array1D<double> eq;
  M.getEqFreqs(eq);
  int n=eq.size();
  double r=0.0;
  for(BOOM::Symbol s=0 ; s<n ; ++s) {
    r+=eq[s]*M(s,s);
  }
  delete &M;
  return r;
}
コード例 #23
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
Array2D CombinationByNonRecursion(Array1D array, int K)
{
    Array2D result;
    if (array.empty() || K <= 0) { return result; }
    if (array.size() < K) {
        result.push_back(array);  /** @warning maybe exclude it */
        return result;
    }
    Array1D cur(1);
    for (int i = 1; i <= array.size(); i++) {
        Array1D::size_type size = cur.size();
        Array1D temp;
        /** @bug has some problems */
        for (int j = 0; j < size; j++) {
            temp.push_back(cur[j]);
            temp.push_back(array[i]);
            if (temp.size() == K) { result.push_back(temp); }
            else { cur.push_back(array[i]); }
        }
    }
    return result;
}
コード例 #24
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
Array2D CombinationByBinary(Array1D array, int K)
{
    Array2D result;
    if (array.empty() || K <= 0) { return result; }
    if (array.size() < K) {
        result.push_back(array);  /** @warning maybe exclude it */
        return result;
    }
    /** @warning sort or not */
    Array1D temp;
    int begin = (1 << K) - 1, end = (1 << array.size()) - (1 << (array.size() - K));
    for (int bit = begin; bit <= end; bit = NextBit(bit)) {
        temp.clear();
        for (int i = 0; i < array.size(); i++) {
            if (bit & (1 << i)) {
                temp.push_back(array[i]);
            }
        }
        result.push_back(temp);
    }
    return result;
}
コード例 #25
0
ファイル: combination.cpp プロジェクト: xiejianhe/FindWork
static void CombinationByIncreaseHelper(Array1D &array, int left, int count,
                                        Array1D &temp, Array2D &result)
{
    for (int i = left; i < array.size() + 1 - count; i++) {
        temp[count - 1] = array[i];
        if (count - 1 == 0) {
            result.push_back(temp);
        }
        else {
            CombinationByIncreaseHelper(array, i + 1, count - 1, temp, result);
        }
    }
}
コード例 #26
0
ファイル: permutation.cpp プロジェクト: xiejianhe/FindWork
bool NextPermutation(Array1D &array)
{
    Array1D::size_type size = array.size();
    if (size <= 1) { return false; }
    for (int i = size - 2, ii = size - 1; i >= 0; i--, ii--) {
        if (array[i] < array[ii]) {
            int j = size - 1;
            while (array[j] <= array[i]) { j--; }
            std::swap(array[i], array[j]);
            std::reverse(array.begin() + ii, array.end());
            return true;
        }
    }
    std::reverse(array.begin(), array.end());
    return false;
}
  void gramSchmidtProcess(Array1D<V>& vectors)
  {
    V* vtmp;
    unsigned int i, n;

    for (n = 0; n < vectors.size(); n++) {
      // orthogonalize the n-th vector respective to the previous ones
      for (i = 0; i < n; i++) {
        vtmp = new V(vectors[i]);
        vtmp->scale(-vectors[i].inner_product(vectors[n]));
        vectors[n].add(*vtmp);
        delete vtmp;
        vtmp = NULL;
      }
      // norm the n-th vector
      vectors[n].scale(1/sqrt(vectors[n].inner_product(vectors[n])));
    }
  }
コード例 #28
0
Array1D<T> zero_pad(const Array1D<T>& v)
{
    int n = pow2(needed_bits(v.size()));
    
    return n==v.size() ? v : zero_pad(v, n);
}
コード例 #29
0
void sort(Array1D<T>& data)
{
    QS(0,data.size()-1,data);
}