* svec_cast_float8arr - turns a float8 array into an svec */
| 558 | * svec_cast_float8arr - turns a float8 array into an svec |
| 559 | */ |
| 560 | Datum svec_cast_float8arr(PG_FUNCTION_ARGS) { |
| 561 | ArrayType *A_PG = PG_GETARG_ARRAYTYPE_P(0); |
| 562 | SvecType *output_svec; |
| 563 | float8 *array_temp; |
| 564 | bits8 *bitmap; |
| 565 | int bitmask; |
| 566 | int i,j; |
| 567 | |
| 568 | if (ARR_ELEMTYPE(A_PG) != FLOAT8OID) |
| 569 | ereport(ERROR, |
| 570 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 571 | errmsg("svec_cast_float8arr only defined over float8[]"))); |
| 572 | if (ARR_NDIM(A_PG) != 1) |
| 573 | ereport(ERROR, |
| 574 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 575 | errmsg("svec_cast_float8arr only defined over 1 dimensional arrays"))); |
| 576 | |
| 577 | /* Extract array */ |
| 578 | int dimension = ARR_DIMS(A_PG)[0]; |
| 579 | float8 *array = (float8 *)ARR_DATA_PTR(A_PG); |
| 580 | |
| 581 | /* If the data array has NULLs, then we need to create an array to |
| 582 | * store the NULL values as NVP values defined in float_specials.h. |
| 583 | */ |
| 584 | if (ARR_HASNULL(A_PG)) { |
| 585 | array_temp = array; |
| 586 | array = (double *)palloc(sizeof(float8) * dimension); |
| 587 | bitmap = ARR_NULLBITMAP(A_PG); |
| 588 | bitmask = 1; |
| 589 | j = 0; |
| 590 | for (i=0; i<dimension; i++) { |
| 591 | if (bitmap && (*bitmap & bitmask) == 0) // if NULL |
| 592 | array[i] = NVP; |
| 593 | else { |
| 594 | array[i] = array_temp[j]; |
| 595 | j++; |
| 596 | } |
| 597 | if (bitmap) { // advance bitmap pointer |
| 598 | bitmask <<= 1; |
| 599 | if (bitmask == 0x100) { |
| 600 | bitmap++; |
| 601 | bitmask = 1; |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | /* Create the output SVEC */ |
| 608 | SparseData sdata = float8arr_to_sdata(array,dimension); |
| 609 | output_svec = svec_from_sparsedata(sdata,true); |
| 610 | |
| 611 | if (ARR_HASNULL(A_PG)) |
| 612 | pfree(array); |
| 613 | |
| 614 | PG_RETURN_SVECTYPE_P(output_svec); |
| 615 | } |
| 616 | |
| 617 | PG_FUNCTION_INFO_V1( svec_cast_positions_float8arr ); |
nothing calls this directly
no test coverage detected