SPB Git

spb/forge Public MIT

Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.

C++ 61.2% C 23% Python 7.6% TeX 7.2% CMake 1.1%
3.1 KB · 79 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Foundation/NSEnumerator.hpp4//5// Copyright 2020-2024 Apple Inc.6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11//     http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223//-------------------------------------------------------------------------------------------------------------------------------------------------------------2425#include "NSObject.hpp"26#include "NSTypes.hpp"2728//-------------------------------------------------------------------------------------------------------------------------------------------------------------2930namespace NS31{32struct FastEnumerationState33{34    unsigned long  state;35    Object**       itemsPtr;36    unsigned long* mutationsPtr;37    unsigned long  extra[5];38} _NS_PACKED;3940class FastEnumeration : public Referencing<FastEnumeration>41{42public:43    NS::UInteger countByEnumerating(FastEnumerationState* pState, Object** pBuffer, NS::UInteger len);44};4546template <class _ObjectType>47class Enumerator : public Referencing<Enumerator<_ObjectType>, FastEnumeration>48{49public:50    _ObjectType* nextObject();51    class Array* allObjects();52};53}5455//-------------------------------------------------------------------------------------------------------------------------------------------------------------5657_NS_INLINE NS::UInteger NS::FastEnumeration::countByEnumerating(FastEnumerationState* pState, Object** pBuffer, NS::UInteger len)58{59    return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(countByEnumeratingWithState_objects_count_), pState, pBuffer, len);60}6162//-------------------------------------------------------------------------------------------------------------------------------------------------------------6364template <class _ObjectType>65_NS_INLINE _ObjectType* NS::Enumerator<_ObjectType>::nextObject()66{67    return Object::sendMessage<_ObjectType*>(this, _NS_PRIVATE_SEL(nextObject));68}6970//-------------------------------------------------------------------------------------------------------------------------------------------------------------7172template <class _ObjectType>73_NS_INLINE NS::Array* NS::Enumerator<_ObjectType>::allObjects()74{75    return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(allObjects));76}7778//-------------------------------------------------------------------------------------------------------------------------------------------------------------79