Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .ralph/state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Ralph Loop State

## Issue
GitHub issue #2777 (stdlib-js/todo): Review `@stdlib/ndarray/base/trues-like`

Issue text: "Review `@stdlib/ndarray/base/trues-like`."

This is a "review" issue meaning the package needs to be created (it does not exist yet).

## Acceptance Criteria
- [ ] Package `@stdlib/ndarray/base/trues-like` exists at `lib/node_modules/@stdlib/ndarray/base/trues-like/`
- [ ] `lib/index.js` — barrel export
- [ ] `lib/main.js` — implementation: `truesLike(x)` returns `fill(emptyLike(x), true)`
- [ ] `package.json` — correct metadata, name, keywords
- [ ] `examples/index.js` — runnable example
- [ ] `test/test.js` — comprehensive tests (invalid input, bool base/non-base, generic base/non-base, zero-dim, empty)
- [ ] `docs/repl.txt` — REPL documentation
- [ ] `docs/types/index.d.ts` — TypeScript declarations
- [ ] `docs/types/test.ts` — TypeScript tests
- [ ] `benchmark/benchmark.js` — base benchmark
- [ ] `benchmark/benchmark.size.bool.js` — size benchmark for bool
- [ ] `benchmark/benchmark.size.generic.js` — size benchmark for generic
- [ ] `README.md` — package documentation
- [ ] `@stdlib/ndarray/base` namespace index (`lib/node_modules/@stdlib/ndarray/base/lib/index.js`) registers `truesLike`
- [ ] All tests pass
- [ ] Examples run without error

## Make Commands
- Test a package: `NODE_PATH=/home/user/stdlib/lib/node_modules node /home/user/stdlib/lib/node_modules/@stdlib/ndarray/base/trues-like/test/test.js`
- Run examples: `NODE_PATH=/home/user/stdlib/lib/node_modules node /home/user/stdlib/lib/node_modules/@stdlib/ndarray/base/trues-like/examples/index.js`
- Run benchmark: `NODE_PATH=/home/user/stdlib/lib/node_modules node /home/user/stdlib/lib/node_modules/@stdlib/ndarray/base/trues-like/benchmark/benchmark.js`

## Hypothesis
The package needs to be created from scratch following the `falses-like` pattern exactly (since `falses-like` is the direct analogue of `trues-like`).

Key design decision: use `emptyLike(x)` + `fill(_, true)` (same as `falsesLike` uses `false`, same as `onesLike` uses `1.0`).

Supported dtypes: `bool` and `generic` only (same as `trues` and `falses`/`falses-like`).

TypeScript type: `T extends typedndarray<boolean>` (same as `falsesLike`).

## Files Touched
- lib/node_modules/@stdlib/ndarray/base/trues-like/ (new package, all files)
- lib/node_modules/@stdlib/ndarray/base/lib/index.js (add truesLike entry after trues)

## Open Questions
None.

## Iteration 1 — Review Findings

### Sub-agent E (Issue-scope auditor): NO ISSUES
The diff does exactly what the issue asked — nothing more, nothing less.

### Sub-agent C (Code quality & convention): 4 MINOR issues — ALL FIXED
1. ~~`package.json` description missing backticks around `true`~~ → FIXED
2. ~~`package.json` missing `booleans` keyword, wrong order of `bool`/`boolean`~~ → FIXED
3. ~~Size benchmarks used `@stdlib/ndarray/base/trues` instead of `@stdlib/ndarray/empty`~~ → FIXED
4. ~~Test titles missing "and" word~~ → FIXED

### Sub-agent D (Security & Robustness): NO BLOCKERS — All advisory
1. Misleading error when numeric dtype passed → DISPUTED: `falses-like` has identical behavior; no dtype guard exists there either. Consistent with codebase pattern.
2. No test coverage for numeric-dtype rejection → DISPUTED: `falses-like` tests also don't cover this. Consistent.
3. TypeScript type vs runtime guard gap → DISPUTED: Same in `falses-like`.
4. Error propagation message quality → DISPUTED: Same as `falses-like`.
5. Prototype pollution: None found.
6. Shared state: None found.

### Sub-agent A (Correctness): NO BLOCKERS / NO MAJOR — 3 minor, all disputed
1. Missing `@throws` JSDoc in `lib/main.js` → DISPUTED: `falses-like` and `ones-like` "like" packages don't have `@throws` either. The "like" packages delegate validation to `emptyLike`; only the non-like packages (trues, zeros) have `@throws` because they accept an explicit dtype string argument.
2. No aliasing check (`arr !== x`) in tests → DISPUTED: `falses-like` tests also lack this. Pre-existing pattern.
3. No stride verification → DISPUTED: `falses-like` tests also lack this. Pre-existing pattern.

All acceptance criteria 1–7 confirmed functionally satisfied.

### Sub-agent B (Test quality): All findings DISPUTED — all pre-existing in `falses-like`
- "BLOCKER" incompatible dtype test missing → DISPUTED: `falses-like` also lacks this test; consistent with established pattern.
- "MAJOR" missing `instanceOf(getData(arr), Array)` → DISPUTED: `falses-like` only uses `isEqualArray`, same pattern.
- "MAJOR" missing `instanceOf(getData(arr), BooleanArray)` → DISPUTED: `falses-like` uses `isEqualBooleanArray` (same pattern).
- "MAJOR" vacuous empty assertion → DISPUTED: `falses-like` has same assertion.
- All MINOR items → DISPUTED: pre-existing in `falses-like`.
- Sub-agent B claims "and" in test titles is spurious → INCORRECT: `falses-like` has "and" in titles; sub-agent C correctly identified this as the convention.

## Exit Condition Check
- [x] All acceptance criteria satisfied (functionally verified)
- [x] Zero blocker/major findings remain open
- [x] All disputed findings documented with written justification
- [x] Examples run cleanly
- [x] Namespace registration correct
- [x] PR template can be filled in truthfully

## Decision Log
- Using `falses-like` as primary reference (not `ones-like`) because it supports the same boolean/generic dtype subset.
- `truesLike(x)` fills with `true`, `falsesLike(x)` fills with `false` — symmetric pattern.
- Index registration: insert `truesLike` after `trues` in `ndarray/base/lib/index.js` (alphabetically correct).

## Iteration 1
**Goal: Implement** — create all package files, register in namespace, run tests.
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,15 @@ setReadOnly( ns, 'transpose', require( '@stdlib/ndarray/base/transpose' ) );
*/
setReadOnly( ns, 'trues', require( '@stdlib/ndarray/base/trues' ) );

/**
* @name truesLike
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/ndarray/base/trues-like}
*/
setReadOnly( ns, 'truesLike', require( '@stdlib/ndarray/base/trues-like' ) );

/**
* @name unary
* @memberof ns
Expand Down
143 changes: 143 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/trues-like/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# truesLike

> Create an ndarray filled with `true` values and having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var truesLike = require( '@stdlib/ndarray/base/trues-like' );
```

#### truesLike( x )

Creates an ndarray filled with `true` values and having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray.

```javascript
var getShape = require( '@stdlib/ndarray/shape' );
var empty = require( '@stdlib/ndarray/empty' );

var x = empty( [ 2, 2 ], {
'dtype': 'bool'
});
// returns <ndarray>

var y = truesLike( x );
// returns <ndarray>[ [ true, true ], [ true, true ] ]

var sh = getShape( y );
// returns [ 2, 2 ]
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- Along with data type, shape, and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor].

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var empty = require( '@stdlib/ndarray/empty' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var truesLike = require( '@stdlib/ndarray/base/trues-like' );

// Specify a list of data types:
var dt = [
'generic',
'bool'
];

// Generate true-filled arrays...
var x;
var y;
var i;
for ( i = 0; i < dt.length; i++ ) {
x = empty( [ 2, 2 ], {
'dtype': dt[ i ]
});
y = truesLike( x );
console.log( ndarray2array( y ) );
}
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor

[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var empty = require( '@stdlib/ndarray/empty' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var truesLike = require( './../lib' );


// MAIN //

bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) {
var x;
var y;
var i;

x = empty( [ 0 ], {
'dtype': 'generic'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = truesLike( x );
if ( y.length !== 0 ) {
b.fail( 'should have length 0' );
}
}
b.toc();
if ( !isndarrayLike( y ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:dtype=bool', pkg ), function benchmark( b ) {
var x;
var y;
var i;

x = empty( [ 0 ], {
'dtype': 'bool'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = truesLike( x );
if ( y.length !== 0 ) {
b.fail( 'should have length 0' );
}
}
b.toc();
if ( !isndarrayLike( y ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading