NumCpp  2.10.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
place.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/NdArray.hpp"
32 
33 namespace nc
34 {
35  //============================================================================
36  // Method Description:
47  template<typename dtype>
48  void place(NdArray<dtype>& arr, const NdArray<bool>& mask, const NdArray<dtype>& vals)
49  {
50  if (mask.size() != arr.size())
51  {
52  THROW_INVALID_ARGUMENT_ERROR("Input arguments 'arr' and 'mask' must have the same size.");
53  }
54 
55  if (vals.isempty())
56  {
57  return;
58  }
59 
60  auto valIdx = 0;
61  for (decltype(arr.size()) i = 0; i < arr.size(); ++i)
62  {
63  if (mask[i])
64  {
65  arr[i] = vals[valIdx++ % vals.size()];
66  }
67  }
68  }
69 } // 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:138
size_type size() const noexcept
Definition: NdArrayCore.hpp:4415
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2855
Definition: Coordinate.hpp:45
void place(NdArray< dtype > &arr, const NdArray< bool > &mask, const NdArray< dtype > &vals)
Definition: place.hpp:48