mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 20:08:26 +08:00
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
/*
|
||
* Copyright (c) 2023 hikyuu.org
|
||
*
|
||
* Created on: 2023-10-10
|
||
* Author: fasiondog
|
||
*/
|
||
|
||
#include <boost/python.hpp>
|
||
#include <hikyuu/analysis/combinate.h>
|
||
#include "pybind_utils.h"
|
||
|
||
using namespace boost::python;
|
||
using namespace hku;
|
||
|
||
namespace py = boost::python;
|
||
|
||
static py::list combinate_index(object seq) {
|
||
size_t total = len(seq);
|
||
std::vector<size_t> index_list(total);
|
||
for (size_t i = 0; i < total; ++i) {
|
||
index_list[i] = i;
|
||
}
|
||
|
||
py::list result;
|
||
std::vector<std::vector<size_t>> comb = combinateIndex(index_list);
|
||
for (size_t i = 0, count = comb.size(); i < count; i++) {
|
||
py::list tmp = vector_to_py_list<std::vector<size_t>>(comb[i]);
|
||
result.append(tmp);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
static py::list combinate_indicator(object seq, int n) {
|
||
size_t total = len(seq);
|
||
std::vector<Indicator> inds(total);
|
||
for (size_t i = 0; i < total; ++i) {
|
||
inds[i] = py::extract<Indicator>(seq[i])();
|
||
}
|
||
|
||
auto comb = combinateIndicator(inds, n);
|
||
return vector_to_py_list(comb);
|
||
}
|
||
|
||
void export_analysis() {
|
||
def("combinate_index", combinate_index, R"(combinate_index(seq)
|
||
|
||
获取序列组合的下标索引, 输入序列的长度最大不超过15,否则抛出异常
|
||
|
||
:param seq: 可迭代的 python 对象
|
||
:rtype: list
|
||
|
||
)");
|
||
|
||
def("combinate_ind", combinate_indicator);
|
||
} |