nl_tokens: CAST // FUNCTION : cast ( x type ) Casts an input array or array - like object to a specified type .
pl_tokens: function cast ( x , <mask> ) { /* jshint newcap:false */ var ctor , len , d , i ; if ( ! arrayLike ( x ) ) { throw new TypeError ( 'invalid input argument. First argument must be an array-like object. Value: `' + x + '`.' ) ; } if ( typeof type === 'string' ) { ctor = getCtor ( type ) ; } else { ctor = getCtor ( dtype ( typeName ( type ) ) ) ; } if ( ctor === null ) { throw new Error ( 'invalid input argument. Unrecognized/unsupported type to which to cast. Value: `' + type + '`.' ) ; } len = x . length ; // Ensure fast elements (contiguous memory)... if ( type === 'generic' && len > 64000 ) { d = new ctor ( 64000 ) ; for ( i = 0 ; i < 64000 ; i ++ ) { d [ i ] = x [ i ] ; } for ( i = 64000 ; i < len ; i ++ ) { d . push ( x [ i ] ) ; } } else { d = new ctor ( len ) ; for ( i = 0 ; i < len ; i ++ ) { d [ i ] = x [ i ] ; } } return d ; }