Skip to content

Commit 903ffa2

Browse files
committed
docs: add example
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 7c29c2d commit 903ffa2

File tree

1 file changed

+60
-0
lines changed
  • lib/node_modules/@stdlib/ndarray/base/binary/examples

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
'use strict';
20+
21+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
22+
var filledarray = require( '@stdlib/array/filled' );
23+
var filledarrayBy = require( '@stdlib/array/filled-by' );
24+
var add = require( '@stdlib/number/float64/base/add' );
25+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
26+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
27+
var binary = require( './../lib' );
28+
29+
var N = 10;
30+
var x = {
31+
'dtype': 'generic',
32+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
33+
'shape': [ 5, 2 ],
34+
'strides': [ 2, 1 ],
35+
'offset': 0,
36+
'order': 'row-major'
37+
};
38+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
39+
40+
var y = {
41+
'dtype': 'generic',
42+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
43+
'shape': x.shape.slice(),
44+
'strides': shape2strides( x.shape, 'column-major' ),
45+
'offset': 0,
46+
'order': 'column-major'
47+
};
48+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
49+
50+
var z = {
51+
'dtype': 'generic',
52+
'data': filledarray( 0, N, 'generic' ),
53+
'shape': x.shape.slice(),
54+
'strides': shape2strides( x.shape, 'column-major' ),
55+
'offset': 0,
56+
'order': 'column-major'
57+
};
58+
59+
binary( [ x, y, z ], add );
60+
console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) );

0 commit comments

Comments
 (0)