Пример #1
0
            public static Dictionary <IntPtr, float[]> LoadDictionaryNative(ModelConfig config, NativeMemAllocationMediator nativeMemAllocator)
            {
                var modelDictionaryNative = new Dictionary <IntPtr, float[]>(Math.Max(config.RowCapacity, 1000), IntPtrEqualityComparer.Inst);

                foreach (var filename in config.Filenames)
                {
                    LoadModelFilenameContentMMF(filename, delegate(in ModelRow row)
                    {
                        var textPtr       = nativeMemAllocator.AllocAndCopy(row.TextPtr, row.TextLength); //= AllocHGlobalAndCopy( row.TextPtr, row.TextLength );
                        var weightClasses = row.WeightClasses.ToArray();
                        modelDictionaryNative.Add(textPtr, weightClasses);
                    });
Пример #2
0
            public static Dictionary <IntPtr, IntPtr> LoadDictionaryNative(ModelConfig config, NativeMemAllocationMediator nativeMemAllocator)
            {
                var modelDictionaryNative = new Dictionary <IntPtr, IntPtr>(Math.Max(config.RowCapacity, 1000), IntPtrEqualityComparer.Inst);

                foreach (var filename in config.Filenames)
                {
                    LoadModelFilenameContentMMF(filename, delegate(in ModelRow row)
                    {
                        var textPtr = nativeMemAllocator.AllocAndCopy(row.TextPtr, row.TextLength);

                        //!!! -= MUST BE EQUALS IN ALL RECORDS =- !!!!
                        byte countWeightClasses   = (byte)row.WeightClasses.Count;
                        var weightClassesPtr      = nativeMemAllocator.Alloc(sizeof(byte) + countWeightClasses * sizeof(float));
                        var weightClassesBytePtr  = (byte *)weightClassesPtr;
                        *weightClassesBytePtr++   = countWeightClasses;
                        var weightClassesFloatPtr = (float *)weightClassesBytePtr;
                        for (var i = 0; i < countWeightClasses; i++)
                        {
                            weightClassesFloatPtr[i] = row.WeightClasses[i];
                        }
                        modelDictionaryNative.Add(textPtr, weightClassesPtr);
                    });