Skip to content

Commit b0cf140

Browse files
committed
Auto-generated commit
1 parent 3dfa656 commit b0cf140

File tree

5 files changed

+88
-8
lines changed

5 files changed

+88
-8
lines changed

.github/.keepalive

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-03-17T00:53:30.187Z
1+
2025-04-14T00:31:16.651Z

CHANGELOG.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-03-17)
7+
## Unreleased (2025-04-14)
8+
9+
<section class="bug-fixes">
10+
11+
### Bug Fixes
12+
13+
- [`f22a9ab`](https://github.com/stdlib-js/stdlib/commit/f22a9ab1c1c50aacc3529b77401469c915f79aaf) - ensure support for allocating zero-dimensional ndarrays
14+
15+
</section>
16+
17+
<!-- /.bug-fixes -->
818

919
<section class="commits">
1020

1121
### Commits
1222

1323
<details>
1424

25+
- [`7536870`](https://github.com/stdlib-js/stdlib/commit/75368709f4bdeb91221d08492b5a0bc9c94f5b71) - **docs:** fix example and update docs _(by Athan Reines)_
26+
- [`f22a9ab`](https://github.com/stdlib-js/stdlib/commit/f22a9ab1c1c50aacc3529b77401469c915f79aaf) - **fix:** ensure support for allocating zero-dimensional ndarrays _(by Athan Reines)_
1527
- [`453c7f9`](https://github.com/stdlib-js/stdlib/commit/453c7f9f7c8ac5b8817b1d81f98af42570f1d0a5) - **refactor:** allow array-like objects containing submodes _(by Athan Reines)_
1628

1729
</details>

CONTRIBUTORS

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Contributors listed in alphabetical order.
44

55
Aadish Jain <[email protected]>
6+
Aarya Balwadkar <[email protected]>
67
Aayush Khanna <[email protected]>
78
Abdelrahman Samir <[email protected]>
9+
Abdul Kaium <[email protected]>
810
Abhay Punia <[email protected]>
911
Abhijit Raut <[email protected]>
1012
Abhishek Jain <[email protected]>
@@ -16,6 +18,7 @@ Ahmed Khaled <[email protected]>
1618
Aksshay Balasubramanian <[email protected]>
1719
Aleksandr <[email protected]>
1820
Ali Salesi <[email protected]>
21+
AlyAbdelmoneim <[email protected]>
1922
Aman Bhansali <[email protected]>
2023
AmanBhadkariya <[email protected]>
2124
Amit Jimiwal <[email protected]>
@@ -24,6 +27,7 @@ Anshu Kumar <[email protected]>
2427
Anudeep Sanapala <[email protected]>
2528
Athan Reines <[email protected]>
2629
30+
Bhavishy Agrawal <[email protected]>
2731
Brendan Graetz <[email protected]>
2832
Bruno Fenzl <[email protected]>
2933
Bryan Elee <[email protected]>
@@ -39,6 +43,7 @@ Dev Goel <[email protected]>
3943
Dhanyabad behera <[email protected]>
4044
Dhruv Arvind Singh <[email protected]>
4145
Dhruvil Mehta <[email protected]>
46+
Dipjyoti Das <[email protected]>
4247
Divyansh Seth <[email protected]>
4348
Dominic Lim <[email protected]>
4449
Dominik Moritz <[email protected]>
@@ -61,6 +66,7 @@ Jaimin Godhani <[email protected]>
6166
Jaison D Souza <[email protected]>
6267
Jalaj Kumar <[email protected]>
6368
James Gelok <[email protected]>
69+
6470
Jaysukh Makvana <[email protected]>
6571
Jenish Thapa <[email protected]>
6672
Jithin KS <[email protected]>
@@ -70,14 +76,18 @@ Jordan Gallivan <[email protected]>
7076
Joris Labie <[email protected]>
7177
Justin Dennison <[email protected]>
7278
Justyn Shelby <[email protected]>
73-
Karan Anand <[email protected]>
79+
Karan Anand <[email protected]>
80+
Karan Yadav <[email protected]>
7481
Karthik Prakash <[email protected]>
7582
Kaushikgtm <[email protected]>
83+
Kavyansh-Bagdi <[email protected]>
7684
Kohantika Nath <[email protected]>
7785
Krishnam Agarwal <[email protected]>
7886
Krishnendu Das <[email protected]>
7987
Kshitij-Dale <[email protected]>
8088
Lovelin Dhoni J B <[email protected]>
89+
90+
Mahfuza Humayra Mohona <[email protected]>
8191
Manik Sharma <[email protected]>
8292
Manvith M <[email protected]>
8393
Marcus Fantham <[email protected]>
@@ -88,9 +98,12 @@ Mohammad Bin Aftab <[email protected]>
8898
Mohammad Kaif <[email protected]>
8999
Momtchil Momtchev <[email protected]>
90100
Muhammad Haris <[email protected]>
101+
Muhammad Taaha Tariq <[email protected]>
102+
Muhmmad Saad <[email protected]>
91103
Naresh Jagadeesan <[email protected]>
92104
Naveen Kumar <[email protected]>
93105
Neeraj Pathak <[email protected]>
106+
NirvedMishra <[email protected]>
94107
Nishant Shinde <[email protected]>
95108
Nishchay Rajput <[email protected]>
96109
Nithin Katta <[email protected]>
@@ -99,15 +112,20 @@ Ognjen Jevremović <[email protected]>
99112
Oneday12323 <[email protected]>
100113
Ori Miles <[email protected]>
101114
Philipp Burckhardt <[email protected]>
115+
Prajjwal Bajpai <[email protected]>
102116
Prajwal Kulkarni <[email protected]>
103117
Pranav Goswami <[email protected]>
104118
Pranjal Jha <[email protected]>
105119
Prashant Kumar Yadav <[email protected]>
120+
PrathamBhamare <[email protected]>
106121
Pratik Singh <[email protected]>
107122
Pratyush Kumar Chouhan <[email protected]>
123+
Pravesh Kunwar <[email protected]>
108124
Priyansh Prajapati <[email protected]>
109125
Priyanshu Agarwal <[email protected]>
126+
Pulkit Gupta <[email protected]>
110127
Pushpendra Chandravanshi <[email protected]>
128+
Rahul Kumar <[email protected]>
111129
Raunak Kumar Gupta <[email protected]>
112130
Rejoan Sardar <[email protected]>
113131
Ricky Reusser <[email protected]>
@@ -116,12 +134,17 @@ Rishav <[email protected]>
116134
Rishav Tarway <[email protected]>
117135
Robert Gislason <[email protected]>
118136
Roman Stetsyk <[email protected]>
137+
119138
Rutam Kathale <[email protected]>
120139
Ruthwik Chikoti <[email protected]>
121140
Ryan Seal <[email protected]>
122141
Rylan Yang <[email protected]>
142+
SAHIL KUMAR <[email protected]>
123143
SHIVAM YADAV <[email protected]>
144+
Sahil Goyal <[email protected]>
145+
Sai Avinash <[email protected]>
124146
Sai Srikar Dumpeti <[email protected]>
147+
Sanchay Ketan Sinha <[email protected]>
125148
Sarthak Paandey <[email protected]>
126149
Saurabh Singh <[email protected]>
127150
Seyyed Parsa Neshaei <[email protected]>
@@ -157,6 +180,7 @@ Yuvi Mittal <[email protected]>
157180
158181
ekambains <[email protected]>
159182
fadiothman22 <[email protected]>
183+
lohithganni <[email protected]>
160184
olenkabilonizhka <[email protected]>
161185
pranav-1720 <[email protected]>
162186
rahulrangers <[email protected]>

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ struct ndarray * stdlib_ndarray_allocate( int16_t dtype, uint8_t *data, int64_t
913913
Notes:
914914

915915
- The user is responsible for freeing the allocated memory.
916+
- To allocate a zero-dimensional ndarray, provide a `shape` argument equal to a null pointer, an `ndims` argument equal to `0`, and a `strides` argument consisting of a single element equal to `0`. The `order` argument can be either row-major or column-major and has no effect on data storage or access.
916917

917918
#### stdlib_ndarray_bytelength( \*arr )
918919

@@ -1032,6 +1033,7 @@ int64_t stdlib_ndarray_dimension( const struct ndarray *arr, const int64_t i );
10321033
Notes:
10331034
10341035
- The function does perform bounds checking for the dimension index.
1036+
- If an input ndarray is zero-dimensional, the function always returns `-1`.
10351037
10361038
#### stdlib_ndarray_disable_flags( \*arr, flags )
10371039
@@ -1538,6 +1540,10 @@ The function accepts the following arguments:
15381540
int64_t * stdlib_ndarray_shape( const struct ndarray *arr );
15391541
```
15401542
1543+
Notes:
1544+
1545+
- If an input ndarray is zero-dimensional, the function returns a null pointer.
1546+
15411547
#### stdlib_ndarray_stride( \*arr, i )
15421548
15431549
Returns an ndarray stride (in bytes).
@@ -1579,7 +1585,7 @@ int64_t stdlib_ndarray_stride( const struct ndarray *arr, const int64_t i );
15791585
15801586
Notes:
15811587
1582-
- the function does perform bounds checking for the dimension index.
1588+
- The function does perform bounds checking for the dimension index.
15831589
15841590
#### stdlib_ndarray_strides( \*arr )
15851591

src/main.c

+42-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@
3737
*
3838
* - The user is responsible for freeing the allocated memory.
3939
*
40+
* - To create a zero-dimensional array,
41+
*
42+
* - provide an `ndims` argument equal to `0`.
43+
* - a `shape` argument equal to a null pointer.
44+
* - a `strides` argument containing a single element equal to `0`.
45+
*
46+
* The `order` argument can be either row-major or column-major and has no effect on data storage or access.
47+
*
48+
* ```javascript
49+
* #include "stdlib/ndarray/ctor.h"
50+
* #include "stdlib/ndarray/dtypes.h"
51+
* #include "stdlib/ndarray/index_modes.h"
52+
* #include "stdlib/ndarray/orders.h"
53+
* #include <stdint.h>
54+
*
55+
* uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
56+
* int64_t *shape = NULL;
57+
* int64_t strides = { 0 };
58+
* int64_t offset = 0;
59+
*
60+
* struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, buffer, 0, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, { STDLIB_NDARRAY_INDEX_ERROR } );
61+
* ```
62+
*
4063
* @param dtype data type
4164
* @param data pointer to the underlying byte array
4265
* @param ndims number of dimensions
@@ -115,7 +138,11 @@ struct ndarray * stdlib_ndarray_allocate( int16_t dtype, uint8_t *data, int64_t
115138
arr->strides = strides;
116139
arr->submodes = submodes;
117140

118-
len = stdlib_ndarray_numel( ndims, shape );
141+
if ( shape == NULL ) {
142+
len = 1;
143+
} else {
144+
len = stdlib_ndarray_numel( ndims, shape );
145+
}
119146
arr->length = len;
120147

121148
arr->BYTES_PER_ELEMENT = stdlib_ndarray_bytes_per_element( dtype );
@@ -146,17 +173,21 @@ uint8_t * stdlib_ndarray_data( const struct ndarray *arr ) {
146173
}
147174

148175
/**
149-
* Returns an ndarray dimension.
176+
* Returns an ndarray dimension size.
150177
*
151178
* ## Notes
152179
*
153180
* - The function does not perform any sanity checks.
181+
* - If an input ndarray is zero-dimensional, the function always returns `-1`.
154182
*
155183
* @param arr input ndarray
156184
* @param i dimension index
157-
* @return dimension
185+
* @return dimension size
158186
*/
159187
int64_t stdlib_ndarray_dimension( const struct ndarray *arr, const int64_t i ) {
188+
if ( arr->shape == NULL ) {
189+
return -1;
190+
}
160191
return arr->shape[ i ];
161192
}
162193

@@ -229,8 +260,11 @@ int64_t stdlib_ndarray_flags( const struct ndarray *arr ) {
229260

230261
// Determine if the array can be stored contiguously...
231262
if ( len == 0 || stdlib_ndarray_iteration_order( ndims, strides ) == 0 ) {
232-
// If an array does not contain any elements, then no data to store, and, if the array is unordered, adjacent array elements are not guaranteed to be stored next to each other.
263+
// If an array does not contain any elements, then no data to store, and, if the array is unordered, adjacent array elements are not guaranteed to be stored next to each other:
233264
contiguous = 0;
265+
} else if ( ndims == 0 ) {
266+
// If an array is zero-dimensional, data consists of a single element which means it is trivially compatible with a single memory segment:
267+
contiguous = 1;
234268
} else {
235269
// Ensure that the array is compatible with a single memory segment:
236270
stdlib_ndarray_minmax_view_buffer_index( ndims, arr->shape, strides, arr->offset, tmp );
@@ -343,6 +377,10 @@ int8_t stdlib_ndarray_order( const struct ndarray *arr ) {
343377
/**
344378
* Returns a pointer to an array containing an ndarray shape (dimensions).
345379
*
380+
* ## Notes
381+
*
382+
* - If an input ndarray is zero-dimensional, the function returns a null pointer.
383+
*
346384
* @param arr input ndarray
347385
* @return array shape (dimensions)
348386
*/

0 commit comments

Comments
 (0)