本文整理汇总了C++中ARR_LBOUND函数的典型用法代码示例。如果您正苦于以下问题:C++ ARR_LBOUND函数的具体用法?C++ ARR_LBOUND怎么用?C++ ARR_LBOUND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ARR_LBOUND函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: array_prepend
/*-----------------------------------------------------------------------------
* array_prepend :
* push an element onto the front of a one-dimensional array
*----------------------------------------------------------------------------
*/
Datum
array_prepend(PG_FUNCTION_ARGS)
{
ArrayType *v;
Datum newelem;
bool isNull;
ArrayType *result;
int *lb;
int indx;
ArrayMetaState *my_extra;
isNull = PG_ARGISNULL(0);
if (isNull)
newelem = (Datum) 0;
else
newelem = PG_GETARG_DATUM(0);
v = fetch_array_arg_replace_nulls(fcinfo, 1);
if (ARR_NDIM(v) == 1)
{
/* prepend newelem */
lb = ARR_LBOUND(v);
indx = lb[0] - 1;
/* overflow? */
if (indx > lb[0])
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
}
else if (ARR_NDIM(v) == 0)
indx = 1;
else
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("argument must be empty or one-dimensional array")));
/* Perform element insertion */
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
result = array_set(v, 1, &indx, newelem, isNull,
-1, my_extra->typlen, my_extra->typbyval, my_extra->typalign);
/* Readjust result's LB to match the input's, as expected for prepend */
if (ARR_NDIM(v) == 1)
ARR_LBOUND(result)[0] = ARR_LBOUND(v)[0];
PG_RETURN_ARRAYTYPE_P(result);
}
示例2: array_loop
void array_loop(ArrayType *array, int32 start, array_iter *iter)
{
iter->array = array;
iter->ptr = ARR_DATA_PTR(array);
iter->max = ARR_DIMS(array)[0];
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&iter->typlen,
&iter->typbyval,
&iter->typalign);
/* If we are starting in the middle of the array, then scan forward */
start = start - ARR_LBOUND(array)[0];
if (start <= 0)
iter->index = start;
else
{
/*
* could probably be more efficient for fixed length arrays, but
* they would still require adjustments for nulls.
*/
iter->index = 0;
while (start--)
{
Datum d;
bool isna;
array_next(iter, &d, &isna);
}
}
}
示例3: array_get_lowerbounds
static PyObj
array_get_lowerbounds(PyObj self, void *closure)
{
ArrayType *at;
PyObj rob;
int i, ndim, *lbs;
at = DatumGetArrayTypeP(PyPgObject_GetDatum(self));
ndim = ARR_NDIM(at);
lbs = ARR_LBOUND(at);
rob = PyTuple_New(ndim);
for (i = 0; i < ndim; ++i)
{
PyObj ob;
ob = PyLong_FromLong(lbs[i]);
if (ob == NULL)
{
Py_DECREF(rob);
return(NULL);
}
PyTuple_SET_ITEM(rob, i, ob);
}
return(rob);
}
示例4: new_intArrayType
/* Create a new int array with room for "num" elements */
ArrayType *
new_intArrayType(int num)
{
ArrayType *r;
int nbytes;
/* if no elements, return a zero-dimensional array */
if (num <= 0)
{
r = construct_empty_array(INT4OID);
return r;
}
nbytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int) * num;
r = (ArrayType *) palloc0(nbytes);
SET_VARSIZE(r, nbytes);
ARR_NDIM(r) = 1;
r->dataoffset = 0; /* marker for no null bitmap */
ARR_ELEMTYPE(r) = INT4OID;
ARR_DIMS(r)[0] = num;
ARR_LBOUND(r)[0] = 1;
return r;
}
示例5: intArrayIdx
static int
intArrayIdx(ArrayType * array, int const * coord, bool noerror)
{
int * lbs;
int * dims;
int i, res;
lbs = ARR_LBOUND(array);
dims = ARR_DIMS(array);
res = 0;
for (i = 0; i < array->ndim; i++)
{
int c = coord[i] - lbs[i];
if (c < 0 || c >= dims[i])
{
if (noerror)
return -1;
else
elog(ERROR, "array out of bounds");
}
res = res * dims[i] + c;
}
return res;
}
示例6: createArrayType
ArrayType* createArrayType(jsize nElems, size_t elemSize, Oid elemType, bool withNulls)
{
ArrayType* v;
Size nBytes = elemSize * nElems;
MemoryContext currCtx = Invocation_switchToUpperContext();
Size dataoffset;
if(withNulls)
{
dataoffset = ARR_OVERHEAD_WITHNULLS(1, nElems);
nBytes += dataoffset;
}
else
{
dataoffset = 0; /* marker for no null bitmap */
nBytes += ARR_OVERHEAD_NONULLS(1);
}
v = (ArrayType*)palloc0(nBytes);
AssertVariableIsOfType(v->dataoffset, int32);
v->dataoffset = (int32)dataoffset;
MemoryContextSwitchTo(currCtx);
SET_VARSIZE(v, nBytes);
ARR_NDIM(v) = 1;
ARR_ELEMTYPE(v) = elemType;
*((int*)ARR_DIMS(v)) = nElems;
*((int*)ARR_LBOUND(v)) = 1;
return v;
}
示例7: intArrayInit
static ArrayType *
intArrayInit(int ndims, int const * dims, int const * lbs)
{
ArrayType * res;
int size;
int nbytes;
if (ndims < 0) /* we do allow zero-dimension arrays */
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid number of dimensions: %d", ndims)));
if (ndims > MAXDIM)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
ndims, MAXDIM)));
/* fast track for empty array */
if (ndims == 0)
return construct_empty_array(INT4OID);
size = ArrayGetNItems(ndims, dims);
nbytes = ARR_OVERHEAD_NONULLS(ndims);
nbytes += size * 4;
res = palloc0(nbytes);
SET_VARSIZE(res, nbytes);
res->ndim = ndims;
res->elemtype = INT4OID;
res->dataoffset = 0;
memcpy(ARR_DIMS(res), dims, ndims * sizeof(int));
memcpy(ARR_LBOUND(res), lbs, ndims * sizeof(int));
return res;
}
示例8: hstore_slice_to_array
Datum
hstore_slice_to_array(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HEntry *entries = ARRPTR(hs);
char *ptr = STRPTR(hs);
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
ArrayType *aout;
Datum *key_datums;
bool *key_nulls;
Datum *out_datums;
bool *out_nulls;
int key_count;
int i;
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
&key_datums, &key_nulls, &key_count);
if (key_count == 0)
{
aout = construct_empty_array(TEXTOID);
PG_RETURN_POINTER(aout);
}
out_datums = palloc(sizeof(Datum) * key_count);
out_nulls = palloc(sizeof(bool) * key_count);
for (i = 0; i < key_count; ++i)
{
text *key = (text *) DatumGetPointer(key_datums[i]);
int idx;
if (key_nulls[i])
idx = -1;
else
idx = hstoreFindKey(hs, NULL, VARDATA(key), VARSIZE(key) - VARHDRSZ);
if (idx < 0 || HS_VALISNULL(entries, idx))
{
out_nulls[i] = true;
out_datums[i] = (Datum) 0;
}
else
{
out_datums[i] = PointerGetDatum(
cstring_to_text_with_len(HS_VAL(entries, ptr, idx),
HS_VALLEN(entries, idx)));
out_nulls[i] = false;
}
}
aout = construct_md_array(out_datums, out_nulls,
ARR_NDIM(key_array),
ARR_DIMS(key_array),
ARR_LBOUND(key_array),
TEXTOID, -1, false, 'i');
PG_RETURN_POINTER(aout);
}
示例9: pcpoint_from_double_array
Datum pcpoint_from_double_array(PG_FUNCTION_ARGS)
{
uint32 pcid = PG_GETARG_INT32(0);
ArrayType *arrptr = PG_GETARG_ARRAYTYPE_P(1);
int nelems;
float8 *vals;
PCPOINT *pt;
PCSCHEMA *schema = pc_schema_from_pcid(pcid, fcinfo);
SERIALIZED_POINT *serpt;
if ( ! schema )
elog(ERROR, "unable to load schema for pcid = %d", pcid);
if ( ARR_ELEMTYPE(arrptr) != FLOAT8OID )
elog(ERROR, "array must be of float8[]");
if ( ARR_NDIM(arrptr) != 1 )
elog(ERROR, "float8[] must have only one dimension");
if ( ARR_HASNULL(arrptr) )
elog(ERROR, "float8[] must not have null elements");
nelems = ARR_DIMS(arrptr)[0];
if ( nelems != schema->ndims || ARR_LBOUND(arrptr)[0] > 1 )
elog(ERROR, "array dimensions do not match schema dimensions of pcid = %d", pcid);
vals = (float8*) ARR_DATA_PTR(arrptr);
pt = pc_point_from_double_array(schema, vals, nelems);
serpt = pc_point_serialize(pt);
pc_point_free(pt);
PG_RETURN_POINTER(serpt);
}
示例10: sizeof
inline
AbstractionLayer::MutableArrayHandle<T>
AbstractionLayer::Allocator::allocateArray(size_t inNumElements) const {
/*
* Check that the size will not exceed addressable memory. Therefore, the
* following precondition has to hold:
* ((std::numeric_limits<size_t>::max() - ARR_OVERHEAD_NONULLS(1)) /
* inElementSize >= inNumElements)
*/
if ((std::numeric_limits<size_t>::max() - ARR_OVERHEAD_NONULLS(1)) /
sizeof(T) < inNumElements)
throw std::bad_alloc();
size_t size = sizeof(T) * inNumElements + ARR_OVERHEAD_NONULLS(1);
ArrayType *array;
// Note: Except for the allocate call, the following statements do not call
// into the PostgreSQL backend. We are only using macros here.
// PostgreSQL requires that all memory is overwritten with zeros. So
// we ingore ZM here
array = static_cast<ArrayType*>(allocate<MC, dbal::DoZero, F>(size));
SET_VARSIZE(array, size);
array->ndim = 1;
array->dataoffset = 0;
array->elemtype = TypeTraits<T>::oid;
ARR_DIMS(array)[0] = inNumElements;
ARR_LBOUND(array)[0] = 1;
return MutableArrayHandle<T>(array);
}
示例11: alpine_miner_lr_ca_derivative
Datum
alpine_miner_lr_ca_derivative(PG_FUNCTION_ARGS)
{
ArrayType *beta_arg, *columns_arg, *result;
float8 *beta_data, *columns_data, *result_data;
int beta_count, columns_count, result_count;
bool add_intercept_arg;
double weight_arg;
int y_arg;
int size;
double gx = 0.0;
double pi = 0.0;
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3) || PG_ARGISNULL(4) || PG_ARGISNULL(5)){
PG_RETURN_NULL();
}
result = PG_GETARG_ARRAYTYPE_P(0);
beta_arg = PG_GETARG_ARRAYTYPE_P(1);
columns_arg = PG_GETARG_ARRAYTYPE_P(2);
add_intercept_arg = PG_GETARG_BOOL(3);
weight_arg = PG_GETARG_FLOAT8(4);
y_arg = PG_GETARG_INT32(5);
result_data = (float8*) ARR_DATA_PTR(result);
beta_data = (float8*) ARR_DATA_PTR(beta_arg);
columns_data = (float8*) ARR_DATA_PTR(columns_arg);
result_count = ARR_DIMS(result)[0];
beta_count = ARR_DIMS(beta_arg)[0];
columns_count = ARR_DIMS(columns_arg)[0];
// float8 * column_array_data = (float8*) ARR_DATA_PTR(column_array);
if (result_count == 1){
result_count = beta_count;
size = result_count * sizeof(float8) + ARR_OVERHEAD_NONULLS(1);
result = (ArrayType *) palloc(size);
SET_VARSIZE(result, size);
result->ndim = 1;
result->dataoffset = 0;
result->elemtype = FLOAT8OID;
ARR_DIMS(result)[0] = result_count;
ARR_LBOUND(result)[0] = 1;
result_data = (float8*) ARR_DATA_PTR(result);
memset(result_data, 0, result_count * sizeof(float8));
}
pi = alpine_miner_compute_pi(beta_data, beta_count, columns_data, columns_count, add_intercept_arg);
alpine_miner_compute_derivative(columns_count,columns_data, result_data
,weight_arg, y_arg, add_intercept_arg, pi);
PG_RETURN_ARRAYTYPE_P(result);
}
示例12: alpine_miner_covar_sam_accum
Datum
alpine_miner_covar_sam_accum(PG_FUNCTION_ARGS)
{
ArrayType *state;
float8 * state_array_data;
ArrayType * column_array;
int column_size;
float8 * column_array_data;
int i;
int k ;
int j;
if (PG_ARGISNULL(0)){
PG_RETURN_NULL();
}
state = PG_GETARG_ARRAYTYPE_P(0);
state_array_data = (float8*) ARR_DATA_PTR(state);
column_array = PG_GETARG_ARRAYTYPE_P(1);
column_size = ARR_DIMS(column_array)[0];
column_array_data = (float8*) ARR_DATA_PTR(column_array);
if (ARR_DIMS(state)[0] == 1){
int result_size = column_size * ( column_size + 1)/2 + column_size+2;
int size = result_size * sizeof(float8) + ARR_OVERHEAD_NONULLS(1);
state = (ArrayType *) palloc(size);
SET_VARSIZE(state, size);
state->ndim = 1;
state->dataoffset = 0;
state->elemtype = FLOAT8OID;
ARR_DIMS(state)[0] = result_size;
ARR_LBOUND(state)[0] = 1;
state_array_data = (float8*) ARR_DATA_PTR(state);
memset(state_array_data, 0, result_size * sizeof(float8));
}
k = 0;
for ( i = 0; i < column_size; i++){
for(j = i; j < column_size; j++){
state_array_data[k] += column_array_data[i] * column_array_data[j];
k++;
}
}
for( i = 0; i < column_size; i++){
state_array_data[k + i] += column_array_data[i];
}
state_array_data[k+i]++;
state_array_data[k+i+1]=column_size;
PG_RETURN_ARRAYTYPE_P(state);
}
示例13: array_append
/*-----------------------------------------------------------------------------
* array_append :
* push an element onto the end of a one-dimensional array
*----------------------------------------------------------------------------
*/
Datum
array_append(PG_FUNCTION_ARGS)
{
ArrayType *v;
Datum newelem;
bool isNull;
ArrayType *result;
int *dimv,
*lb;
int indx;
ArrayMetaState *my_extra;
v = fetch_array_arg_replace_nulls(fcinfo, 0);
isNull = PG_ARGISNULL(1);
if (isNull)
newelem = (Datum) 0;
else
newelem = PG_GETARG_DATUM(1);
if (ARR_NDIM(v) == 1)
{
/* append newelem */
int ub;
lb = ARR_LBOUND(v);
dimv = ARR_DIMS(v);
ub = dimv[0] + lb[0] - 1;
indx = ub + 1;
/* overflow? */
if (indx < ub)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
}
else if (ARR_NDIM(v) == 0)
indx = 1;
else
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("argument must be empty or one-dimensional array")));
/* Perform element insertion */
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
result = array_set(v, 1, &indx, newelem, isNull,
-1, my_extra->typlen, my_extra->typbyval, my_extra->typalign);
PG_RETURN_ARRAYTYPE_P(result);
}
示例14: internal_get_array_of_close_canopies
Datum
internal_get_array_of_close_canopies(PG_FUNCTION_ARGS)
{
SvecType *svec;
Datum *all_canopies;
int num_all_canopies;
float8 threshold;
PGFunction metric_fn;
ArrayType *close_canopies_arr;
int4 *close_canopies;
int num_close_canopies;
size_t bytes;
MemoryContext mem_context_for_function_calls;
svec = PG_GETARG_SVECTYPE_P(verify_arg_nonnull(fcinfo, 0));
get_svec_array_elms(PG_GETARG_ARRAYTYPE_P(verify_arg_nonnull(fcinfo, 1)),
&all_canopies, &num_all_canopies);
threshold = PG_GETARG_FLOAT8(verify_arg_nonnull(fcinfo, 2));
metric_fn = get_metric_fn(PG_GETARG_INT32(verify_arg_nonnull(fcinfo, 3)));
mem_context_for_function_calls = setup_mem_context_for_functional_calls();
close_canopies = (int4 *) palloc(sizeof(int4) * num_all_canopies);
num_close_canopies = 0;
for (int i = 0; i < num_all_canopies; i++) {
if (compute_metric(metric_fn, mem_context_for_function_calls,
PointerGetDatum(svec), all_canopies[i]) < threshold)
close_canopies[num_close_canopies++] = i + 1 /* lower bound */;
}
MemoryContextDelete(mem_context_for_function_calls);
/* If we cannot find any close canopy, return NULL. Note that the result
* we return will be passed to internal_kmeans_closest_centroid() and if the
* array of close canopies is NULL, then internal_kmeans_closest_centroid()
* will consider and compute the distance to all centroids. */
if (num_close_canopies == 0)
PG_RETURN_NULL();
bytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int4) * num_close_canopies;
close_canopies_arr = (ArrayType *) palloc0(bytes);
SET_VARSIZE(close_canopies_arr, bytes);
ARR_ELEMTYPE(close_canopies_arr) = INT4OID;
ARR_NDIM(close_canopies_arr) = 1;
ARR_DIMS(close_canopies_arr)[0] = num_close_canopies;
ARR_LBOUND(close_canopies_arr)[0] = 1;
memcpy(ARR_DATA_PTR(close_canopies_arr), close_canopies,
sizeof(int4) * num_close_canopies);
PG_RETURN_ARRAYTYPE_P(close_canopies_arr);
}
示例15: alpine_miner_covar_sam_final
Datum
alpine_miner_covar_sam_final(PG_FUNCTION_ARGS){
ArrayType *state ;
ArrayType *result;
float8 * resultData;
float8 * state_array_data;
int total_length;
int column_size;
float8 row_size;
int result_size;
int size;
int k=0;
int i,j;
int sam_row_size;
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
state = PG_GETARG_ARRAYTYPE_P(0);
state_array_data = (float8*) ARR_DATA_PTR(state);
total_length=ARR_DIMS(state)[0];
column_size=state_array_data[total_length-1];
row_size=state_array_data[total_length-2];
result_size=column_size*(column_size+1)/2;
size = result_size * sizeof(float8) + ARR_OVERHEAD_NONULLS(1);
result = (ArrayType *) palloc(size);
SET_VARSIZE(result, size);
result->ndim = 1;
result->dataoffset = 0;
result->elemtype = FLOAT8OID;
ARR_DIMS(result)[0] = result_size;
ARR_LBOUND(result)[0] = 1;
resultData = (float8*) ARR_DATA_PTR(result);
memset(resultData, 0, result_size * sizeof(float8));
sam_row_size=row_size-1;
if(sam_row_size<=0)
sam_row_size=1;
k=0;
for ( i = 0; i < column_size; i++){
for( j = i; j < column_size; j++){
resultData[k] =state_array_data[k]/sam_row_size- state_array_data[result_size+i] * state_array_data[result_size+j]/row_size/sam_row_size;
k++;
}
}
PG_RETURN_ARRAYTYPE_P(result);
}