Skip to content

convolve expects both data and weights to have the exact same types #17

@rkshthrmsh

Description

@rkshthrmsh

I am trying to convolve over the 2D arrays in an image cube and noticed the following mismatched types error.

pub fn denoise(hsi: &mut Array3<f32>) {
    let corner_kernel = arr2(&[[0.25f32, 0., 0.25], [0., 0., 0.], [0.25, 0., 0.25]]);
    hsi.outer_iter_mut().into_par_iter().for_each(|bnd| {
        let corner_average =
            ndarray_ndimage::convolve(&bnd, &corner_kernel.view(), BorderMode::Mirror, ORIGIN);
    });
// --snip--
}

Error:

error[E0308]: mismatched types
   --> src/lib.rs:93:45
    |
93  |             ndarray_ndimage::convolve(&bnd, &corner_kernel.view(), BorderMode::Mirror, ORIGIN);
    |             -------------------------       ^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
    |             |
    |             arguments to this function are incorrect
    |
    = note: expected reference `&ArrayBase<ViewRepr<&mut f32>, Dim<[usize; 2]>>`
               found reference `&ArrayBase<ViewRepr<&f32>, Dim<[usize; 2]>>`

I belive this is because of convolve's signature. Since both data and weights have the same generic parameters, the compiler expects them to both have the exact same types, which, I suspect, is probably not necessary?

pub fn convolve<S, A, D>(
    data: &ArrayBase<S, D>,
    weights: &ArrayBase<S, D>,
    mode: BorderMode<A>,
    origin: isize
) -> Array<A, D>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions