Skip to content

Commit 82839be

Browse files
committed
Fix offset bug
1 parent 7e7d2f4 commit 82839be

File tree

1 file changed

+7
-0
lines changed
  • lib/node_modules/@stdlib/math/special/abs/lib

1 file changed

+7
-0
lines changed

lib/node_modules/@stdlib/math/special/abs/lib/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var buffer = require( '@stdlib/ndarray/base/buffer' );
3131
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3232
var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' );
3333
var dtype = require( '@stdlib/ndarray/base/buffer-dtype' );
34+
var maxViewBufferIndex = require( '@stdlib/ndarray/base/max-view-buffer-index' );
35+
var minViewBufferIndex = require( '@stdlib/ndarray/base/min-view-buffer-index' );
3436
var base = require( '@stdlib/math/base/special/abs' );
3537
var dabs = require( '@stdlib/math/strided/special/dabs' );
3638
var sabs = require( '@stdlib/math/strided/special/sabs' );
@@ -124,6 +126,11 @@ function abs( x ) {
124126
// Determine whether we can ignore shape (and strides) and treat `x` as a linear array...
125127
s = iterationOrder( strides ); // +/-1
126128
if ( s !== 0 && isSingleSegmentCompatible( shape, strides, offset ) ) { // Note: equivalent to @stdlib/ndarray/base/assert/is-contiguous, but in-lined so we can retain iteration order
129+
if ( s === 1 ) {
130+
offset = minViewBufferIndex( shape, strides, offset );
131+
} else {
132+
offset = maxViewBufferIndex( shape, strides, offset );
133+
}
127134
if ( dt === 'float64' ) {
128135
dabs.ndarray( N, data, s, offset, buf, 1, 0 );
129136
} else if ( dt === 'float32' ) {

0 commit comments

Comments
 (0)