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

Function IterateFunctionFromCSC

src/c_api.cpp:1812–1875  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1810}
1811
1812std::function<std::pair<int, double>(int idx)>
1813IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* indices, const void* data, int data_type, int64_t ncol_ptr, int64_t , int col_idx) {
1814 CHECK(col_idx < ncol_ptr && col_idx >= 0);
1815 if (data_type == C_API_DTYPE_FLOAT32) {
1816 const float* data_ptr = reinterpret_cast<const float*>(data);
1817 if (col_ptr_type == C_API_DTYPE_INT32) {
1818 const int32_t* ptr_col_ptr = reinterpret_cast<const int32_t*>(col_ptr);
1819 int64_t start = ptr_col_ptr[col_idx];
1820 int64_t end = ptr_col_ptr[col_idx + 1];
1821 return [=] (int offset) {
1822 int64_t i = static_cast<int64_t>(start + offset);
1823 if (i >= end) {
1824 return std::make_pair(-1, 0.0);
1825 }
1826 int idx = static_cast<int>(indices[i]);
1827 double val = static_cast<double>(data_ptr[i]);
1828 return std::make_pair(idx, val);
1829 };
1830 } else if (col_ptr_type == C_API_DTYPE_INT64) {
1831 const int64_t* ptr_col_ptr = reinterpret_cast<const int64_t*>(col_ptr);
1832 int64_t start = ptr_col_ptr[col_idx];
1833 int64_t end = ptr_col_ptr[col_idx + 1];
1834 return [=] (int offset) {
1835 int64_t i = static_cast<int64_t>(start + offset);
1836 if (i >= end) {
1837 return std::make_pair(-1, 0.0);
1838 }
1839 int idx = static_cast<int>(indices[i]);
1840 double val = static_cast<double>(data_ptr[i]);
1841 return std::make_pair(idx, val);
1842 };
1843 }
1844 } else if (data_type == C_API_DTYPE_FLOAT64) {
1845 const double* data_ptr = reinterpret_cast<const double*>(data);
1846 if (col_ptr_type == C_API_DTYPE_INT32) {
1847 const int32_t* ptr_col_ptr = reinterpret_cast<const int32_t*>(col_ptr);
1848 int64_t start = ptr_col_ptr[col_idx];
1849 int64_t end = ptr_col_ptr[col_idx + 1];
1850 return [=] (int offset) {
1851 int64_t i = static_cast<int64_t>(start + offset);
1852 if (i >= end) {
1853 return std::make_pair(-1, 0.0);
1854 }
1855 int idx = static_cast<int>(indices[i]);
1856 double val = static_cast<double>(data_ptr[i]);
1857 return std::make_pair(idx, val);
1858 };
1859 } else if (col_ptr_type == C_API_DTYPE_INT64) {
1860 const int64_t* ptr_col_ptr = reinterpret_cast<const int64_t*>(col_ptr);
1861 int64_t start = ptr_col_ptr[col_idx];
1862 int64_t end = ptr_col_ptr[col_idx + 1];
1863 return [=] (int offset) {
1864 int64_t i = static_cast<int64_t>(start + offset);
1865 if (i >= end) {
1866 return std::make_pair(-1, 0.0);
1867 }
1868 int idx = static_cast<int>(indices[i]);
1869 double val = static_cast<double>(data_ptr[i]);

Callers 1

CSC_RowIteratorMethod · 0.70

Calls 1

make_pairFunction · 0.85

Tested by

no test coverage detected