Skip to content

Commit ab7bc62

Browse files
committed
feat: add tests and update main and readme accordingly
1 parent 3554f06 commit ab7bc62

File tree

3 files changed

+627
-3
lines changed

3 files changed

+627
-3
lines changed

lib/node_modules/@stdlib/ndarray/base/eye/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ The function accepts the following arguments:
8080

8181
## Notes
8282

83+
- If the provided [data type][@stdlib/ndarray/dtypes] is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero
84+
85+
- If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros
8386

8487
</section>
8588

lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' );
2424
var accessorSetter = require( '@stdlib/array/base/accessor-setter' );
2525
var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' );
26+
var isInteger = require( '@stdlib/assert/is-integer' );
27+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' );
2628
var ctors = require( '@stdlib/complex/ctors' );
2729
var max = require( '@stdlib/math/base/special/max' );
2830
var min = require( '@stdlib/math/base/special/min' );
31+
var format = require( '@stdlib/string/format' );
2932
var zeros = require( '@stdlib/ndarray/base/zeros' );
3033

3134

@@ -50,10 +53,13 @@ function setter( buf, idx, v ) {
5053
* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere.
5154
*
5255
* @param {*} dtype - output array data type
53-
* @param {Number} rows - output array number of rows
54-
* @param {Number} cols - output array number of columns
55-
* @param {Number} k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal
56+
* @param {NonNegativeInteger} rows - output array number of rows
57+
* @param {NonNegativeInteger} cols - output array number of columns
58+
* @param {IntegerNumber} k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal
5659
* @param {string} order - memory layout (either row-major or column-major)
60+
* @throws {TypeError} first argument must be a recognized data type
61+
* @throws {TypeError} fourth argument must be an integer
62+
* @throws {TypeError} second and third arguments must be non-negative integers
5763
* @returns {ndarray} ndarray
5864
*
5965
* @example
@@ -87,6 +93,14 @@ function eye( dtype, rows, cols, k, order ) {
8793
var c;
8894
var x;
8995

96+
if ( !isInteger( k ) ) {
97+
throw new TypeError( format('invalid arguments. Diagonal index must be an integer. Value: %s.', k) );
98+
}
99+
100+
if ( !isNonNegativeInteger( rows ) || !isNonNegativeInteger( cols ) ) {
101+
throw new TypeError( format('invalid arguments. Rows and columns must be non-negative integers. Value: %s, %s.', rows, cols) );
102+
}
103+
90104
if ( k < 0 ) {
91105
r = -k;
92106
c = 0;

0 commit comments

Comments
 (0)