File: _strides.h

package info (click to toggle)
mrcal 2.5-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 8,560 kB
  • sloc: python: 40,604; ansic: 15,576; cpp: 1,754; perl: 303; makefile: 158; sh: 98; lisp: 84
file content (51 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download | duplicates (3)
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
// Copyright (c) 2017-2023 California Institute of Technology ("Caltech"). U.S.
// Government sponsorship acknowledged. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0

#pragma once

#ifdef __cplusplus
extern "C" {
#endif


// This is an internal header to make the stride logic work. Not to be seen by
// the end-users or installed

// stride-aware matrix access
#define _P1(x, stride0, i0)                     \
    (*(double*)( (char*)(x) +                   \
    (i0) * (stride0)))
#define _P2(x, stride0, stride1, i0, i1)        \
    (*(double*)( (char*)(x) +                   \
    (i0) * (stride0) +                          \
    (i1) * (stride1)))
#define _P3(x, stride0, stride1, stride2,i0, i1, i2)    \
    (*(double*)( (char*)(x) +                           \
    (i0) * (stride0) +                                  \
    (i1) * (stride1) +                                  \
    (i2) * (stride2)))

#define P1(x, i0)       _P1(x, x##_stride0,                           i0)
#define P2(x, i0,i1)    _P2(x, x##_stride0, x##_stride1,              i0,i1)
#define P3(x, i0,i1,i2) _P3(x, x##_stride0, x##_stride1, x##_stride2, i0,i1,i2)

// Init strides. If a given stride is <= 0, set the default, as we would have if
// the data was contiguous
#define init_stride_1D(x, d0) \
    if( x ## _stride0 <= 0) x ## _stride0 = sizeof(*x)
#define init_stride_2D(x, d0, d1)                       \
    if( x ## _stride1 <= 0) x ## _stride1 = sizeof(*x); \
    if( x ## _stride0 <= 0) x ## _stride0 = d1 * x ## _stride1
#define init_stride_3D(x, d0, d1, d2)                   \
    if( x ## _stride2 <= 0) x ## _stride2 = sizeof(*x); \
    if( x ## _stride1 <= 0) x ## _stride1 = d2 * x ## _stride2; \
    if( x ## _stride0 <= 0) x ## _stride0 = d1 * x ## _stride1

#ifdef __cplusplus
}
#endif