NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
place.hpp
Go to the documentation of this file.
1
28#pragma once
29
31#include "NumCpp/NdArray.hpp"
32
33namespace nc
34{
35 //============================================================================
36 // Method Description:
46 template<typename dtype>
47 void place(NdArray<dtype>& arr, const NdArray<bool>& mask, const NdArray<dtype>& vals)
48 {
49 if (mask.size() != arr.size())
50 {
51 THROW_INVALID_ARGUMENT_ERROR("Input arguments 'arr' and 'mask' must have the same size.");
52 }
53
54 if (vals.isempty())
55 {
56 return;
57 }
58
59 auto valIdx = 0;
60 for (decltype(arr.size()) i = 0; i < arr.size(); ++i)
61 {
62 if (mask[i])
63 {
64 arr[i] = vals[valIdx++ % vals.size()];
65 }
66 }
67 }
68} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2932
Definition: Cartesian.hpp:40
void place(NdArray< dtype > &arr, const NdArray< bool > &mask, const NdArray< dtype > &vals)
Definition: place.hpp:47