Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Dec 30, 2023
1 parent 0281e54 commit 018d924
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 5 deletions.
31 changes: 30 additions & 1 deletion complex64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,6 @@ bool = arr.includes( new Complex64( 4.0, -4.0 ), -3 );
// returns true
```


<a name="method-index-of"></a>

#### Complex64Array.prototype.indexOf( searchElement\[, fromIndex] )
Expand Down Expand Up @@ -1478,6 +1477,36 @@ idx = arr.indexOf( new Complex64( 1.0, -1.0 ), 1 );
// returns -1
```

<a name="method-join"></a>

#### Complex64Array.prototype.join( \[separator] )

Returns a new string by concatenating all array elements.

```javascript
var arr = new Complex64Array( 3 );

arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );

var str = arr.join();
// returns '1 + 1i,2 - 2i,3 + 3i'
```

By default, the method separates serialized array elements with a comma. To use an alternative separator, provide a `separator` string.

```javascript
var arr = new Complex64Array( 3 );

arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );

var str = arr.join( '/' );
// returns '1 + 1i/2 - 2i/3 + 3i'
```

<a name="method-last-index-of"></a>

#### Complex64Array.prototype.lastIndexOf( searchElement\[, fromIndex] )
Expand Down
50 changes: 50 additions & 0 deletions complex64/benchmark/benchmark.join.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var pkg = require( './../package.json' ).name;
var Complex64Array = require( './../lib' );


// MAIN //

bench( pkg+':join', function benchmark( b ) {
var out;
var arr;
var i;

arr = new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.join();
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});
102 changes: 102 additions & 0 deletions complex64/benchmark/benchmark.join.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex64 = require( '@stdlib/complex/float32' );
var pkg = require( './../package.json' ).name;
var Complex64Array = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr;
var i;

arr = [];
for ( i = 0; i < len; i++ ) {
arr.push( new Complex64( i, i ) );
}
arr = new Complex64Array( arr );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.join( '/' );
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':join:len='+len, f );
}
}

main();
20 changes: 20 additions & 0 deletions complex64/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,26 @@ declare class Complex64Array implements Complex64ArrayInterface {
*/
indexOf( searchElement: ComplexLike, fromIndex?: number ): number;

/**
* Returns a new string by concatenating all array elements.
*
* @param separator - value separator (default: ',')
* @returns string
*
* @example
* var arr = new Complex64Array( 2 );
*
* arr.set( [ 1.0, 1.0 ], 0 );
* arr.set( [ 2.0, 2.0 ], 1 );
*
* var str = arr.join();
* // returns '1 + 1i,2 + 2i'
*
* str = arr.join( '/' );
* // returns '1 + 1i/2 + 2i'
*/
join( separator?: string ): string;

/**
* Returns the last index at which a given element can be found.
*
Expand Down
47 changes: 47 additions & 0 deletions complex64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var isCollection = require( '@stdlib/assert/is-collection' );
var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' );
var isObject = require( '@stdlib/assert/is-object' );
var isArray = require( '@stdlib/assert/is-array' );
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var isFunction = require( '@stdlib/assert/is-function' );
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
var isEven = require( '@stdlib/math/base/assert/is-even' );
Expand Down Expand Up @@ -1522,6 +1523,52 @@ setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElemen
return -1;
});

/**
* Returns a new string by concatenating all array elements.
*
* @name join
* @memberof Complex64Array.prototype
* @type {Function}
* @param {string} [separator=','] - element separator
* @throws {TypeError} `this` must be a complex number array
* @throws {TypeError} first argument must be a string
* @returns {string} string representation
*
* @example
* var arr = new Complex64Array( 2 );
*
* arr.set( [ 1.0, 1.0 ], 0 );
* arr.set( [ 2.0, 2.0 ], 1 );
*
* var str = arr.join();
* // returns '1 + 1i,2 + 2i'
*
* str = arr.join( '/' );
* // returns '1 + 1i/2 + 2i'
*/
setReadOnly( Complex64Array.prototype, 'join', function join( separator ) {
var out;
var buf;
var sep;
var i;
if ( !isComplexArray( this ) ) {
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
}
if ( arguments.length === 0 ) {
sep = ',';
} else if ( isString( separator ) ) {
sep = separator;
} else {
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) );
}
out = [];
buf = this._buffer;
for ( i = 0; i < this._length; i++ ) {
out.push( getComplex64( buf, i ).toString() );
}
return out.join( sep );
});

/**
* Returns the last index at which a given element can be found.
*
Expand Down
Loading

0 comments on commit 018d924

Please sign in to comment.