Skip to content

InverseHInto returns incorrect results for row major arrays #285

Open
@jturner314

Description

@jturner314

This example

use approx::assert_abs_diff_eq;
use ndarray::*;
use ndarray_linalg::*;

fn main() {
    let arr = array![[1., 3.], [3., 1.]];
    assert_abs_diff_eq!(
        arr.invh_into().unwrap(),
        array![[-0.125, 0.375], [0.375, -0.125]],
        epsilon = 1e-9,
    );
}

fails with the following message

thread 'main' panicked at 'assert_abs_diff_eq!(arr.invh_into().unwrap(), array![[- 0.125, 0.375], [0.375, - 0.125]], epsilon = 1e-9)

    left  = [[-0.125, 3.0],
 [3.0, -0.125]], shape=[2, 2], strides=[2, 1], layout=Cc (0x5), const ndim=2
    right = [[-0.125, 0.375],
 [0.375, -0.125]], shape=[2, 2], strides=[2, 1], layout=Cc (0x5), const ndim=2

It seems that invh_into is copying the incorrect triangular portion to overwrite the other triangular portion of the matrix after calling the LAPACK routine. This bug is layout-dependent. Changing arr in the example to array![[1., 3.], [3., 1.]].reversed_axes() causes the assertion to pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug issue, or bug fix change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions