mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-14 08:36:54 +08:00
Added cast from half to real [skip ci]
This commit is contained in:
@@ -46,6 +46,9 @@ CREATE FUNCTION half_negative_inner_product(half[], half[]) RETURNS float8
|
|||||||
CREATE FUNCTION float4_to_half(real, integer, boolean) RETURNS half
|
CREATE FUNCTION float4_to_half(real, integer, boolean) RETURNS half
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
|
CREATE FUNCTION half_to_float4(half, integer, boolean) RETURNS real
|
||||||
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
CREATE FUNCTION integer_to_half(integer, integer, boolean) RETURNS half
|
CREATE FUNCTION integer_to_half(integer, integer, boolean) RETURNS half
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
@@ -55,6 +58,9 @@ CREATE FUNCTION numeric_to_half(numeric, integer, boolean) RETURNS half
|
|||||||
CREATE CAST (real AS half)
|
CREATE CAST (real AS half)
|
||||||
WITH FUNCTION float4_to_half(real, integer, boolean) AS IMPLICIT;
|
WITH FUNCTION float4_to_half(real, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
|
CREATE CAST (half AS real)
|
||||||
|
WITH FUNCTION half_to_float4(half, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
CREATE CAST (integer AS half)
|
CREATE CAST (integer AS half)
|
||||||
WITH FUNCTION integer_to_half(integer, integer, boolean) AS IMPLICIT;
|
WITH FUNCTION integer_to_half(integer, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
|
|||||||
@@ -344,6 +344,9 @@ CREATE FUNCTION half_negative_inner_product(half[], half[]) RETURNS float8
|
|||||||
CREATE FUNCTION float4_to_half(real, integer, boolean) RETURNS half
|
CREATE FUNCTION float4_to_half(real, integer, boolean) RETURNS half
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
|
CREATE FUNCTION half_to_float4(half, integer, boolean) RETURNS real
|
||||||
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
CREATE FUNCTION integer_to_half(integer, integer, boolean) RETURNS half
|
CREATE FUNCTION integer_to_half(integer, integer, boolean) RETURNS half
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
@@ -355,6 +358,9 @@ CREATE FUNCTION numeric_to_half(numeric, integer, boolean) RETURNS half
|
|||||||
CREATE CAST (real AS half)
|
CREATE CAST (real AS half)
|
||||||
WITH FUNCTION float4_to_half(real, integer, boolean) AS IMPLICIT;
|
WITH FUNCTION float4_to_half(real, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
|
CREATE CAST (half AS real)
|
||||||
|
WITH FUNCTION half_to_float4(half, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
CREATE CAST (integer AS half)
|
CREATE CAST (integer AS half)
|
||||||
WITH FUNCTION integer_to_half(integer, integer, boolean) AS IMPLICIT;
|
WITH FUNCTION integer_to_half(integer, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
|
|||||||
13
src/half.c
13
src/half.c
@@ -439,6 +439,19 @@ float4_to_half(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_HALF(h);
|
PG_RETURN_HALF(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert half to float4
|
||||||
|
*/
|
||||||
|
PGDLLEXPORT PG_FUNCTION_INFO_V1(half_to_float4);
|
||||||
|
Datum
|
||||||
|
half_to_float4(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
half h = PG_GETARG_HALF(0);
|
||||||
|
float f = HalfToFloat4(h);
|
||||||
|
|
||||||
|
PG_RETURN_FLOAT4(f);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the L2 distance between half arrays
|
* Get the L2 distance between half arrays
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -76,6 +76,18 @@ SELECT 'Infinity'::real::half;
|
|||||||
Infinity
|
Infinity
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT '1.5'::half::real;
|
||||||
|
float4
|
||||||
|
--------
|
||||||
|
1.5
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT '{1.5}'::half[]::real[];
|
||||||
|
float4
|
||||||
|
--------
|
||||||
|
{1.5}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT l2_distance('{0,0}'::half[], '{3,4}'::half[]);
|
SELECT l2_distance('{0,0}'::half[], '{3,4}'::half[]);
|
||||||
l2_distance
|
l2_distance
|
||||||
-------------
|
-------------
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ SELECT '65505'::integer::half;
|
|||||||
SELECT 'NaN'::real::half;
|
SELECT 'NaN'::real::half;
|
||||||
SELECT 'Infinity'::real::half;
|
SELECT 'Infinity'::real::half;
|
||||||
|
|
||||||
|
SELECT '1.5'::half::real;
|
||||||
|
SELECT '{1.5}'::half[]::real[];
|
||||||
|
|
||||||
SELECT l2_distance('{0,0}'::half[], '{3,4}'::half[]);
|
SELECT l2_distance('{0,0}'::half[], '{3,4}'::half[]);
|
||||||
SELECT l2_distance('{0,0}'::half[], '{0,1}'::half[]);
|
SELECT l2_distance('{0,0}'::half[], '{0,1}'::half[]);
|
||||||
SELECT l2_distance('{1,2}'::half[], '{3}'::half[]);
|
SELECT l2_distance('{1,2}'::half[], '{3}'::half[]);
|
||||||
|
|||||||
Reference in New Issue
Block a user