summaryrefslogtreecommitdiffstats
path: root/src/H5Vprivate.h
blob: 4e0ae3d2385cdcd321fd57ef37c3a5c02684f80b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
 * Copyright (C) 1997 NCSA
 *                    All rights reserved.
 *
 * Programmer: Robb Matzke <matzke@llnl.gov>
 *             Friday, October 10, 1997
 */
#ifndef H5Vprivate_H
#define H5Vprivate_H

#include <H5private.h>
#include <H5api_adpt.h>
/* Vector comparison functions like Fortran66 comparison operators */
#define H5V_vector_eq_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)==0)
#define H5V_vector_lt_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)<0)
#define H5V_vector_gt_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)>0)
#define H5V_vector_le_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)<=0)
#define H5V_vector_ge_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)>=0)
#define H5V_vector_eq_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)==0)
#define H5V_vector_lt_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)<0)
#define H5V_vector_gt_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)>0)
#define H5V_vector_le_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)<=0)
#define H5V_vector_ge_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)>=0)

/* Other functions */
#define H5V_vector_cpy(N,DST,SRC) {                                           \
    assert (sizeof(*(DST))==sizeof(*(SRC)));				      \
    if (SRC) HDmemcpy (DST, SRC, (N)*sizeof(*(DST)));                         \
    else HDmemset (DST, 0, (N)*sizeof(*(DST)));                               \
}

#define H5V_vector_zero(N,DST) HDmemset(DST,0,(N)*sizeof(*(DST)))

/* A null pointer is equivalent to a zero vector */
#define H5V_ZERO        NULL

hsize_t H5V_hyper_stride(intn n, const hsize_t *size,
			 const hsize_t *total_size, const hssize_t *offset,
			 hssize_t *stride);
htri_t H5V_hyper_disjointp(intn n, const hssize_t *offset1,
			   const hsize_t *size1, const hssize_t *offset2,
			   const hsize_t *size2);
htri_t H5V_hyper_eq(intn n, const hssize_t *offset1, const hsize_t *size1,
		     const hssize_t *offset2, const hsize_t *size2);
HDF5API herr_t H5V_hyper_fill(intn n, const hsize_t *_size, const hsize_t *total_size,
		      const hssize_t *offset, void *_dst, uintn fill_value);
HDF5API herr_t H5V_hyper_copy(intn n, const hsize_t *size,
		      const hsize_t *dst_total_size,
		      const hssize_t *dst_offset, void *_dst,
		      const hsize_t *src_total_size,
		      const hssize_t *src_offset, const void *_src);
herr_t H5V_stride_fill(intn n, hsize_t elmt_size, const hsize_t *size,
		       const hssize_t *stride, void *_dst, uintn fill_value);
HDF5API herr_t H5V_stride_copy(intn n, hsize_t elmt_size, const hsize_t *_size,
		       const hssize_t *dst_stride, void *_dst,
		       const hssize_t *src_stride, const void *_src);
herr_t H5V_stride_copy2(hsize_t nelmts, hsize_t elmt_size, intn dst_n,
			const hsize_t *dst_size, const hssize_t *dst_stride,
			void *_dst, intn src_n, const hsize_t *src_size,
			const hssize_t *src_stride, const void *_src);
herr_t H5V_stride_optimize1(intn *np, hsize_t *elmt_size, hsize_t *size,
			    hssize_t *stride1);
herr_t H5V_stride_optimize2(intn *np, hsize_t *elmt_size, hsize_t *size,
			    hssize_t *stride1, hssize_t *stride2);
herr_t H5V_array_fill(void *_dst, const void *src, size_t size, size_t count);


/*-------------------------------------------------------------------------
 * Function:    H5V_vector_reduce_product
 *
 * Purpose:     Product reduction of a vector.  Vector elements and return
 *              value are size_t because we usually want the number of
 *              elements in an array and array dimensions are always of type
 *              size_t.
 *
 * Return:      Success:        Product of elements
 *
 *              Failure:        1 if N is zero
 *
 * Programmer:  Robb Matzke
 *              Friday, October 10, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static inline hsize_t __unused__
H5V_vector_reduce_product(intn n, const hsize_t *v)
{
    size_t                  ans = 1;

    if (n && !v) return 0;
    while (n--) ans *= *v++;
    return ans;
}

/*-------------------------------------------------------------------------
 * Function:    H5V_vector_zerop_u
 *
 * Purpose:     Determines if all elements of a vector are zero.
 *
 * Return:      Success:        TRUE if all elements are zero,
 *                              FALSE otherwise
 *
 *              Failure:        TRUE if N is zero
 *
 * Programmer:  Robb Matzke
 *              Friday, October 10, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static inline htri_t __unused__
H5V_vector_zerop_u(intn n, const hsize_t *v)
{
    if (!v) return TRUE;
    while (n--) {
	if (*v++) return FALSE;
    }
    return TRUE;
}

/*-------------------------------------------------------------------------
 * Function:    H5V_vector_zerop_s
 *
 * Purpose:     Determines if all elements of a vector are zero.
 *
 * Return:      Success:        TRUE if all elements are zero,
 *                              FALSE otherwise
 *
 *              Failure:        TRUE if N is zero
 *
 * Programmer:  Robb Matzke
 *              Friday, October 10, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static inline htri_t __unused__
H5V_vector_zerop_s(intn n, const hssize_t *v)
{
    if (!v) return TRUE;
    while (n--) {
	if (*v++) return FALSE;
    }
    return TRUE;
}

/*-------------------------------------------------------------------------
 * Function:    H5V_vector_cmp_u
 *
 * Purpose:     Compares two vectors of the same size and determines if V1 is
 *              lexicographically less than, equal, or greater than V2.
 *
 * Return:      Success:        -1 if V1 is less than V2
 *                              0 if they are equal
 *                              1 if V1 is greater than V2
 *
 *              Failure:        0 if N is zero
 *
 * Programmer:  Robb Matzke
 *              Friday, October 10, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static inline intn __unused__
H5V_vector_cmp_u (intn n, const hsize_t *v1, const hsize_t *v2)
{
    if (v1 == v2) return 0;
    while (n--) {
        if ((v1 ? *v1 : 0) < (v2 ? *v2 : 0)) return -1;
        if ((v1 ? *v1 : 0) > (v2 ? *v2 : 0)) return 1;
        if (v1) v1++;
        if (v2) v2++;
    }
    return 0;
}


/*-------------------------------------------------------------------------
 * Function:	H5V_vector_cmp_s
 *
 * Purpose:     Compares two vectors of the same size and determines if V1 is
 *              lexicographically less than, equal, or greater than V2.
 *
 * Return:      Success:        -1 if V1 is less than V2
 *                              0 if they are equal
 *                              1 if V1 is greater than V2
 *
 *              Failure:        0 if N is zero
 *
 * Programmer:	Robb Matzke
 *              Wednesday, April  8, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static inline intn __unused__
H5V_vector_cmp_s (intn n, const hssize_t *v1, const hssize_t *v2)
{
    if (v1 == v2) return 0;
    while (n--) {
        if ((v1 ? *v1 : 0) < (v2 ? *v2 : 0)) return -1;
        if ((v1 ? *v1 : 0) > (v2 ? *v2 : 0)) return 1;
        if (v1) v1++;
        if (v2) v2++;
    }
    return 0;
}


/*-------------------------------------------------------------------------
 * Function:    H5V_vector_inc
 *
 * Purpose:     Increments V1 by V2
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              Monday, October 13, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static inline void __unused__
H5V_vector_inc(intn n, hsize_t *v1, const hsize_t *v2)
{
    while (n--) *v1++ += *v2++;
}

#endif