mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-30 09:41:15 +08:00
44 lines
984 B
C
44 lines
984 B
C
#ifndef HALFVEC_H
|
|
#define HALFVEC_H
|
|
|
|
#define __STDC_WANT_IEC_60559_TYPES_EXT__
|
|
|
|
#include <float.h>
|
|
|
|
#include "vector.h"
|
|
|
|
#ifdef __FLT16_MAX__
|
|
#define FLT16_SUPPORT
|
|
#endif
|
|
|
|
#ifdef FLT16_SUPPORT
|
|
#define half _Float16
|
|
#define HALF_MAX FLT16_MAX
|
|
#else
|
|
/* TODO #pragma message("")? */
|
|
#define half uint16
|
|
#define HALF_MAX 65504
|
|
#endif
|
|
|
|
#define HALFVEC_MAX_DIM VECTOR_MAX_DIM
|
|
|
|
#define HALFVEC_SIZE(_dim) (offsetof(HalfVector, x) + sizeof(half)*(_dim))
|
|
#define DatumGetHalfVector(x) ((HalfVector *) PG_DETOAST_DATUM(x))
|
|
#define PG_GETARG_HALFVEC_P(x) DatumGetHalfVector(PG_GETARG_DATUM(x))
|
|
#define PG_RETURN_HALFVEC_P(x) PG_RETURN_POINTER(x)
|
|
|
|
typedef struct HalfVector
|
|
{
|
|
int32 vl_len_; /* varlena header (do not touch directly!) */
|
|
int16 dim; /* number of dimensions */
|
|
int16 unused;
|
|
half x[FLEXIBLE_ARRAY_MEMBER];
|
|
} HalfVector;
|
|
|
|
HalfVector *InitHalfVector(int dim);
|
|
float HalfToFloat4(half num);
|
|
half Float4ToHalf(float num);
|
|
half Float4ToHalfUnchecked(float num);
|
|
|
|
#endif
|