Skip to content

Commit 126f380

Browse files
committed
Auto-generated commit
1 parent 5bfeb44 commit 126f380

File tree

8 files changed

+32
-8
lines changed

8 files changed

+32
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ arr = ndarray2array( v );
107107

108108
The function accepts the following `options`:
109109

110-
- **readonly**: boolean indicating whether returned [`ndarray`][@stdlib/ndarray/ctor] views should be read-only. Default: `true`.
110+
- **readonly**: boolean indicating whether returned [`ndarray`][@stdlib/ndarray/ctor] views should be read-only. In order to return writable [`ndarray`][@stdlib/ndarray/ctor] views, the input [`ndarray`][@stdlib/ndarray/ctor] must be writable. If the input [`ndarray`][@stdlib/ndarray/ctor] is read-only, setting this option to `false` raises an exception. Default: `true`.
111111

112112
By default, the iterator returns [`ndarray`][@stdlib/ndarray/ctor] views which are **read-only**. To return writable [views][@stdlib/ndarray/slice], set the `readonly` option to `false`.
113113

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/repl.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
options.readonly: boolean (optional)
2222
Boolean indicating whether returned ndarray views should be read-only.
23-
Default: true.
23+
If the input ndarray is read-only, setting this option to `false` raises
24+
an exception. Default: true.
2425

2526
Returns
2627
-------

docs/types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ type Iterator<T> = TypedIterator<T> | TypedIterableIterator<T>;
3232
interface Options {
3333
/**
3434
* Boolean indicating whether returned views should be read-only (default: true).
35+
*
36+
* ## Notes
37+
*
38+
* - If the input array is read-only, setting this option to `false` raises an exception.
3539
*/
3640
readonly?: boolean;
3741
}

lib/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-propert
2424
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
2525
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
2626
var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );
27+
var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );
2728
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
2829
var iteratorSymbol = require( '@stdlib/symbol-iterator' );
2930
var zeros = require( '@stdlib/array-base-zeros' );
@@ -46,6 +47,7 @@ var format = require( '@stdlib/string-format' );
4647
* @throws {TypeError} first argument must have at least two dimensions
4748
* @throws {TypeError} options argument must be an object
4849
* @throws {TypeError} must provide valid options
50+
* @throws {Error} cannot write to a read-only array
4951
* @returns {Iterator} iterator
5052
*
5153
* @example
@@ -106,6 +108,9 @@ function nditerRows( x ) {
106108
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );
107109
}
108110
opts.writable = !options.readonly;
111+
if ( opts.writable && isReadOnly( x ) ) {
112+
throw new Error( format( 'invalid option. Cannot write to read-only array.' ) );
113+
}
109114
}
110115
}
111116
// Retrieve input array meta data:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@stdlib/assert-is-boolean": "^0.1.1",
4343
"@stdlib/assert-is-ndarray-like": "^0.1.0",
4444
"@stdlib/assert-is-plain-object": "^0.1.1",
45+
"@stdlib/ndarray-base-assert-is-read-only": "^0.1.1",
4546
"@stdlib/ndarray-base-next-cartesian-index": "github:stdlib-js/ndarray-base-next-cartesian-index#main",
4647
"@stdlib/ndarray-base-numel": "^0.1.1",
4748
"@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main",
@@ -56,7 +57,6 @@
5657
"@stdlib/assert-is-iterator-like": "^0.1.1",
5758
"@stdlib/bench": "^0.1.0",
5859
"@stdlib/ndarray-array": "^0.1.0",
59-
"@stdlib/ndarray-base-assert-is-read-only": "^0.1.1",
6060
"@stdlib/ndarray-slice": "github:stdlib-js/ndarray-slice#main",
6161
"@stdlib/ndarray-to-array": "^0.1.0",
6262
"@stdlib/ndarray-zeros": "^0.1.0",

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ tape( 'the function throws an error if provided a `readonly` option which is not
155155
}
156156
});
157157

158+
tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) {
159+
t.throws( badValue, Error, 'throws an error' );
160+
t.end();
161+
162+
function badValue() {
163+
var x = zeros( [ 2, 2 ], {
164+
'readonly': true
165+
});
166+
nditerRows( x, {
167+
'readonly': false
168+
});
169+
}
170+
});
171+
158172
tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) {
159173
var values;
160174
var i;

0 commit comments

Comments
 (0)