Skip to content

Commit 485fd08

Browse files
committed
feat: add ndarray/base/from-array
--- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent c95312a commit 485fd08

File tree

10 files changed

+1315
-0
lines changed

10 files changed

+1315
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# array2ndarray
22+
23+
> Convert an array to a one-dimensional [ndarray][@stdlib/ndarray/base/ctor].
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 array2ndarray = require( '@stdlib/ndarray/base/from-array' );
41+
```
42+
43+
#### array2ndarray( buf, order )
44+
45+
Returns a one-dimensional [ndarray][@stdlib/ndarray/base/ctor] which wraps a provided input array.
46+
47+
```javascript
48+
var x = array2ndarray( [ 1, 2, 3 ], 'row-major' );
49+
// returns <ndarray>
50+
51+
var sh = x.shape;
52+
// returns [ 3 ]
53+
54+
var dt = x.dtype;
55+
// returns 'generic'
56+
```
57+
58+
The function supports the following parameters:
59+
60+
- **buf**: input array.
61+
- **order**: memory [layout][@stdlib/ndarray/orders]. Must be either `'row-major'` or `'column-major'`.
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
68+
69+
<section class="notes">
70+
71+
</section>
72+
73+
<!-- /.notes -->
74+
75+
<!-- Package usage examples. -->
76+
77+
<section class="examples">
78+
79+
## Examples
80+
81+
<!-- eslint no-undef: "error" -->
82+
83+
```javascript
84+
var dtype = require( '@stdlib/ndarray/dtype' );
85+
var typedarray = require( '@stdlib/array/typed' );
86+
var array2ndarray = require( '@stdlib/ndarray/base/from-array' );
87+
88+
var buf = typedarray( 10, 'float64' );
89+
var x = array2ndarray( buf, 'row-major' );
90+
console.log( dtype( x ) );
91+
// => 'float64'
92+
93+
buf = typedarray( 10, 'int32' );
94+
x = array2ndarray( buf, 'row-major' );
95+
console.log( dtype( x ) );
96+
// => 'int32'
97+
98+
buf = typedarray( 10, 'complex128' );
99+
x = array2ndarray( buf, 'row-major' );
100+
console.log( dtype( x ) );
101+
// => 'complex128'
102+
103+
buf = typedarray( 10, 'bool' );
104+
x = array2ndarray( buf, 'row-major' );
105+
console.log( dtype( x ) );
106+
// => 'bool'
107+
```
108+
109+
</section>
110+
111+
<!-- /.examples -->
112+
113+
<!-- 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. -->
114+
115+
<section class="references">
116+
117+
</section>
118+
119+
<!-- /.references -->
120+
121+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
122+
123+
<section class="related">
124+
125+
</section>
126+
127+
<!-- /.related -->
128+
129+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
130+
131+
<section class="links">
132+
133+
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor
134+
135+
[@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders
136+
137+
</section>
138+
139+
<!-- /.links -->

0 commit comments

Comments
 (0)