MCPcopy Create free account
hub / github.com/apache/madlib / svec_mean_final

Function svec_mean_final

methods/svec_util/src/pg_gp/svec_util.c:1375–1406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1373 */
1374PG_FUNCTION_INFO_V1( svec_mean_final );
1375Datum svec_mean_final( PG_FUNCTION_ARGS)
1376{
1377 /* Validate state input*/
1378 if PG_ARGISNULL(0) {
1379 PG_RETURN_NULL();
1380 }
1381
1382 SvecType *svec;
1383 ArrayType *transarray;
1384
1385 /* Read the argument */
1386 if (fcinfo->context && IsA(fcinfo->context, AggState))
1387 transarray = PG_GETARG_ARRAYTYPE_P(0);
1388 else
1389 transarray = PG_GETARG_ARRAYTYPE_P_COPY(0);
1390
1391 /* Define the array */
1392 float8 *array = (float8 *)ARR_DATA_PTR(transarray);
1393 int dim = ARR_DIMS(transarray)[0];
1394
1395 /* Divide */
1396 for (int i=0; i<dim-1; i++) {
1397 array[i] = array[i] / array[dim-1];
1398 }
1399
1400 /* Create the output SVEC */
1401 SparseData sdata = float8arr_to_sdata(array,dim-1);
1402 svec = svec_from_sparsedata(sdata,true);
1403
1404 PG_RETURN_SVECTYPE_P(svec);
1405
1406}

Callers

nothing calls this directly

Calls 2

float8arr_to_sdataFunction · 0.85
svec_from_sparsedataFunction · 0.85

Tested by

no test coverage detected