Skip to content

Commit 1e48327

Browse files
committed
fix: handle zero-dimensional ndarrays
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 282d01f commit 1e48327

File tree

1 file changed

+9
-2
lines changed
  • lib/node_modules/@stdlib/ndarray/base/assign/lib

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,23 @@ function boolean2uint8( x ) {
166166
* @returns {Object} output ndarray object
167167
*/
168168
function complex2real( x ) {
169+
var ndims = x.shape.length;
170+
169171
x.data = reinterpretComplex( x.data, 0 );
170172
x.accessorProtocol = false;
171173
x.dtype = COMPLEX_TO_REAL[ x.dtype ];
172-
x.strides = gscal( x.shape.length, 2, x.strides, 1 );
174+
x.strides = gscal( ndims, 2, x.strides, 1 );
173175
x.offset *= 2;
174176

175177
// Append a trailing dimension where each element is the real and imaginary component for a corresponding element in the original input ndarray (note: this means that a two-dimensional complex-valued ndarray becomes a three-dimensional real-valued ndarray; while this does entail additional loop overhead, it is still significantly faster than sending complex-valued ndarrays down the accessor path):
176178
x.shape.push( 2 ); // real and imaginary components
177-
x.strides.push( 1 ); // real and imaginary components are assumed to be adjacent in memory
178179

180+
// Augment the strides, where we assume that real and imaginary components are adjacent in memory...
181+
if ( ndims === 0 ) {
182+
x.strides[ 0 ] = 1;
183+
} else {
184+
x.strides.push( 1 );
185+
}
179186
return x;
180187
}
181188

0 commit comments

Comments
 (0)