You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Converts an ndarray instance to a primitive value.
575
+
*
576
+
* ## Notes
577
+
*
578
+
* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects.
579
+
*
580
+
* @name valueOf
581
+
* @memberof ndarray.prototype
582
+
* @type {Function}
583
+
* @returns {(*|ndarray)} result
584
+
*
585
+
* @example
586
+
* var buffer = [ 3.14 ];
587
+
* var shape = [];
588
+
* var strides = [ 0 ];
589
+
* var offset = 0;
590
+
*
591
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
592
+
*
593
+
* var v = x.valueOf();
594
+
* // returns 3.14
595
+
*
596
+
* @example
597
+
* var buffer = [ 3.14 ];
598
+
* var shape = [ 1 ];
599
+
* var strides = [ 1 ];
600
+
* var offset = 0;
601
+
*
602
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
* 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
+
// MAIN //
22
+
23
+
/**
24
+
* Converts an ndarray instance to a primitive value.
25
+
*
26
+
* ## Notes
27
+
*
28
+
* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects.
Copy file name to clipboardExpand all lines: vector/ctor/lib/main.js
+17-8Lines changed: 17 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -165,7 +165,7 @@ function arraybuffer2vector( dtype, buffer, length, stride, byteOffset, order, o
165
165
N=length*stride;
166
166
167
167
// Adjust the byte offset to point to the element marking the beginning of the view:
168
-
if(stride<0){
168
+
if(stride<0){// TODO: the following is effectively unreachable code, as provided strides are never anything other than unity; however, we keep this around in the event that we want to extract this function to a separate package and would like to maintain generality
169
169
N*=-1;
170
170
o-=N*bytesPerElement(dtype);
171
171
}
@@ -483,6 +483,9 @@ function vector() {
483
483
if(nargs===2){
484
484
// Case: vector( dtype, options )
485
485
if(isDataType(arg0)){
486
+
if(arg1===null){
487
+
thrownewTypeError(format('invalid argument. Options argument must be an object. Value: `%s`.',arg1));
thrownewTypeError(format('invalid argument. Options argument must be an object. Value: `%s`.',arg1));
509
+
}
504
510
out=vectorWithDType(arg0,DEFAULT_DTYPE,arg1);
505
511
if(out===null){
506
512
thrownewTypeError(format('invalid argument. First argument must be a length, ArrayBuffer, typed array, array-like object, or iterable. Value: `%s`.',arg0));
@@ -523,6 +529,9 @@ function vector() {
523
529
}
524
530
// Case: vector( arg0, dtype, options )
525
531
if(isDataType(arg1)){
532
+
if(arg2===null){
533
+
thrownewTypeError(format('invalid argument. Options argument must be an object. Value: `%s`.',arg2));
534
+
}
526
535
out=vectorWithDType(arg0,arg1,arg2);
527
536
if(out===null){
528
537
thrownewTypeError(format('invalid argument. First argument must be a length, ArrayBuffer, typed array, array-like object, or iterable. Value: `%s`.',arg0));
@@ -536,15 +545,15 @@ function vector() {
536
545
if(!isNonNegativeInteger(arg1)){
537
546
thrownewTypeError(format('invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.',arg1));
0 commit comments