Skip to content

Commit bc8b428

Browse files
committed
Auto-generated commit
1 parent 8843c9d commit bc8b428

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

from-scalar/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ The function accepts the following `options`:
6666

6767
If a `dtype` option is not provided and `value`
6868

69-
- is a `number`, the default [data type][@stdlib/ndarray/dtypes] is `'float64'`.
70-
- is a complex number object, the default [data type][@stdlib/ndarray/dtypes] is `'complex128'`.
69+
- is a `number`, the default [data type][@stdlib/ndarray/dtypes] is the [default][@stdlib/ndarray/defaults] real-valued floating-point data type.
70+
- is a complex number object of a known data type, the data type is the same as the provided value.
71+
- is a complex number object of an unknown data type, the default [data type][@stdlib/ndarray/dtypes] is the [default][@stdlib/ndarray/defaults] complex-valued floating-point data type.
7172
- is any other value type, the default [data type][@stdlib/ndarray/dtypes] is `'generic'`.
7273

7374
To explicitly specify the [data type][@stdlib/ndarray/dtypes] of the returned [`ndarray`][@stdlib/ndarray/ctor], provide a `dtype` option.
@@ -165,6 +166,8 @@ for ( i = 0; i < dt.length; i++ ) {
165166

166167
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
167168

169+
[@stdlib/ndarray/defaults]: https://github.com/stdlib-js/ndarray/tree/main/defaults
170+
168171
<!-- <related-links> -->
169172

170173
[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray/tree/main/array

from-scalar/docs/repl.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
options.dtype: string (optional)
1919
Data type. If not provided and `value`
2020

21-
- is a number, the default data type is 'float64'.
22-
- is a complex number object, the default data type is 'complex128'.
21+
- is a number, the default data type is the default real-valued
22+
floating-point data type.
23+
- is a complex number object of a known complex data type, the data type
24+
is the same as the provided value.
25+
- is a complex number object of an unknown data type, the default data
26+
type is the default complex-valued floating-point data type.
2327
- is any other value type, the default data type is 'generic'.
2428

2529
options.order: string (optional)

from-scalar/docs/types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ declare function scalar2ndarray( value: number, options: Uint8cOptions ): uint8c
461461
*
462462
* - If a `dtype` option is not provided and `value`
463463
*
464-
* - is a `number`, the default data type is `'float64'`.
465-
* - is a complex number object, the default data type is `'complex128'`.
464+
* - is a `number`, the default data type is the default real-valued floating-point data type.
465+
* - is a complex number object of a known complex data type, the data type is the same as the provided value.
466+
* - is a complex number object of an unknown complex data type, the default data type is the default complex-valued floating-point data type.
466467
* - is any other value type, the default data type is `'generic'`.
467468
*
468469
* @param value - scalar value

from-scalar/lib/main.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ var setter = require( '@stdlib/array/base/setter' );
3030
var buffer = require( './../../base/buffer' );
3131
var ndarray = require( './../../ctor' );
3232
var defaults = require( './../../defaults' );
33+
var dtype = require( '@stdlib/complex/dtype' );
3334
var format = require( '@stdlib/string/format' );
3435

3536

3637
// VARIABLES //
3738

3839
var ORDER = defaults.get( 'order' );
40+
var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' );
41+
var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' );
3942

4043

4144
// MAIN //
@@ -47,8 +50,9 @@ var ORDER = defaults.get( 'order' );
4750
*
4851
* - If a `dtype` option is not provided and `value`
4952
*
50-
* - is a `number`, the default data type is `'float64'`.
51-
* - is a complex number object, the default data type is `'complex128'`.
53+
* - is a `number`, the default data type is the default real-valued floating-point data type.
54+
* - is a complex number object of a known complex data type, the data type is the same as the provided value.
55+
* - is a complex number object of an unknown complex data type, the default data type is the default complex-valued floating-point data type.
5256
* - is any other value type, the default data type is `'generic'`.
5357
*
5458
* @param {*} value - scalar value
@@ -120,9 +124,12 @@ function scalar2ndarray( value ) {
120124
flg = isNumber( value );
121125
if ( opts.dtype === '' ) {
122126
if ( flg ) {
123-
dt = 'float64';
127+
dt = DEFAULT_REAL;
124128
} else if ( isComplexLike( value ) ) {
125-
dt = 'complex128';
129+
dt = dtype( value );
130+
if ( dt === null ) {
131+
dt = DEFAULT_CMPLX;
132+
}
126133
} else {
127134
dt = 'generic';
128135
}

from-scalar/test/test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ tape( 'the function returns a zero-dimensional ndarray (default, number)', funct
188188
t.end();
189189
});
190190

191-
tape( 'the function returns a zero-dimensional ndarray (default, complex)', function test( t ) {
191+
tape( 'the function returns a zero-dimensional ndarray (default, complex128)', function test( t ) {
192192
var expected;
193193
var arr;
194194
var v;
195195

196196
expected = new Float64Array( [ 1.0, 2.0 ] );
197197

198-
v = new Complex64( 1.0, 2.0 );
198+
v = new Complex128( 1.0, 2.0 );
199199
arr = scalar2ndarray( v );
200200

201201
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );
@@ -209,6 +209,27 @@ tape( 'the function returns a zero-dimensional ndarray (default, complex)', func
209209
t.end();
210210
});
211211

212+
tape( 'the function returns a zero-dimensional ndarray (default, complex64)', function test( t ) {
213+
var expected;
214+
var arr;
215+
var v;
216+
217+
expected = new Float32Array( [ 1.0, 2.0 ] );
218+
219+
v = new Complex64( 1.0, 2.0 );
220+
arr = scalar2ndarray( v );
221+
222+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );
223+
t.strictEqual( arr.dtype, 'complex64', 'returns expected value' );
224+
t.deepEqual( arr.shape, [], 'returns expected value' );
225+
t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' );
226+
t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' );
227+
t.strictEqual( arr.order, 'row-major', 'returns expected value' );
228+
t.strictEqual( arr.length, 1, 'returns expected value' );
229+
230+
t.end();
231+
});
232+
212233
tape( 'the function returns a zero-dimensional ndarray (default, other)', function test( t ) {
213234
var expected;
214235
var arr;

0 commit comments

Comments
 (0)