Exemplo n.º 1
0
        public void Train(SamplerDelegate sampler, ref DictionaryTrainingParameters parameters)
        {
            var samplesBuffer = GatherSamples(sampler, out var samplesSizes);

            Size = Native.ZDict.Train(
                Data,
                samplesBuffer, (ReadOnlySpan <UIntPtr>)samplesSizes,
                ref parameters
                )
                   .EnsureZDictSuccess();
        }
        public void Train(SamplerDelegate sampler, ref DictionaryTrainingParameters parameters, int compressionLevel = default, uint nbThreads = 1, uint tuningSteps = 0)
        {
            var samplesBuffer = GatherSamples(sampler, out var samplesSizes);

            Size = Native.ZDict.Train(
                Data,
                samplesBuffer, (ReadOnlySpan <UIntPtr>)samplesSizes,
                ref parameters
                )
                   .EnsureZDictSuccess();
        }
Exemplo n.º 3
0
        public unsafe void Train(AsyncSamplerDelegate sampler, ref DictionaryTrainingParameters parameters, int compressionLevel = default, uint nbThreads = 1, uint tuningSteps = 0)
        {
            var data = Data;

            fixed(DictionaryTrainingParameters *pParameters = &parameters)
            {
                Size = GatherSamples(sampler)
                       .ContinueWith((samplesTask, state) => {
                    // ReSharper disable once PossibleNullReferenceException
                    // ReSharper disable once VariableHidesOuterVariable
                    var pParameters = (DictionaryTrainingParameters *)(IntPtr)state;
                    var(samplesBuffer, samplesSizes) = samplesTask.GetAwaiter().GetResult();
                    return(Native.ZDict.Train(
                               data,
                               samplesBuffer, (ReadOnlySpan <UIntPtr>)samplesSizes,
                               ref Unsafe.AsRef <DictionaryTrainingParameters>(pParameters)
                               ));
                }, (IntPtr)pParameters)
                       .GetAwaiter().GetResult()
                       .EnsureZDictSuccess();
            }
        }
Exemplo n.º 4
0
 public static UIntPtr Train(Span <byte> dictionary, ReadOnlySpan <byte> samples, ReadOnlySpan <UIntPtr> samplesSizes, ref DictionaryTrainingParameters parameters) {
     fixed(byte *pDictBuffer = dictionary)
     fixed(byte *pSamplesBuffer    = samples)
     fixed(UIntPtr * pSamplesSizes = samplesSizes)
     fixed(DictionaryTrainingParameters * pParameters = &parameters)
     return(Train(pDictBuffer, (UIntPtr)dictionary.Length, pSamplesBuffer, pSamplesSizes, (uint)samplesSizes.Length, pParameters));
 }