@stdlib/ndarray-base-from-scalar-like 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2024 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
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # scalar2ndarrayLike
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Convert a scalar value to a zero-dimensional ndarray having the same [data type][@stdlib/ndarray/dtypes] as a provided ndarray.
37
+
38
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
39
+
40
+ <section class="intro">
41
+
42
+ </section>
43
+
44
+ <!-- /.intro -->
45
+
46
+ <!-- Package usage documentation. -->
47
+
48
+ <section class="installation">
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install @stdlib/ndarray-base-from-scalar-like
54
+ ```
55
+
56
+ </section>
57
+
58
+ <section class="usage">
59
+
60
+ ## Usage
61
+
62
+ ```javascript
63
+ var scalar2ndarrayLike = require( '@stdlib/ndarray-base-from-scalar-like' );
64
+ ```
65
+
66
+ #### scalar2ndarrayLike( x, value )
67
+
68
+ Returns a zero-dimensional ndarray containing a provided scalar `value` and having the same [data type][@stdlib/ndarray/dtypes] as a provided ndarray.
69
+
70
+ ```javascript
71
+ var zeros = require( '@stdlib/ndarray-base-zeros' );
72
+
73
+ var x = zeros( 'float32', [ 2, 2 ], 'row-major' );
74
+ // returns <ndarray>
75
+
76
+ var y = scalar2ndarrayLike( x, 1.0 );
77
+ // returns <ndarray>
78
+
79
+ var sh = y.shape;
80
+ // returns []
81
+
82
+ var dt = y.dtype;
83
+ // returns 'float32'
84
+
85
+ var v = y.get();
86
+ // returns 1.0
87
+ ```
88
+
89
+ </section>
90
+
91
+ <!-- /.usage -->
92
+
93
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
94
+
95
+ <section class="notes">
96
+
97
+ ## Notes
98
+
99
+ - Along with data type and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor].
100
+ - If `value` is a number and a provided ndarray has a complex [data type][@stdlib/ndarray/dtypes], the function returns a zero-dimensional ndarray containing a complex number whose real component equals the provided scalar `value` and whose imaginary component is zero.
101
+
102
+ </section>
103
+
104
+ <!-- /.notes -->
105
+
106
+ <!-- Package usage examples. -->
107
+
108
+ <section class="examples">
109
+
110
+ ## Examples
111
+
112
+ <!-- eslint no-undef: "error" -->
113
+
114
+ ```javascript
115
+ var dtypes = require( '@stdlib/ndarray-dtypes' );
116
+ var empty = require( '@stdlib/ndarray-base-empty' );
117
+ var scalar2ndarrayLike = require( '@stdlib/ndarray-base-from-scalar-like' );
118
+
119
+ // Get a list of data types:
120
+ var dt = dtypes();
121
+
122
+ // Generate zero-dimensional arrays...
123
+ var x;
124
+ var y;
125
+ var i;
126
+ for ( i = 0; i < dt.length; i++ ) {
127
+ x = empty( dt[ i ], [ 2, 2 ], 'row-major' );
128
+ y = scalar2ndarrayLike( x, i );
129
+ console.log( y.get() );
130
+ }
131
+ ```
132
+
133
+ </section>
134
+
135
+ <!-- /.examples -->
136
+
137
+ <!-- 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. -->
138
+
139
+ <section class="references">
140
+
141
+ </section>
142
+
143
+ <!-- /.references -->
144
+
145
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
146
+
147
+ <section class="related">
148
+
149
+ </section>
150
+
151
+ <!-- /.related -->
152
+
153
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
154
+
155
+
156
+ <section class="main-repo" >
157
+
158
+ * * *
159
+
160
+ ## Notice
161
+
162
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
163
+
164
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
165
+
166
+ #### Community
167
+
168
+ [![Chat][chat-image]][chat-url]
169
+
170
+ ---
171
+
172
+ ## License
173
+
174
+ See [LICENSE][stdlib-license].
175
+
176
+
177
+ ## Copyright
178
+
179
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
180
+
181
+ </section>
182
+
183
+ <!-- /.stdlib -->
184
+
185
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
186
+
187
+ <section class="links">
188
+
189
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-from-scalar-like.svg
190
+ [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-from-scalar-like
191
+
192
+ [test-image]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/actions/workflows/test.yml/badge.svg?branch=v0.1.0
193
+ [test-url]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/actions/workflows/test.yml?query=branch:v0.1.0
194
+
195
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-from-scalar-like/main.svg
196
+ [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-from-scalar-like?branch=main
197
+
198
+ <!--
199
+
200
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/ndarray-base-from-scalar-like.svg
201
+ [dependencies-url]: https://david-dm.org/stdlib-js/ndarray-base-from-scalar-like/main
202
+
203
+ -->
204
+
205
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
206
+ [chat-url]: https://stdlib.zulipchat.com
207
+
208
+ [stdlib]: https://github.com/stdlib-js/stdlib
209
+
210
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
211
+
212
+ [umd]: https://github.com/umdjs/umd
213
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
214
+
215
+ [deno-url]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/tree/deno
216
+ [deno-readme]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/blob/deno/README.md
217
+ [umd-url]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/tree/umd
218
+ [umd-readme]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/blob/umd/README.md
219
+ [esm-url]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/tree/esm
220
+ [esm-readme]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/blob/esm/README.md
221
+ [branches-url]: https://github.com/stdlib-js/ndarray-base-from-scalar-like/blob/main/branches.md
222
+
223
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-from-scalar-like/main/LICENSE
224
+
225
+ [@stdlib/ndarray/base/ctor]: https://www.npmjs.com/package/@stdlib/ndarray-base-ctor
226
+
227
+ [@stdlib/ndarray/ctor]: https://www.npmjs.com/package/@stdlib/ndarray-ctor
228
+
229
+ [@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes
230
+
231
+ </section>
232
+
233
+ <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import scalar2ndarrayLike from '../docs/types/index';
3
+ export = scalar2ndarrayLike;
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";var c=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var u=c(function(A,a){"use strict";var v=require("@stdlib/assert-is-number").isPrimitive,n=require("@stdlib/array-base-assert-is-accessor-array"),o=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),f=require("@stdlib/ndarray-base-dtype"),y=require("@stdlib/ndarray-base-order"),m=require("@stdlib/array-empty"),p=require("@stdlib/buffer-alloc-unsafe");function b(i,r){var t,s,e;return e=f(i),e==="binary"?t=p(1):t=m(1,e),/^complex/.test(e)&&v(r)&&(r=[r,0]),n(t)?s=o(e):s=q(e),s(t,0,r),new i.constructor(e,t,[],[0],0,y(i))}a.exports=b});var d=u();module.exports=d;
2
+ /**
3
+ * @license Apache-2.0
4
+ *
5
+ * Copyright (c) 2024 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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar emptyArray = require( '@stdlib/array-empty' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\n\n\n// MAIN //\n\n/**\n* Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {*} value - scalar value\n* @throws {TypeError} first argument must have a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-base-zeros' );\n*\n* var x = zeros( 'float32', [ 2, 2 ], 'row-major' );\n* // returns <ndarray>\n*\n* var y = scalar2ndarrayLike( x, 1.0 );\n* // returns <ndarray>\n*\n* var sh = y.shape;\n* // returns []\n*\n* var dt = y.dtype;\n* // returns 'float32'\n*\n* var v = y.get();\n* // returns 1.0\n*/\nfunction scalar2ndarrayLike( x, value ) {\n\tvar buf;\n\tvar set;\n\tvar dt;\n\n\tdt = getDType( x );\n\tif ( dt === 'binary' ) {\n\t\tbuf = allocUnsafe( 1 );\n\t} else {\n\t\tbuf = emptyArray( 1, dt );\n\t}\n\tif ( /^complex/.test( dt ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dt );\n\t} else {\n\t\tset = setter( dt );\n\t}\n\tset( buf, 0, value );\n\treturn new x.constructor( dt, buf, [], [ 0 ], 0, getOrder( x ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = scalar2ndarrayLike;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Convert a scalar value to a zero-dimensional ndarray having the same data type as a provided ndarray.\n*\n* @module @stdlib/ndarray-base-from-scalar-like\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-base-zeros' );\n* var scalar2ndarrayLike = require( '@stdlib/ndarray-base-from-scalar-like' );\n*\n* var x = zeros( 'float32', [ 2, 2 ], 'row-major' );\n* // returns <ndarray>\n*\n* var y = scalar2ndarrayLike( x, 1.0 );\n* // returns <ndarray>\n*\n* var sh = y.shape;\n* // returns []\n*\n* var dt = y.dtype;\n* // returns 'float32'\n*\n* var v = y.get();\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAc,QAAS,6BAA8B,EA+BzD,SAASC,EAAoBC,EAAGC,EAAQ,CACvC,IAAIC,EACAC,EACAC,EAEJ,OAAAA,EAAKT,EAAUK,CAAE,EACZI,IAAO,SACXF,EAAMJ,EAAa,CAAE,EAErBI,EAAML,EAAY,EAAGO,CAAG,EAEpB,WAAW,KAAMA,CAAG,GAAKb,EAAUU,CAAM,IAC7CA,EAAQ,CAAEA,EAAO,CAAI,GAEjBT,EAAiBU,CAAI,EACzBC,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAElBD,EAAKD,EAAK,EAAGD,CAAM,EACZ,IAAID,EAAE,YAAaI,EAAIF,EAAK,CAAC,EAAG,CAAE,CAAE,EAAG,EAAGN,EAAUI,CAAE,CAAE,CAChE,CAKAV,EAAO,QAAUS,ICvCjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "isNumber", "isAccessorArray", "accessorSetter", "setter", "getDType", "getOrder", "emptyArray", "allocUnsafe", "scalar2ndarrayLike", "x", "value", "buf", "set", "dt", "main"]
7
+ }
@@ -0,0 +1,437 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ // TypeScript Version: 4.1
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray';
24
+ import { ComplexLike } from '@stdlib/types/complex';
25
+
26
+ /**
27
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
28
+ *
29
+ * @param x - input array
30
+ * @param value - scalar value
31
+ * @returns zero-dimensional ndarray
32
+ *
33
+ * @example
34
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
35
+ *
36
+ * var x = zeros( 'float64', [ 2, 2 ], 'row-major' );
37
+ * // returns <ndarray>
38
+ *
39
+ * var y = scalar2ndarrayLike( x, 1.0 );
40
+ * // returns <ndarray>
41
+ *
42
+ * var sh = y.shape;
43
+ * // returns []
44
+ *
45
+ * var dt = y.dtype;
46
+ * // returns 'float64'
47
+ *
48
+ * var v = y.get();
49
+ * // returns 1.0
50
+ */
51
+ declare function scalar2ndarrayLike( x: float64ndarray, value: number ): float64ndarray;
52
+
53
+ /**
54
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
55
+ *
56
+ * @param x - input array
57
+ * @param value - scalar value
58
+ * @returns zero-dimensional ndarray
59
+ *
60
+ * @example
61
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
62
+ *
63
+ * var x = zeros( 'float32', [ 2, 2 ], 'row-major' );
64
+ * // returns <ndarray>
65
+ *
66
+ * var y = scalar2ndarrayLike( x, 1.0 );
67
+ * // returns <ndarray>
68
+ *
69
+ * var sh = y.shape;
70
+ * // returns []
71
+ *
72
+ * var dt = y.dtype;
73
+ * // returns 'float32'
74
+ *
75
+ * var v = y.get();
76
+ * // returns 1.0
77
+ */
78
+ declare function scalar2ndarrayLike( x: float32ndarray, value: number ): float32ndarray;
79
+
80
+ /**
81
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
82
+ *
83
+ * ## Notes
84
+ *
85
+ * - If provided a number, the function returns a zero-dimensional ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero.
86
+ *
87
+ * @param x - input array
88
+ * @param value - scalar value
89
+ * @returns zero-dimensional ndarray
90
+ *
91
+ * @example
92
+ * var Complex128 = require( '@stdlib/complex-float64-ctor' );
93
+ * var real = require( '@stdlib/complex-float64-real' );
94
+ * var imag = require( '@stdlib/complex-float64-imag' );
95
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
96
+ *
97
+ * var x = zeros( 'complex128', [ 2, 2 ], 'row-major' );
98
+ * // returns <ndarray>
99
+ *
100
+ * var v = new Complex128( 1.0, 2.0 );
101
+ *
102
+ * var y = scalar2ndarrayLike( x, v );
103
+ * // returns <ndarray>
104
+ *
105
+ * var sh = y.shape;
106
+ * // returns []
107
+ *
108
+ * var dt = y.dtype;
109
+ * // returns 'complex128'
110
+ *
111
+ * var v = y.get();
112
+ * // returns <Complex128>
113
+ *
114
+ * var re = real( v );
115
+ * // returns 1.0
116
+ *
117
+ * var im = imag( v );
118
+ * // returns 2.0
119
+ */
120
+ declare function scalar2ndarrayLike( x: complex128ndarray, value: ComplexLike | number ): complex128ndarray;
121
+
122
+ /**
123
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
124
+ *
125
+ * ## Notes
126
+ *
127
+ * - If provided a number, the function returns a zero-dimensional ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero.
128
+ *
129
+ * @param x - input array
130
+ * @param value - scalar value
131
+ * @returns zero-dimensional ndarray
132
+ *
133
+ * @example
134
+ * var Complex64 = require( '@stdlib/complex-float32-ctor' );
135
+ * var realf = require( '@stdlib/complex-float32-real' );
136
+ * var imagf = require( '@stdlib/complex-float32-imag' );
137
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
138
+ *
139
+ * var x = zeros( 'complex64', [ 2, 2 ], 'row-major' );
140
+ * // returns <ndarray>
141
+ *
142
+ * var v = new Complex64( 1.0, 2.0 );
143
+ *
144
+ * var y = scalar2ndarrayLike( x, v );
145
+ * // returns <ndarray>
146
+ *
147
+ * var sh = y.shape;
148
+ * // returns []
149
+ *
150
+ * var dt = y.dtype;
151
+ * // returns 'complex64'
152
+ *
153
+ * var v = y.get();
154
+ * // returns <Complex64>
155
+ *
156
+ * var re = realf( v );
157
+ * // returns 1.0
158
+ *
159
+ * var im = imagf( v );
160
+ * // returns 2.0
161
+ */
162
+ declare function scalar2ndarrayLike( x: complex64ndarray, value: ComplexLike | number ): complex64ndarray;
163
+
164
+ /**
165
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
166
+ *
167
+ * @param x - input array
168
+ * @param value - scalar value
169
+ * @returns zero-dimensional ndarray
170
+ *
171
+ * @example
172
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
173
+ *
174
+ * var x = zeros( 'int32', [ 2, 2 ], 'row-major' );
175
+ * // returns <ndarray>
176
+ *
177
+ * var y = scalar2ndarrayLike( x, 1 );
178
+ * // returns <ndarray>
179
+ *
180
+ * var sh = y.shape;
181
+ * // returns []
182
+ *
183
+ * var dt = y.dtype;
184
+ * // returns 'int32'
185
+ *
186
+ * var v = y.get();
187
+ * // returns 1
188
+ */
189
+ declare function scalar2ndarrayLike( x: int32ndarray, value: number ): int32ndarray;
190
+
191
+ /**
192
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
193
+ *
194
+ * @param x - input array
195
+ * @param value - scalar value
196
+ * @returns zero-dimensional ndarray
197
+ *
198
+ * @example
199
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
200
+ *
201
+ * var x = zeros( 'int16', [ 2, 2 ], 'row-major' );
202
+ * // returns <ndarray>
203
+ *
204
+ * var y = scalar2ndarrayLike( x, 1 );
205
+ * // returns <ndarray>
206
+ *
207
+ * var sh = y.shape;
208
+ * // returns []
209
+ *
210
+ * var dt = y.dtype;
211
+ * // returns 'int16'
212
+ *
213
+ * var v = y.get();
214
+ * // returns 1
215
+ */
216
+ declare function scalar2ndarrayLike( x: int16ndarray, value: number ): int16ndarray;
217
+
218
+ /**
219
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
220
+ *
221
+ * @param x - input array
222
+ * @param value - scalar value
223
+ * @returns zero-dimensional ndarray
224
+ *
225
+ * @example
226
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
227
+ *
228
+ * var x = zeros( 'int8', [ 2, 2 ], 'row-major' );
229
+ * // returns <ndarray>
230
+ *
231
+ * var y = scalar2ndarrayLike( x, 1 );
232
+ * // returns <ndarray>
233
+ *
234
+ * var sh = y.shape;
235
+ * // returns []
236
+ *
237
+ * var dt = y.dtype;
238
+ * // returns 'int8'
239
+ *
240
+ * var v = y.get();
241
+ * // returns 1
242
+ */
243
+ declare function scalar2ndarrayLike( x: int8ndarray, value: number ): int8ndarray;
244
+
245
+ /**
246
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
247
+ *
248
+ * @param x - input array
249
+ * @param value - scalar value
250
+ * @returns zero-dimensional ndarray
251
+ *
252
+ * @example
253
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
254
+ *
255
+ * var x = zeros( 'uint32', [ 2, 2 ], 'row-major' );
256
+ * // returns <ndarray>
257
+ *
258
+ * var y = scalar2ndarrayLike( x, 1 );
259
+ * // returns <ndarray>
260
+ *
261
+ * var sh = y.shape;
262
+ * // returns []
263
+ *
264
+ * var dt = y.dtype;
265
+ * // returns 'uint32'
266
+ *
267
+ * var v = y.get();
268
+ * // returns 1
269
+ */
270
+ declare function scalar2ndarrayLike( x: uint32ndarray, value: number ): uint32ndarray;
271
+
272
+ /**
273
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
274
+ *
275
+ * @param x - input array
276
+ * @param value - scalar value
277
+ * @returns zero-dimensional ndarray
278
+ *
279
+ * @example
280
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
281
+ *
282
+ * var x = zeros( 'uint16', [ 2, 2 ], 'row-major' );
283
+ * // returns <ndarray>
284
+ *
285
+ * var y = scalar2ndarrayLike( x, 1 );
286
+ * // returns <ndarray>
287
+ *
288
+ * var sh = y.shape;
289
+ * // returns []
290
+ *
291
+ * var dt = y.dtype;
292
+ * // returns 'uint16'
293
+ *
294
+ * var v = y.get();
295
+ * // returns 1
296
+ */
297
+ declare function scalar2ndarrayLike( x: uint16ndarray, value: number ): uint16ndarray;
298
+
299
+ /**
300
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
301
+ *
302
+ * @param x - input array
303
+ * @param value - scalar value
304
+ * @returns zero-dimensional ndarray
305
+ *
306
+ * @example
307
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
308
+ *
309
+ * var x = zeros( 'uint8', [ 2, 2 ], 'row-major' );
310
+ * // returns <ndarray>
311
+ *
312
+ * var y = scalar2ndarrayLike( x, 1 );
313
+ * // returns <ndarray>
314
+ *
315
+ * var sh = y.shape;
316
+ * // returns []
317
+ *
318
+ * var dt = y.dtype;
319
+ * // returns 'uint8'
320
+ *
321
+ * var v = y.get();
322
+ * // returns 1
323
+ */
324
+ declare function scalar2ndarrayLike( x: uint8ndarray, value: number ): uint8ndarray;
325
+
326
+ /**
327
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
328
+ *
329
+ * @param x - input array
330
+ * @param value - scalar value
331
+ * @returns zero-dimensional ndarray
332
+ *
333
+ * @example
334
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
335
+ *
336
+ * var x = zeros( 'uint8c', [ 2, 2 ], 'row-major' );
337
+ * // returns <ndarray>
338
+ *
339
+ * var y = scalar2ndarrayLike( x, 1 );
340
+ * // returns <ndarray>
341
+ *
342
+ * var sh = y.shape;
343
+ * // returns []
344
+ *
345
+ * var dt = y.dtype;
346
+ * // returns 'uint8c'
347
+ *
348
+ * var v = y.get();
349
+ * // returns 1
350
+ */
351
+ declare function scalar2ndarrayLike( x: uint8cndarray, value: number ): uint8cndarray;
352
+
353
+ /**
354
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
355
+ *
356
+ * @param x - input array
357
+ * @param value - scalar value
358
+ * @returns zero-dimensional ndarray
359
+ *
360
+ * @example
361
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
362
+ *
363
+ * var x = zeros( 'bool', [ 2, 2 ], 'row-major' );
364
+ * // returns <ndarray>
365
+ *
366
+ * var y = scalar2ndarrayLike( x, true );
367
+ * // returns <ndarray>
368
+ *
369
+ * var sh = y.shape;
370
+ * // returns []
371
+ *
372
+ * var dt = y.dtype;
373
+ * // returns 'bool'
374
+ *
375
+ * var v = y.get();
376
+ * // returns true
377
+ */
378
+ declare function scalar2ndarrayLike( x: boolndarray, value: boolean ): boolndarray;
379
+
380
+ /**
381
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
382
+ *
383
+ * @param x - input array
384
+ * @param value - scalar value
385
+ * @returns zero-dimensional ndarray
386
+ *
387
+ * @example
388
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
389
+ *
390
+ * var x = zeros( 'generic', [ 2, 2 ], 'row-major' );
391
+ * // returns <ndarray>
392
+ *
393
+ * var y = scalar2ndarrayLike( x, 1.0 );
394
+ * // returns <ndarray>
395
+ *
396
+ * var sh = y.shape;
397
+ * // returns []
398
+ *
399
+ * var dt = y.dtype;
400
+ * // returns 'generic'
401
+ *
402
+ * var v = y.get();
403
+ * // returns 1.0
404
+ */
405
+ declare function scalar2ndarrayLike<T = unknown>( x: genericndarray<T>, value: T ): genericndarray<T>;
406
+
407
+ /**
408
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided input ndarray.
409
+ *
410
+ * @param x - input array
411
+ * @param value - scalar value
412
+ * @returns zero-dimensional ndarray
413
+ *
414
+ * @example
415
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
416
+ *
417
+ * var x = zeros( 'float64', [ 2, 2 ], 'row-major' );
418
+ * // returns <ndarray>
419
+ *
420
+ * var y = scalar2ndarrayLike( x, 1.0 );
421
+ * // returns <ndarray>
422
+ *
423
+ * var sh = y.shape;
424
+ * // returns []
425
+ *
426
+ * var dt = y.dtype;
427
+ * // returns 'float64'
428
+ *
429
+ * var v = y.get();
430
+ * // returns 1.0
431
+ */
432
+ declare function scalar2ndarrayLike<T = unknown>( x: typedndarray<T>, value: T ): typedndarray<T>;
433
+
434
+
435
+ // EXPORTS //
436
+
437
+ export = scalar2ndarrayLike;
package/lib/index.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ /**
22
+ * Convert a scalar value to a zero-dimensional ndarray having the same data type as a provided ndarray.
23
+ *
24
+ * @module @stdlib/ndarray-base-from-scalar-like
25
+ *
26
+ * @example
27
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
28
+ * var scalar2ndarrayLike = require( '@stdlib/ndarray-base-from-scalar-like' );
29
+ *
30
+ * var x = zeros( 'float32', [ 2, 2 ], 'row-major' );
31
+ * // returns <ndarray>
32
+ *
33
+ * var y = scalar2ndarrayLike( x, 1.0 );
34
+ * // returns <ndarray>
35
+ *
36
+ * var sh = y.shape;
37
+ * // returns []
38
+ *
39
+ * var dt = y.dtype;
40
+ * // returns 'float32'
41
+ *
42
+ * var v = y.get();
43
+ * // returns 1.0
44
+ */
45
+
46
+ // MODULES //
47
+
48
+ var main = require( './main.js' );
49
+
50
+
51
+ // EXPORTS //
52
+
53
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ // MODULES //
22
+
23
+ var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
24
+ var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );
25
+ var accessorSetter = require( '@stdlib/array-base-accessor-setter' );
26
+ var setter = require( '@stdlib/array-base-setter' );
27
+ var getDType = require( '@stdlib/ndarray-base-dtype' );
28
+ var getOrder = require( '@stdlib/ndarray-base-order' );
29
+ var emptyArray = require( '@stdlib/array-empty' );
30
+ var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
31
+
32
+
33
+ // MAIN //
34
+
35
+ /**
36
+ * Returns a zero-dimensional ndarray containing a provided scalar value and having the same data type as a provided ndarray.
37
+ *
38
+ * @param {ndarray} x - input array
39
+ * @param {*} value - scalar value
40
+ * @throws {TypeError} first argument must have a recognized data type
41
+ * @returns {ndarray} ndarray
42
+ *
43
+ * @example
44
+ * var zeros = require( '@stdlib/ndarray-base-zeros' );
45
+ *
46
+ * var x = zeros( 'float32', [ 2, 2 ], 'row-major' );
47
+ * // returns <ndarray>
48
+ *
49
+ * var y = scalar2ndarrayLike( x, 1.0 );
50
+ * // returns <ndarray>
51
+ *
52
+ * var sh = y.shape;
53
+ * // returns []
54
+ *
55
+ * var dt = y.dtype;
56
+ * // returns 'float32'
57
+ *
58
+ * var v = y.get();
59
+ * // returns 1.0
60
+ */
61
+ function scalar2ndarrayLike( x, value ) {
62
+ var buf;
63
+ var set;
64
+ var dt;
65
+
66
+ dt = getDType( x );
67
+ if ( dt === 'binary' ) {
68
+ buf = allocUnsafe( 1 );
69
+ } else {
70
+ buf = emptyArray( 1, dt );
71
+ }
72
+ if ( /^complex/.test( dt ) && isNumber( value ) ) {
73
+ value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components
74
+ }
75
+ if ( isAccessorArray( buf ) ) {
76
+ set = accessorSetter( dt );
77
+ } else {
78
+ set = setter( dt );
79
+ }
80
+ set( buf, 0, value );
81
+ return new x.constructor( dt, buf, [], [ 0 ], 0, getOrder( x ) );
82
+ }
83
+
84
+
85
+ // EXPORTS //
86
+
87
+ module.exports = scalar2ndarrayLike;
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@stdlib/ndarray-base-from-scalar-like",
3
+ "version": "0.1.0",
4
+ "description": "Convert a scalar value to a zero-dimensional ndarray having the same data type as a provided ndarray.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "doc": "./docs",
19
+ "lib": "./lib",
20
+ "dist": "./dist"
21
+ },
22
+ "types": "./docs/types",
23
+ "scripts": {},
24
+ "homepage": "https://stdlib.io",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/stdlib-js/ndarray-base-from-scalar-like.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/stdlib-js/stdlib/issues"
31
+ },
32
+ "dependencies": {
33
+ "@stdlib/array-base-accessor-setter": "^0.2.2",
34
+ "@stdlib/array-base-assert-is-accessor-array": "^0.2.2",
35
+ "@stdlib/array-base-setter": "^0.2.2",
36
+ "@stdlib/array-empty": "^0.3.0",
37
+ "@stdlib/assert-is-number": "^0.2.2",
38
+ "@stdlib/buffer-alloc-unsafe": "^0.2.2",
39
+ "@stdlib/ndarray-base-dtype": "^0.2.2",
40
+ "@stdlib/ndarray-base-order": "^0.2.2"
41
+ },
42
+ "devDependencies": {},
43
+ "engines": {
44
+ "node": ">=0.10.0",
45
+ "npm": ">2.7.0"
46
+ },
47
+ "os": [
48
+ "aix",
49
+ "darwin",
50
+ "freebsd",
51
+ "linux",
52
+ "macos",
53
+ "openbsd",
54
+ "sunos",
55
+ "win32",
56
+ "windows"
57
+ ],
58
+ "keywords": [
59
+ "stdlib",
60
+ "stdtypes",
61
+ "types",
62
+ "base",
63
+ "data",
64
+ "structure",
65
+ "ndarray",
66
+ "scalar",
67
+ "wrap",
68
+ "convert"
69
+ ],
70
+ "funding": {
71
+ "type": "opencollective",
72
+ "url": "https://opencollective.com/stdlib"
73
+ }
74
+ }