306 const auto value =
values.front();
310 [
arrSize, value](
auto index) -> std::pair<int32, dtype>
312 if constexpr (type_traits::is_ndarray_signed_int_v<Indices>)
321 THROW_INVALID_ARGUMENT_ERROR(
"index out of range");
329 return std::make_pair(
static_cast<int32>(index), value);
338 [
arrSize](
auto index,
const auto& value) -> std::pair<int32, dtype>
340 if constexpr (type_traits::is_ndarray_signed_int_v<Indices>)
349 THROW_INVALID_ARGUMENT_ERROR(
"index out of range");
357 return std::make_pair(
static_cast<int32>(index), value);
364 { return indexValue1.first < indexValue2.first; });
370 { return indexValue1.first == indexValue2.first; });
379 { mask[indexValue.first + counter++] = false; });
390 [](
const auto&
indexValue) { return indexValue.second; });
405 const auto value =
values.front();
413 if constexpr (type_traits::is_ndarray_signed_int_v<Indices>)
422 THROW_INVALID_ARGUMENT_ERROR(
"index out of range");
440 if constexpr (type_traits::is_ndarray_signed_int_v<Indices>)
449 THROW_INVALID_ARGUMENT_ERROR(
"index out of range");
457 return std::make_pair(
static_cast<int32>(index),
values);
460 else if (values.numCols() == arr.numCols() && values.numRows() == indices.size())
463 std::transform(indices.begin(),
466 [arrNumRows, &values, &counter](
auto index) -> std::pair<int32, NdArray<dtype>>
468 if constexpr (type_traits::is_ndarray_signed_int_v<Indices>)
477 THROW_INVALID_ARGUMENT_ERROR(
"index out of range");
480 if (
static_cast<int32>(index) > arrNumRows)
485 return std::make_pair(
static_cast<int32>(index),
486 values(counter++, values.cSlice()));
494 stl_algorithms::sort(indexValues.begin(),
496 [](
const auto& indexValue1,
const auto& indexValue2) noexcept ->
bool
497 { return indexValue1.first < indexValue2.first; });
498 auto indexValuesUnique = std::vector<
typename decltype(indexValues)::value_type>{};
499 std::unique_copy(indexValues.begin(),
501 std::back_inserter(indexValuesUnique),
502 [](
const auto& indexValue1,
const auto& indexValue2) noexcept ->
bool
503 { return indexValue1.first == indexValue2.first; });
505 auto result = NdArray<dtype>(arrNumRows + indexValuesUnique.size(), arr.numCols());
507 auto mask = ones_like<bool>(result);
509 std::for_each(indexValuesUnique.begin(),
510 indexValuesUnique.end(),
511 [&counter, &mask](
auto& indexValue) noexcept ->
void
512 { mask.put(indexValue.first + counter++, mask.cSlice(), false); });
514 result.putMask(mask, arr);
517 for (
const auto& [index, values_] : indexValuesUnique)
519 result.put(index + counter++, result.cSlice(), values_);
526 return insert(arr.transpose(), indices, values.transpose(), Axis::ROW).transpose();
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:775