22#define PLATFORM_SUPPORT_FLOATING_INTERLOCKED_ADD (PLATFORM_WINDOWS && (__cplusplus >= 202002L))
25template<
typename TVectorType,
bool bUseAtomicType>
37 #if PLATFORM_SUPPORT_FLOATING_INTERLOCKED_ADD
40 for (
uint32 ComponentIndex = 0; ComponentIndex < TVectorType::NumComponents; ++ComponentIndex)
42 AtomicValues[ComponentIndex].SetNumZeroed(
Num);
54 #if PLATFORM_SUPPORT_FLOATING_INTERLOCKED_ADD
57 for (
uint32 ComponentIndex = 0; ComponentIndex < TVectorType::NumComponents; ++ComponentIndex)
59 AtomicValues[ComponentIndex][
Index] = In[ComponentIndex];
71 #if PLATFORM_SUPPORT_FLOATING_INTERLOCKED_ADD
75 for (
uint32 ComponentIndex = 0; ComponentIndex < TVectorType::NumComponents; ++ComponentIndex)
77 Out[ComponentIndex] = AtomicValues[ComponentIndex][
Index] /
InDivider;
90 #if PLATFORM_SUPPORT_FLOATING_INTERLOCKED_ADD
93 for (
uint32 ComponentIndex = 0; ComponentIndex < TVectorType::NumComponents; ++ComponentIndex)
95 AtomicValues[ComponentIndex][
Index].fetch_add(In[ComponentIndex]);
107 #if PLATFORM_SUPPORT_FLOATING_INTERLOCKED_ADD
110 for (
uint32 ComponentIndex = 0; ComponentIndex < TVectorType::NumComponents; ++ComponentIndex)
151 template<
typename TVectorType = FVector,
bool bRunParallel=false>
186 for (
int32 Idx = 0; Idx < NumClusters; ++Idx)
203 if (NumClusters == 0)
207 else if (NumClusters == 1)
239 const TVectorType& Point = PointsToCluster[PointIdx];
240 double ClosestDistSq = (double)UE::Geometry::DistanceSquared(Point, (*UseCenters)[0]);
241 int32 ClosestCenter = 0;
242 for (int32 CenterIdx = 1; CenterIdx < UseCenters->Num(); ++CenterIdx)
244 double DistSq = UE::Geometry::DistanceSquared(PointsToCluster[PointIdx], (*UseCenters)[CenterIdx]);
245 if (DistSq < ClosestDistSq)
247 ClosestDistSq = DistSq;
248 ClosestCenter = CenterIdx;
308 for (
int32 ClusterIdx = 0; ClusterIdx <
UseCenters->Num(); ++ClusterIdx)
313 NextCenters.Assign(ClusterIdx, TVectorType::ZeroVector);
349 template<
typename TVectorType = FVector>
354 int32 NumOut = FMath::Min(NumClusters, OrderPoints.Order.Num());
EAllowShrinking
Definition AllowShrinking.h:10
#define checkSlow(expr)
Definition AssertionMacros.h:332
void ParallelFor(int32 Num, TFunctionRef< void(int32)> Body, bool bForceSingleThread, bool bPumpRenderingThread=false)
Definition ParallelFor.h:481
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define PLATFORM_SUPPORT_FLOATING_INTERLOCKED_ADD
Definition KMeans.h:22
Definition ArrayView.h:139
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void SetNumZeroed(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2340
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_FORCEINLINE_HINT void RemoveAtSwap(SizeType Index, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2185
UE_REWRITE bool IsEmpty() const
Definition Array.h:1133
void Init(const ElementType &Element, SizeType Number)
Definition Array.h:3043
void SetNumUninitialized(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2369
Definition StaticArray.h:26
T DistanceSquared(const UE::Math::TVector2< T > &V1, const UE::Math::TVector2< T > &V2)
Definition VectorTypes.h:82
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
Definition RandomStream.h:20
TArray< std::atomic< int32 > > ClusterSizes
Definition KMeans.h:139
TArray< int32 > ClusterIDs
Outputs.
Definition KMeans.h:136
void GetUniformSpacedInitialCenters(TArrayView< const TVectorType > PointsToCluster, int32 NumClusters, TArray< TVectorType > &OutCenters)
Definition KMeans.h:350
int32 RandomSeed
Definition KMeans.h:131
int32 MaxIterations
Parameters.
Definition KMeans.h:128
int32 ComputeClusters(TArrayView< const TVectorType > PointsToCluster, int32 NumClusters, TArrayView< const TVectorType > InitialCenters=TArrayView< const TVectorType >(), TArray< TVectorType > *OutClusterCenters=nullptr)
Definition KMeans.h:152
Definition PriorityOrderPoints.h:26
void SetNumZeroed(uint32 Num)
Definition KMeans.h:35
void RemoveAtSwap(size_t Index, EAllowShrinking AllowShrinking)
Definition KMeans.h:105
void Accumulate(int32 Index, const TVectorType &In)
Definition KMeans.h:88
void Assign(int32 Index, const TVectorType &In)
Definition KMeans.h:52
TVectorType DivideBy(int32 Index, int32 InDivider)
Definition KMeans.h:69