MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / RowFunctionFromCSR

Function RowFunctionFromCSR

src/c_api.cpp:1744–1810  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1742}
1743
1744std::function<std::vector<std::pair<int, double>>(int idx)>
1745RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, const void* data, int data_type, int64_t , int64_t ) {
1746 if (data_type == C_API_DTYPE_FLOAT32) {
1747 const float* data_ptr = reinterpret_cast<const float*>(data);
1748 if (indptr_type == C_API_DTYPE_INT32) {
1749 const int32_t* ptr_indptr = reinterpret_cast<const int32_t*>(indptr);
1750 return [=] (int idx) {
1751 std::vector<std::pair<int, double>> ret;
1752 int64_t start = ptr_indptr[idx];
1753 int64_t end = ptr_indptr[idx + 1];
1754 if (end - start > 0) {
1755 ret.reserve(end - start);
1756 }
1757 for (int64_t i = start; i < end; ++i) {
1758 ret.emplace_back(indices[i], data_ptr[i]);
1759 }
1760 return ret;
1761 };
1762 } else if (indptr_type == C_API_DTYPE_INT64) {
1763 const int64_t* ptr_indptr = reinterpret_cast<const int64_t*>(indptr);
1764 return [=] (int idx) {
1765 std::vector<std::pair<int, double>> ret;
1766 int64_t start = ptr_indptr[idx];
1767 int64_t end = ptr_indptr[idx + 1];
1768 if (end - start > 0) {
1769 ret.reserve(end - start);
1770 }
1771 for (int64_t i = start; i < end; ++i) {
1772 ret.emplace_back(indices[i], data_ptr[i]);
1773 }
1774 return ret;
1775 };
1776 }
1777 } else if (data_type == C_API_DTYPE_FLOAT64) {
1778 const double* data_ptr = reinterpret_cast<const double*>(data);
1779 if (indptr_type == C_API_DTYPE_INT32) {
1780 const int32_t* ptr_indptr = reinterpret_cast<const int32_t*>(indptr);
1781 return [=] (int idx) {
1782 std::vector<std::pair<int, double>> ret;
1783 int64_t start = ptr_indptr[idx];
1784 int64_t end = ptr_indptr[idx + 1];
1785 if (end - start > 0) {
1786 ret.reserve(end - start);
1787 }
1788 for (int64_t i = start; i < end; ++i) {
1789 ret.emplace_back(indices[i], data_ptr[i]);
1790 }
1791 return ret;
1792 };
1793 } else if (indptr_type == C_API_DTYPE_INT64) {
1794 const int64_t* ptr_indptr = reinterpret_cast<const int64_t*>(indptr);
1795 return [=] (int idx) {
1796 std::vector<std::pair<int, double>> ret;
1797 int64_t start = ptr_indptr[idx];
1798 int64_t end = ptr_indptr[idx + 1];
1799 if (end - start > 0) {
1800 ret.reserve(end - start);
1801 }

Callers 4

Calls 1

reserveMethod · 0.45

Tested by

no test coverage detected