예제 #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);
                    });