Skip to content

Please add maxElement and minElement in mir (trying to use std.algorithm gives opCmp not defined) #471

@prbuen

Description

@prbuen

To find the maximum value in an ndslice u, we can use mir's maxIndex:

u[u.maxIndex]

but it would be nice to have the functions maxElement and minElement directly implemented in mir. It's not possible to use these functions from std.algorithm (the complaint is that opCmd is not defined), unless doing u.flattened.maxElement.

It doesn't sound like much but it would allow to more easily write code that can apply to both standard D dynamic arrays and ndslices.

Here is my use case: in numerical computation (e.g. errors) we often need to find the maximum absolute value of an ndslice. This can be achieved both with dynamic arrays (were it not for this bug) and ndslices with

u[u.map!fabs.maxIndex].fabs

but it's pretty heavy and not as readable compared to

u.map!fabs.maxElement

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions