* This function applies an input function on all elements of a sparse data. * The function is modelled after the corresponding function in R. * * @param func The name of the function to apply * @param sdata The input sparse data to be modified * @return A SparseData with the same dimension as sdata but with each element sdata[i] replaced by func(sdata[i]) */
| 1752 | * @return A SparseData with the same dimension as sdata but with each element sdata[i] replaced by func(sdata[i]) |
| 1753 | */ |
| 1754 | SparseData lapply(text * func, SparseData sdata) { |
| 1755 | Oid argtypes[1] = { FLOAT8OID }; |
| 1756 | List * funcname = textToQualifiedNameList(func); |
| 1757 | SparseData result = makeSparseDataCopy(sdata); |
| 1758 | Oid foid = LookupFuncName(funcname, 1, argtypes, false); |
| 1759 | |
| 1760 | lapply_error_checking(foid, funcname); |
| 1761 | |
| 1762 | for (int i=0; i<sdata->unique_value_count; i++) |
| 1763 | valref(float8,result,i) = |
| 1764 | DatumGetFloat8( |
| 1765 | OidFunctionCall1(foid, |
| 1766 | Float8GetDatum(valref(float8,sdata,i)))); |
| 1767 | return result; |
| 1768 | } |
| 1769 | |
| 1770 | /* This function checks for error conditions in lapply() function calls. |
| 1771 | */ |
no test coverage detected