sg-ode
vector.h
Go to the documentation of this file.
1 #ifndef G_LD1RHWBBXD615K1PEKWNYBSHDF5Q8
2 #define G_LD1RHWBBXD615K1PEKWNYBSHDF5Q8
3 
6 #include <stddef.h>
7 #include "extern.h"
8 #include "inline_begin.h"
9 #include "restrict_begin.h"
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
15 typedef void SgVector;
16 
18 typedef void SgVectorAccum;
19 
35 typedef int SgVectorAccumType;
36 
60 typedef void SgVectorOperation(void *f_ctx,
61  SgVectorAccum *accum,
62  const SgVectorAccum *val,
63  size_t offset,
64  double **data,
65  size_t num_elems);
66 
68 typedef void SgVectorDriverBase;
69 
77  size_t (*len)(const SgVectorDriverBase *self);
78 
81  SgVector *(*try_new)(const SgVectorDriverBase *self);
82 
84  void (*del)(const SgVectorDriverBase *self, SgVector *vector);
85 
120  void (*operate)(const SgVectorDriverBase *self,
121  SgVectorAccum *accum,
122  SgVectorAccumType accum_type,
124  void *f_ctx,
125  size_t offset,
126  SgVector **vectors,
127  size_t num_vectors);
128 };
129 
133  const SgVectorDriverBase *data;
134  const struct SgVectorDriverVt *vtable;
135 };
136 
138 SG_EXTERN SgVector *sg_vector_try_new(struct SgVectorDriver drv);
139 
141 SG_EXTERN SgVector *sg_vector_new(struct SgVectorDriver drv);
142 
144 SG_EXTERN void sg_vector_del(struct SgVectorDriver drv, SgVector *vector);
145 
147 SG_EXTERN size_t sg_vector_len(struct SgVectorDriver drv);
148 
151 SG_EXTERN void sg_vector_operate(struct SgVectorDriver drv,
152  SgVectorAccum *accum,
153  SgVectorAccumType accum_type,
155  void *f_ctx,
156  size_t offset,
157  SgVector **vectors,
158  size_t num_vectors);
159 
161 SG_EXTERN void sg_vector_fill(struct SgVectorDriver drv,
162  double value,
163  SgVector *vector);
164 
165 SG_EXTERN extern SgVectorOperation sg_vector_fill_operation;
166 
168 SG_EXTERN void sg_vector_copy(struct SgVectorDriver drv,
169  const SgVector *src,
170  SgVector *dest);
171 
172 SG_EXTERN extern SgVectorOperation sg_vector_copy_operation;
173 
174 SG_EXTERN void sg_vector_neg_assign(struct SgVectorDriver drv, SgVector *z);
175 
176 SG_EXTERN extern SgVectorOperation sg_vector_neg_assign_operation;
177 
178 SG_EXTERN void sg_vector_neg(struct SgVectorDriver drv,
179  const SgVector *x,
180  SgVector *z);
181 
182 SG_EXTERN extern SgVectorOperation sg_vector_neg_operation;
183 
185 SG_EXTERN void sg_vector_scale_assign(struct SgVectorDriver drv,
186  double alpha,
187  SgVector *z);
188 
189 SG_EXTERN extern SgVectorOperation sg_vector_scale_assign_operation;
190 
196 SG_EXTERN void sg_vector_scale(struct SgVectorDriver drv,
197  double alpha,
198  const SgVector *x,
199  SgVector *z);
200 
201 SG_EXTERN extern SgVectorOperation sg_vector_scale_operation;
202 
208 SG_EXTERN void sg_vector_linear_assign(struct SgVectorDriver drv,
209  double alpha,
210  double beta,
211  const SgVector *y,
212  SgVector *z);
213 
214 SG_EXTERN extern SgVectorOperation sg_vector_linear_assign_operation;
215 
221 SG_EXTERN void sg_vector_linear(struct SgVectorDriver drv,
222  double alpha,
223  const SgVector *x,
224  double beta,
225  const SgVector *y,
226  SgVector *z);
227 
228 SG_EXTERN extern SgVectorOperation sg_vector_linear_operation;
229 
231 SG_EXTERN double sg_vector_sum(struct SgVectorDriver drv,
232  const SgVector *vector);
233 
236 
237 SG_EXTERN extern struct SgVectorDriverVt SG_BASIC_VECTOR_DRIVER_VT;
238 
246 static inline struct SgVectorDriver sg_basic_vector_driver(size_t *len)
247 {
248  struct SgVectorDriver drv;
249  drv.data = len;
250  drv.vtable = &SG_BASIC_VECTOR_DRIVER_VT;
251  return drv;
252 }
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #include "restrict_end.h"
258 #include "inline_end.h"
259 #endif
void sg_vector_del(struct SgVectorDriver drv, SgVector *vector)
Destroys the vector.
Definition: vector.c:22
void SgVectorOperation(void *f_ctx, SgVectorAccum *accum, const SgVectorAccum *val, size_t offset, double **data, size_t num_elems)
An operation suitable for use in SgVectorDriverVt.operate.
Definition: vector.h:60
void(* del)(const SgVectorDriverBase *self, SgVector *vector)
Destroys a vector.
Definition: vector.h:84
int SgVectorAccumType
The type of an accumulator.
Definition: vector.h:35
void sg_vector_linear_assign(struct SgVectorDriver drv, double alpha, double beta, const SgVector *y, SgVector *z)
Calculate z ← α z + β y.
double sg_vector_sum(struct SgVectorDriver drv, const SgVector *vector)
Sums the values of a vector.
void(* operate)(const SgVectorDriverBase *self, SgVectorAccum *accum, SgVectorAccumType accum_type, SgVectorOperation *f, void *f_ctx, size_t offset, SgVector **vectors, size_t num_vectors)
Applies an element-wise operation (map) to a set of vectors and then accumulates a combined result (f...
Definition: vector.h:120
A vector driver.
Definition: vector.h:132
void sg_vector_operate(struct SgVectorDriver drv, SgVectorAccum *accum, SgVectorAccumType accum_type, SgVectorOperation *f, void *f_ctx, size_t offset, SgVector **vectors, size_t num_vectors)
Perform a generic operation on some vectors.
Definition: vector.c:32
SgVector * sg_vector_new(struct SgVectorDriver drv)
Creates a vector.
Definition: vector.c:15
void SgVectorAccum
An accumulator is an array of some kind.
Definition: vector.h:18
void SgVectorDriverBase
Represents an opaque vector driver.
Definition: vector.h:68
size_t sg_vector_len(struct SgVectorDriver drv)
Gets the length of any vector created by this vector driver.
Definition: vector.c:27
void sg_vector_fill(struct SgVectorDriver drv, double value, SgVector *vector)
Set every element of a vector to the same value.
Definition: vector.c:45
size_t(* len)(const SgVectorDriverBase *self)
Retrieve the length of vectors created by this driver.
Definition: vector.h:77
void sg_vector_scale(struct SgVectorDriver drv, double alpha, const SgVector *x, SgVector *z)
Calculate scalar multiplication of a vector.
void sg_vector_copy(struct SgVectorDriver drv, const SgVector *src, SgVector *dest)
Copy the contents of a vector.
Definition: vector.c:83
void sg_vector_linear(struct SgVectorDriver drv, double alpha, const SgVector *x, double beta, const SgVector *y, SgVector *z)
Calculate the linear combination of two vectors.
The minimal set of operations that a vector driver must support.
Definition: vector.h:75
SgVectorOperation sg_vector_sum_operation
The underlying operation used by sg_vector_sum.
void sg_vector_scale_assign(struct SgVectorDriver drv, double alpha, SgVector *z)
In-place scalar multiplication of a vector.
SgVector * sg_vector_try_new(struct SgVectorDriver drv)
Creates a vector, returning NULL if it fails.
Definition: vector.c:10
void SgVector
A vector is an opaque data type containing a finite number of doubles.
Definition: vector.h:15