README.md (4320B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Non-Singleton Dimensions 22 23 > Return the number of non-singleton dimensions. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var nonsingletonDimensions = require( '@stdlib/ndarray/base/nonsingleton-dimensions' ); 41 ``` 42 43 #### nonsingletonDimensions( shape ) 44 45 Returns number of non-singleton dimensions. 46 47 ```javascript 48 var n = nonsingletonDimensions( [ 3, 1, 3 ] ); 49 // returns 2 50 ``` 51 52 </section> 53 54 <!-- /.usage --> 55 56 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 57 58 <section class="notes"> 59 60 ## Notes 61 62 - A singleton dimension is a dimension whose size is equal to `1`. 63 64 </section> 65 66 <!-- /.notes --> 67 68 <!-- Package usage examples. --> 69 70 <section class="examples"> 71 72 ## Examples 73 74 <!-- eslint no-undef: "error" --> 75 76 ```javascript 77 var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); 78 var nonsingletonDimensions = require( '@stdlib/ndarray/base/nonsingleton-dimensions' ); 79 80 var shape; 81 var n; 82 var i; 83 84 shape = [ 0, 0, 0 ]; 85 for ( i = 0; i < 100; i++ ) { 86 shape[ 0 ] = discreteUniform( 1, 5 ); 87 shape[ 1 ] = discreteUniform( 1, 5 ); 88 shape[ 2 ] = discreteUniform( 1, 5 ); 89 n = nonsingletonDimensions( shape ); 90 console.log( 'shape: %s. non-singleton dimensions: %d.', shape.join( 'x' ), n ); 91 } 92 ``` 93 94 </section> 95 96 <!-- /.examples --> 97 98 <!-- C interface documentation. --> 99 100 * * * 101 102 <section class="c"> 103 104 ## C APIs 105 106 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 107 108 <section class="intro"> 109 110 </section> 111 112 <!-- /.intro --> 113 114 <!-- C usage documentation. --> 115 116 <section class="usage"> 117 118 ### Usage 119 120 ```c 121 #include "stdlib/ndarray/base/nonsingleton_dimensions.h" 122 ``` 123 124 #### stdlib_ndarray_nonsingleton_dimensions( ndims, \*shape ) 125 126 Returns the number of non-singleton dimensions. 127 128 ```c 129 int64_t ndims = 2; 130 int64_t shape[] = { 10, 1 }; 131 132 int64_t n = stdlib_ndarray_nonsingleton_dimensions( ndims, shape ); 133 // returns 1 134 ``` 135 136 The function accepts the following arguments: 137 138 - **ndims**: `[in] int64_t` number of dimensions. 139 - **shape**: `[in] int64_t*` array shape. 140 141 ```c 142 int64_t stdlib_ndarray_nonsingleton_dimensions( int64_t ndims, int64_t *shape ); 143 ``` 144 145 </section> 146 147 <!-- /.usage --> 148 149 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 150 151 <section class="notes"> 152 153 </section> 154 155 <!-- /.notes --> 156 157 <!-- C API usage examples. --> 158 159 <section class="examples"> 160 161 ### Examples 162 163 ```c 164 #include "stdlib/ndarray/base/nonsingleton_dimensions.h" 165 #include <stdio.h> 166 #include <inttypes.h> 167 168 int main() { 169 int64_t shape[] = { 10, 3, 1, 1, 5 }; 170 171 int64_t n = stdlib_ndarray_nonsingleton_dimensions( 5, shape ); 172 printf( "shape: %"PRId64"x%"PRId64"x%"PRId64"x%"PRId64"x%"PRId64". non-singleton dimensions: %"PRId64"\n", shape[ 0 ], shape[ 1 ], shape[ 2 ], shape[ 3 ], shape[ 4 ], n ); 173 } 174 ``` 175 176 </section> 177 178 <!-- /.examples --> 179 180 </section> 181 182 <!-- /.c --> 183 184 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 185 186 <section class="references"> 187 188 </section> 189 190 <!-- /.references --> 191 192 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 193 194 <section class="links"> 195 196 </section> 197 198 <!-- /.links -->