Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement numpy argpartition #225

Open
ss32 opened this issue Feb 2, 2025 · 0 comments
Open

Implement numpy argpartition #225

ss32 opened this issue Feb 2, 2025 · 0 comments
Assignees

Comments

@ss32
Copy link

ss32 commented Feb 2, 2025

Is your feature request related to a problem? Please describe.
argpartition is a simple operation present in numpy that's missing from this library and I think it can be accomplished with existing funtions.

https://numpy.org/doc/stable/reference/generated/numpy.argpartition.html

Describe the solution you'd like
I think the hpp would look like

#pragma once

#include "NumCpp/Core/Types.hpp"
#include "NumCpp/NdArray.hpp"

namespace nc
{
    //============================================================================
    ///
    /// NumPy Reference: https://www.numpy.org/devdocs/reference/generated/numpy.argpartition.html
    ///
    /// @param inArray
    /// @param inKth: kth element
    /// @param inAxis (Optional, default NONE)
    /// @return NdArray
    ///
    template<typename dtype>
    NdArray<dtype> partition(const NdArray<dtype>& inArray, uint32 inKth, Axis inAxis = Axis::NONE)
    {
        NdArray<dtype> returnArray(inArray);
        returnArray.partition(inKth, inAxis);
        return returnArray.argsort(inAxis);
    }
}
@ss32 ss32 changed the title Implement numpy argparition Implement numpy argpartition Feb 2, 2025
@dpilger26 dpilger26 self-assigned this Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants