Skip to content

Commit 61b4944

Browse files
committed
Move struct definition to separate header
1 parent 43737d8 commit 61b4944

File tree

2 files changed

+138
-109
lines changed
  • lib/node_modules/@stdlib/ndarray/ctor/include/stdlib/ndarray

2 files changed

+138
-109
lines changed

lib/node_modules/@stdlib/ndarray/ctor/include/stdlib/ndarray/ctor.h

+1-109
Original file line numberDiff line numberDiff line change
@@ -25,115 +25,7 @@
2525
#include "stdlib/ndarray/index_modes.h"
2626
#include "stdlib/ndarray/orders.h"
2727
#include "ctor/macros.h"
28-
29-
/**
30-
* ndarray structure.
31-
*
32-
* @example
33-
* #include <stdlib.h>
34-
* #include <stdio.h>
35-
* #include <stdint.h>
36-
* #include "stdlib/ndarray/base/bytes_per_element.h"
37-
* #include "stdlib/ndarray/dtypes.h"
38-
* #include "stdlib/ndarray/index_modes.h"
39-
* #include "stdlib/ndarray/orders.h"
40-
* #include "stdlib/ndarray/ctor.h"
41-
*
42-
* struct ndarray *x = malloc( sizeof( struct ndarray ) );
43-
* if ( x == NULL ) {
44-
* fprintf( stderr, "Error allocating memory.\n" );
45-
* exit( 1 );
46-
* }
47-
*
48-
* // Create an underlying byte array:
49-
* uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
50-
* x->data = buffer;
51-
*
52-
* // Specify the underlying data type:
53-
* x->dtype = STDLIB_NDARRAY_FLOAT64;
54-
*
55-
* // Explicitly specify the number of bytes per element:
56-
* x->BYTES_PER_ELEMENT = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT;
57-
*
58-
* // Specify the array shape:
59-
* int64_t shape[] = { 3 }; // vector consisting of 3 doubles
60-
* x->shape = shape;
61-
*
62-
* // Specify the array strides:
63-
* int64_t strides[] = { x->BYTES_PER_ELEMENT };
64-
* x->strides = strides;
65-
*
66-
* // Specify the byte offset:
67-
* x->offset = 0;
68-
*
69-
* // Specify the array order (note: this does not matter for a 1-dimensional array):
70-
* x->order = STDLIB_NDARRAY_ROW_MAJOR;
71-
*
72-
* // Specify the index mode:
73-
* x->imode = STDLIB_NDARRAY_INDEX_ERROR;
74-
*
75-
* // Specify subscript index modes:
76-
* x->submodes = { STDLIB_NDARRAY_INDEX_ERROR };
77-
* x->nsubmodes = 1;
78-
*
79-
* // Explicitly specify the number of array dimensions:
80-
* x->ndims = 1; // vector
81-
*
82-
* // Explicitly specify the number of array elements (doubles):
83-
* x->length = x->shape[ 0 ];
84-
*
85-
* // Explicitly specify the number of bytes:
86-
* x->byteLength = (x->length) * (x->BYTES_PER_ELEMENT);
87-
*
88-
* // Explicitly set the array flags:
89-
* x->flags = stdlib_ndarray_flags( x );
90-
*
91-
* // Free allocated memory:
92-
* free( x );
93-
*/
94-
struct ndarray {
95-
// Underlying data type:
96-
enum STDLIB_NDARRAY_DTYPE dtype;
97-
98-
// Pointer to the underlying byte array:
99-
uint8_t *data;
100-
101-
// Number of array dimensions:
102-
int64_t ndims;
103-
104-
// Array shape (dimensions):
105-
int64_t *shape;
106-
107-
// Array strides (in bytes) specifying how to iterate over a strided array:
108-
int64_t *strides;
109-
110-
// Byte offset which specifies the location at which to start iterating over array elements:
111-
int64_t offset;
112-
113-
// Array order (either row-major (C-style) or column-major (Fortran-style)):
114-
enum STDLIB_NDARRAY_ORDER order;
115-
116-
// Mode specifying how to handle indices which exceed array dimensions:
117-
enum STDLIB_NDARRAY_INDEX_MODE imode;
118-
119-
// Number of subscript modes:
120-
int64_t nsubmodes;
121-
122-
// Mode(s) specifying how to handle subscripts which exceed array dimensions on a per dimension basis:
123-
enum STDLIB_NDARRAY_INDEX_MODE *submodes;
124-
125-
// Number of array elements:
126-
int64_t length;
127-
128-
// Size in bytes:
129-
int64_t byteLength;
130-
131-
// Number of bytes per element (i.e., item size):
132-
enum STDLIB_NDARRAY_BYTES_PER_ELEMENT BYTES_PER_ELEMENT;
133-
134-
// Bit mask providing information regarding the memory layout of the array (e.g., see macros in this file):
135-
int flags;
136-
};
28+
#include "ctor/ndarray.h"
13729

13830
/**
13931
* Returns a pointer to a dynamically allocated ndarray.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#ifndef STDLIB_NDARRAY_CTOR_NDARRAY_H
20+
#define STDLIB_NDARRAY_CTOR_NDARRAY_H
21+
22+
#include <stdint.h>
23+
#include "stdlib/ndarray/base/bytes_per_element.h"
24+
#include "stdlib/ndarray/dtypes.h"
25+
#include "stdlib/ndarray/index_modes.h"
26+
#include "stdlib/ndarray/orders.h"
27+
28+
/**
29+
* ndarray structure.
30+
*
31+
* @example
32+
* #include <stdlib.h>
33+
* #include <stdio.h>
34+
* #include <stdint.h>
35+
* #include "stdlib/ndarray/base/bytes_per_element.h"
36+
* #include "stdlib/ndarray/dtypes.h"
37+
* #include "stdlib/ndarray/index_modes.h"
38+
* #include "stdlib/ndarray/orders.h"
39+
* #include "stdlib/ndarray/ctor.h"
40+
*
41+
* struct ndarray *x = malloc( sizeof( struct ndarray ) );
42+
* if ( x == NULL ) {
43+
* fprintf( stderr, "Error allocating memory.\n" );
44+
* exit( 1 );
45+
* }
46+
*
47+
* // Create an underlying byte array:
48+
* uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
49+
* x->data = buffer;
50+
*
51+
* // Specify the underlying data type:
52+
* x->dtype = STDLIB_NDARRAY_FLOAT64;
53+
*
54+
* // Explicitly specify the number of bytes per element:
55+
* x->BYTES_PER_ELEMENT = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT;
56+
*
57+
* // Specify the array shape:
58+
* int64_t shape[] = { 3 }; // vector consisting of 3 doubles
59+
* x->shape = shape;
60+
*
61+
* // Specify the array strides:
62+
* int64_t strides[] = { x->BYTES_PER_ELEMENT };
63+
* x->strides = strides;
64+
*
65+
* // Specify the byte offset:
66+
* x->offset = 0;
67+
*
68+
* // Specify the array order (note: this does not matter for a 1-dimensional array):
69+
* x->order = STDLIB_NDARRAY_ROW_MAJOR;
70+
*
71+
* // Specify the index mode:
72+
* x->imode = STDLIB_NDARRAY_INDEX_ERROR;
73+
*
74+
* // Specify subscript index modes:
75+
* x->submodes = { STDLIB_NDARRAY_INDEX_ERROR };
76+
* x->nsubmodes = 1;
77+
*
78+
* // Explicitly specify the number of array dimensions:
79+
* x->ndims = 1; // vector
80+
*
81+
* // Explicitly specify the number of array elements (doubles):
82+
* x->length = x->shape[ 0 ];
83+
*
84+
* // Explicitly specify the number of bytes:
85+
* x->byteLength = (x->length) * (x->BYTES_PER_ELEMENT);
86+
*
87+
* // Explicitly set the array flags:
88+
* x->flags = stdlib_ndarray_flags( x );
89+
*
90+
* // Free allocated memory:
91+
* free( x );
92+
*/
93+
struct ndarray {
94+
// Underlying data type:
95+
enum STDLIB_NDARRAY_DTYPE dtype;
96+
97+
// Pointer to the underlying byte array:
98+
uint8_t *data;
99+
100+
// Number of array dimensions:
101+
int64_t ndims;
102+
103+
// Array shape (dimensions):
104+
int64_t *shape;
105+
106+
// Array strides (in bytes) specifying how to iterate over a strided array:
107+
int64_t *strides;
108+
109+
// Byte offset which specifies the location at which to start iterating over array elements:
110+
int64_t offset;
111+
112+
// Array order (either row-major (C-style) or column-major (Fortran-style)):
113+
enum STDLIB_NDARRAY_ORDER order;
114+
115+
// Mode specifying how to handle indices which exceed array dimensions:
116+
enum STDLIB_NDARRAY_INDEX_MODE imode;
117+
118+
// Number of subscript modes:
119+
int64_t nsubmodes;
120+
121+
// Mode(s) specifying how to handle subscripts which exceed array dimensions on a per dimension basis:
122+
enum STDLIB_NDARRAY_INDEX_MODE *submodes;
123+
124+
// Number of array elements:
125+
int64_t length;
126+
127+
// Size in bytes:
128+
int64_t byteLength;
129+
130+
// Number of bytes per element (i.e., item size):
131+
enum STDLIB_NDARRAY_BYTES_PER_ELEMENT BYTES_PER_ELEMENT;
132+
133+
// Bit mask providing information regarding the memory layout of the array (e.g., see macros in this file):
134+
int flags;
135+
};
136+
137+
#endif // !STDLIB_NDARRAY_CTOR_NDARRAY_H

0 commit comments

Comments
 (0)