예제 #1
0
        private static bool kl_init(bilist *****bucket_ptrs, /* space for multiple bucket sorts */
                                    bilist ***listspace,     /* space for all elements of linked lists */
                                    int ***dvals,            /* change in cross edges for each move */
                                    int ***tops,             /* top dval for each type of move */
                                    int nvtxs,               /* number of vertices in the graph */
                                    int nsets,               /* number of sets created at each step */
                                    int maxchange            /* maximum change by moving a vertex */
                                    )
        {
            bilist * spacel; /* space for all listspace entries */
            bilist **spaceb; /* space for all buckets entries */
            int      sizeb;  /* size of set of buckets */
            int      sizel;  /* size of set of pointers for all vertices */
            int      i, j;   /* loop counters */

            /* Allocate appropriate data structures for buckets, and listspace. */

            *bucket_ptrs = (bilist ****)array_alloc_2D_ret <IntPtr>(nsets, nsets, sizeof(bilist *));

            *dvals = (int **)array_alloc_2D_ret <int>(nvtxs + 1, nsets - 1, sizeof(int));

            *tops = (int **)array_alloc_2D_ret <int>(nsets, nsets, sizeof(int));

            /* By using '-1' in the next line, I save space, but I need to */
            /* be careful to get the right element in listspace each time. */
            *listspace = (bilist **)Marshal.AllocHGlobal((nsets - 1) * sizeof(bilist *));

            sizeb  = (2 * maxchange + 1) * sizeof(bilist *);
            sizel  = (nvtxs + 1) * sizeof(bilist);
            spacel = (bilist *)Marshal.AllocHGlobal((nsets - 1) * sizel);
            spaceb = (bilist **)Marshal.AllocHGlobal(nsets * (nsets - 1) * sizeb);

            if (*bucket_ptrs == null || *dvals == null || *tops == null || *listspace == null ||
                spacel == null || spaceb == null)
            {
                Marshal.FreeHGlobal((IntPtr)spacel);
                Marshal.FreeHGlobal((IntPtr)spaceb);
                return(true);
            }

            for (i = 0; i < nsets; i++)
            {
                if (i != nsets - 1)
                {
                    (*listspace)[i] = spacel;
                    spacel         += nvtxs + 1;
                }

                for (j = 0; j < nsets; j++)
                {
                    if (i != j)
                    {
                        (*bucket_ptrs)[i][j] = spaceb;
                        spaceb += 2 * maxchange + 1;
                    }
                }
            }

            return(false);
        }
예제 #2
0
 public static void DuplicatePointers(int*** values, int numValues)
 {
     int sizeInBytes = sizeof(int*) * numValues;
     int** newArray = (int**)Marshal.AllocCoTaskMem(sizeInBytes);
     new Span<byte>(*values, sizeInBytes).CopyTo(new Span<byte>(newArray, sizeInBytes));
     Marshal.FreeCoTaskMem((IntPtr)(*values));
     *values = newArray;
 }
예제 #3
0
        public static int SumInPointers(int*** values, int numValues)
        {
            if (*values == null)
                return -1;

            int sum = 0;
            for (int i = 0; i < numValues; i++)
            {
                sum += *(*values)[i];
            }
            return sum;
        }
예제 #4
0
        public static int SumInPointers(int ***values, int numValues)
        {
            if (*values == null)
            {
                return(-1);
            }

            int sum = 0;

            for (int i = 0; i < numValues; i++)
            {
                sum += *(*values)[i];
            }
            return(sum);
        }
 /// <summary>
 /// This method retrieves the result set from executing the @script in sp_execute_external_script.
 /// </summary>
 public void GetResults(
     ulong *rowsNumber,
     void ***data,
     int ***strLenOrNullMap)
 {
     Logging.Trace("CSharpSession::GetResults");
     if (_outputDataSet.CSharpDataFrame != null)
     {
         *rowsNumber = (ulong)_outputDataSet.CSharpDataFrame.Rows.Count;
         _outputDataSet.RetrieveColumns(data, strLenOrNullMap);
     }
     else
     {
         *rowsNumber = 0;
     }
 }
 /// <summary>
 /// This method implements GetResults API.
 /// Retrieve the result set from executing the @script in sp_execute_external_script.
 /// </summary>
 /// <param name="sessionId">
 /// GUID uniquely identifying this script session.
 /// </param>
 /// <param name="taskId">
 /// An integer uniquely identifying this execution process.
 /// </param>
 /// <param name="rowsNumber">
 /// A pointer to a buffer that contains the number of rows in the Data.
 /// </param>
 /// <param name="data">
 /// A pointer to a two-dimensional array allocated by the extension that
 /// contains the result set of @script n sp_execute_external_script.
 /// </param>
 /// <param name="strLenOrNullMap">
 ///  A pointer to a two-dimensional array allocated by the extension that
 ///  contains the length/NULL indicator for each value in Data.
 /// <returns>
 /// SQL_SUCCESS(0), SQL_ERROR(-1)
 /// </returns>
 public static short GetResults(
     Guid sessionId,
     ushort TaskId,
     ulong *rowsNumber,
     void ***data,
     int ***strLenOrNullMap)
 {
     Logging.Trace("CSharpExtension::GetResults");
     return(ExceptionUtils.WrapError(() =>
     {
         _currentSession.GetResults(
             rowsNumber,
             data,
             strLenOrNullMap);
     }));
 }
예제 #7
0
파일: CApi.cs 프로젝트: horker/py2cs
 public static extern unsafe int MXSymbolInferShapeEx(SymbolHandle sym,
                                                      uint num_args,
                                                      [In][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPUTF8Str)]
                                                      string[] keys,
                                                      int[] arg_ind_ptr,
                                                      int[] arg_shape_data,
                                                      int *in_shape_size,
                                                      int **in_shape_ndim,
                                                      int ***in_shape_data,
                                                      out int out_shape_size,
                                                      out int *out_shape_ndim,
                                                      out int **out_shape_data,
                                                      out int aux_shape_size,
                                                      out int *aux_shape_ndim,
                                                      out int **aux_shape_data,
                                                      out int complete);
        /// <summary>
        /// This method retrieves the DataFrame data from output DataSet by assigning
        /// pointers to the data pointers array and strLenOrNullMap pointers array
        /// </summary>
        public unsafe void RetrieveColumns(
            void ***data,
            int ***strLenOrNullMap
            )
        {
            Logging.Trace("CSharpOutputDataSet::RetrieveColumns");
            fixed(void **ptrptr = _dataPtrs)
            {
                _handleList.Add(GCHandle.Alloc(_dataPtrs));
                *data = ptrptr;
            }

            fixed(int **ptrptr = _strLenOrNullMapPtrs)
            {
                _handleList.Add(GCHandle.Alloc(_strLenOrNullMapPtrs));
                *strLenOrNullMap = ptrptr;
            }
        }
예제 #9
0
        public unsafe bool Query()
        {
            Guid classGuid         = Guid.Empty;
            Guid interfaceGuid     = Guid.Empty;
            Guid classFactoryGuid  = typeof(IClassFactory).GUID;
            Guid classFactory2Guid = typeof(IClassFactory2).GUID;

            int[]  vTableOffsets = null;
            object classInstance = null;

            if (ClassType != null)
            {
                classGuid     = ClassType.GUID;
                interfaceGuid = InterfaceType.GUID;
                // get com-slot-number (vtable-index) of function X
                vTableOffsets = new int[MethodPointers.Length];
                for (var i = 0; i < Methods.Length; i++)
                {
                    vTableOffsets[i] = Marshal.GetComSlotForMethodInfo(Methods[i]);
                }
            }
            else
            {
                classGuid     = ClassId;
                interfaceGuid = InterfaceId;
                // get com-slot-number (vtable-index) of function N
                vTableOffsets = VTableIndexes;
            }

            classInstance = GetClassInstance(classGuid, interfaceGuid, classFactoryGuid, classFactory2Guid);
            if (classInstance == null)
            {
                return(false);
            }

            IntPtr interfaceIntPtr = IntPtr.Zero;

            if (InterfaceType != null)
            {
                interfaceIntPtr = Marshal.GetComInterfaceForObject(classInstance, InterfaceType);
            }
            else
            {
                interfaceIntPtr = Marshal.GetIUnknownForObject(classInstance);
            }

            try
            {
                int ***interfaceRawPtr = (int ***)interfaceIntPtr.ToPointer();
                // get vtable
                int **vTable = *interfaceRawPtr;
                // get function-addresses from vtable
                for (var i = 0; i < vTableOffsets.Length; i++)
                {
                    int *faddr = vTable[vTableOffsets[i]];
                    MethodPointers[i] = new IntPtr(faddr);
                }
            }
            finally
            {
                // release intptr
                if (interfaceIntPtr != IntPtr.Zero)
                {
                    Marshal.Release(interfaceIntPtr);
                }
                Marshal.FinalReleaseComObject(classInstance);
            }

            return(true);
        }
예제 #10
0
        static int mapping0_forward(ref vorbis_block vb)
        {
            vorbis_dsp_state vd = vb.vd;
            vorbis_info      vi = vd.vi;

            codec_setup_info      ci  = vi.codec_setup as codec_setup_info;
            private_state         b   = vb.vd.backend_state as private_state;
            vorbis_block_internal vbi = vb._internal as vorbis_block_internal;

            int n = vb.pcmend;
            int i, j, k;

            int *   nonzero     = stackalloc int[vi.channels];
            float **gmdct       = (float **)_vorbis_block_alloc(ref vb, vi.channels * sizeof(float *));
            int **  iwork       = (int **)_vorbis_block_alloc(ref vb, vi.channels * sizeof(int *));
            int *** floor_posts = (int ***)_vorbis_block_alloc(ref vb, vi.channels * sizeof(int **));

            float  global_ampmax = vbi.ampmax;
            float *local_ampmax  = stackalloc float[vi.channels];

            int blocktype  = vbi.blocktype;
            int modenumber = vb.W;

            vorbis_info_mapping0 info     = ci.map_param[modenumber] as vorbis_info_mapping0;
            vorbis_look_psy      psy_look = b.psy[blocktype + (vb.W != 0 ? 2 : 0)];

            vb.mode = modenumber;

            for (i = 0; i < vi.channels; i++)
            {
                float scale = 4.0f / n;
                float scale_dB;

                float *pcm    = vb.pcm[i];
                float *logfft = pcm;

                iwork[i] = (int *)_vorbis_block_alloc(ref vb, (n / 2) * sizeof(int));
                gmdct[i] = (float *)_vorbis_block_alloc(ref vb, (n / 2) * sizeof(float));

                /* + .345 is a hack; the original todB estimation used on IEEE 754 compliant machines had a bug that
                 * returned dB values about a third of a decibel too high.  The bug was harmless because tunings
                 * implicitly took that into account.  However, fixing the bug in the estimator requires changing all the tunings as well.
                 * For now, it's easier to sync things back up here, and recalibrate the tunings in the next major model upgrade. */

                scale_dB = todB(scale) + 0.345f;

                /* window the PCM data */
                _vorbis_apply_window(pcm, ref b.window, ref ci.blocksizes, vb.lW, vb.W, vb.nW);

                /* transform the PCM data */
                /* only MDCT right now.... */
                mdct_forward(b.transform[vb.W][0] as mdct_lookup, pcm, gmdct[i]);

                /* FFT yields more accurate tonal estimation (not phase sensitive) */
                drft_forward(ref b.fft_look[vb.W], pcm);

                /* + .345 is a hack; the original todB estimation used on IEEE 754 compliant machines had a bug that
                 * returned dB values about a third of a decibel too high.  The bug was harmless because tunings
                 * implicitly took that into account.  However, fixing the bug in the estimator requires changing all the tunings as well.
                 * For now, it's easier to sync things back up here, and recalibrate the tunings in the next major model upgrade. */

                logfft[0]       = scale_dB + todB(*pcm) + 0.345f;
                local_ampmax[i] = logfft[0];

                for (j = 1; j < n - 1; j += 2)
                {
                    float temp = pcm[j] * pcm[j] + pcm[j + 1] * pcm[j + 1];

                    /* + .345 is a hack; the original todB estimation used on IEEE 754 compliant machines had a bug that
                     * returned dB values about a third of a decibel too high.  The bug was harmless because tunings
                     * implicitly took that into account.  However, fixing the bug in the estimator requires changing all the tunings as well.
                     * For now, it's easier to sync things back up here, and recalibrate the tunings in the next major model upgrade. */

                    temp = logfft[(j + 1) >> 1] = scale_dB + 0.5f * todB(temp) + 0.345f;

                    if (temp > local_ampmax[i])
                    {
                        local_ampmax[i] = temp;
                    }
                }

                if (local_ampmax[i] > 0.0f)
                {
                    local_ampmax[i] = 0.0f;
                }

                if (local_ampmax[i] > global_ampmax)
                {
                    global_ampmax = local_ampmax[i];
                }
            }

            {
                float *noise = (float *)_vorbis_block_alloc(ref vb, n / 2 * sizeof(float));
                float *tone  = (float *)_vorbis_block_alloc(ref vb, n / 2 * sizeof(float));

                for (i = 0; i < vi.channels; i++)
                {
                    /* the encoder setup assumes that all the modes used by any
                     * specific bitrate tweaking use the same floor */

                    int submap = info.chmuxlist[i];

                    /* the following makes things clearer to *me* anyway */

                    float *mdct   = gmdct[i];
                    float *logfft = vb.pcm[i];

                    float *logmdct = logfft + n / 2;
                    float *logmask = logfft;

                    vb.mode = modenumber;

                    floor_posts[i] = (int **)_vorbis_block_alloc(ref vb, PACKETBLOBS * sizeof(int *));
                    ZeroMemory(floor_posts[i], sizeof(int *) * PACKETBLOBS);

                    for (j = 0; j < n / 2; j++)
                    {
                        /* + .345 is a hack; the original todB estimation used on IEEE 754 compliant machines had a bug that
                         * returned dB values about a third of a decibel too high.  The bug was harmless because tunings
                         * implicitly took that into account.  However, fixing the bug in the estimator requires changing all the tunings as well.
                         * For now, it's easier to sync things back up here, and recalibrate the tunings in the next major model upgrade. */

                        logmdct[j] = todB(mdct[j]) + 0.345f;

                        /* first step; noise masking.  Not only does 'noise masking' give us curves from which we can decide how much resolution
                         * to give noise parts of the spectrum, it also implicitly hands us a tonality estimate (the larger the value in the
                         * 'noise_depth' vector, the more tonal that area is) */

                        _vp_noisemask(ref psy_look, logmdct, noise); /* noise does not have by-frequency offset bias applied yet */

                        /* second step: 'all the other crap'; all the stuff that isn't computed/fit for bitrate management goes in the second psy
                         * vector.  This includes tone masking, peak limiting and ATH */

                        _vp_tonemask(ref psy_look, logfft, tone, global_ampmax, local_ampmax[i]);

                        /* third step; we offset the noise vectors, overlay tone masking.  We then do a floor1-specific line fit.  If we're
                         * performing bitrate management, the line fit is performed multiple times for up/down tweakage on demand. */

                        _vp_offset_and_mix(ref psy_look, noise, tone, 1, logmask, mdct, logmdct);

                        /* this algorithm is hardwired to floor 1 for now; abort out if  we're *not* floor1.  This won't happen unless someone has
                         * broken the encode setup lib.  Guard it anyway. */

                        if (ci.floor_type[info.floorsubmap[submap]] != 1)
                        {
                            return(-1);
                        }

                        floor_posts[i][PACKETBLOBS / 2] = floor1_fit(ref vb, b.flr[info.floorsubmap[submap]] as vorbis_look_floor1, logmdct, logmask);

                        /* are we managing bitrate?  If so, perform two more fits for later rate tweaking (fits represent hi/lo) */
                        if (vorbis_bitrate_managed(ref vb) != 0 && floor_posts[i][PACKETBLOBS / 2] != null)
                        {
                            /* higher rate by way of lower noise curve */
                            _vp_offset_and_mix(ref psy_look, noise, tone, 2, logmask, mdct, logmdct);

                            floor_posts[i][PACKETBLOBS - 1] = floor1_fit(ref vb, b.flr[info.floorsubmap[submap]] as vorbis_look_floor1, logmdct, logmask);

                            /* lower rate by way of higher noise curve */
                            _vp_offset_and_mix(ref psy_look, noise, tone, 0, logmask, mdct, logmdct);

                            floor_posts[i][0] = floor1_fit(ref vb, b.flr[info.floorsubmap[submap]] as vorbis_look_floor1, logmdct, logmask);

                            /* we also interpolate a range of intermediate curves for
                             * intermediate rates */
                            for (k = 1; k < PACKETBLOBS / 2; k++)
                            {
                                floor_posts[i][k] = floor1_interpolate_fit(ref vb, b.flr[info.floorsubmap[submap]] as vorbis_look_floor1, floor_posts[i][0], floor_posts[i][PACKETBLOBS / 2], k * 65536 / (PACKETBLOBS / 2));
                            }

                            for (k = PACKETBLOBS / 2 + 1; k < PACKETBLOBS - 1; k++)
                            {
                                floor_posts[i][k] = floor1_interpolate_fit(ref vb, b.flr[info.floorsubmap[submap]] as vorbis_look_floor1, floor_posts[i][PACKETBLOBS / 2], floor_posts[i][PACKETBLOBS - 1], (k - PACKETBLOBS / 2) * 65536 / (PACKETBLOBS / 2));
                            }
                        }
                    }
                }

                vbi.ampmax = global_ampmax;

                /*
                 * the next phases are performed once for vbr-only and PACKETBLOB
                 * times for bitrate managed modes.
                 *
                 * 1) encode actual mode being used
                 * 2) encode the floor for each channel, compute coded mask curve/res
                 * 3) normalize and couple.
                 * 4) encode residue
                 * 5) save packet bytes to the packetblob vector
                 */

                /* iterate over the many masking curve fits we've created */

                {
                    int **couple_bundle = stackalloc int *[vi.channels];
                    int * zerobundle    = stackalloc int[vi.channels];

                    for (k = (vorbis_bitrate_managed(ref vb) != 0 ? 0 : PACKETBLOBS / 2); k <= (vorbis_bitrate_managed(ref vb) != 0 ? PACKETBLOBS - 1 : PACKETBLOBS / 2); k++)
                    {
                        Ogg.oggpack_buffer opb = vbi.packetblob[k];

                        /* start out our new packet blob with packet type and mode */
                        /* Encode the packet type */
                        Ogg.oggpack_write(ref opb, 0, 1);

                        /* Encode the modenumber */
                        /* Encode frame mode, pre,post windowsize, then dispatch */
                        Ogg.oggpack_write(ref opb, (uint)modenumber, b.modebits);

                        if (vb.W != 0)
                        {
                            Ogg.oggpack_write(ref opb, (uint)vb.lW, 1);
                            Ogg.oggpack_write(ref opb, (uint)vb.nW, 1);
                        }

                        /* encode floor, compute masking curve, sep out residue */
                        for (i = 0; i < vi.channels; i++)
                        {
                            int  submap   = info.chmuxlist[i];
                            int *ilogmask = iwork[i];

                            nonzero[i] = floor1_encode(ref opb, ref vb, b.flr[info.floorsubmap[submap]] as vorbis_look_floor1, floor_posts[i][k], ilogmask);
                        }

                        /* our iteration is now based on masking curve, not prequant and coupling.  Only one prequant/coupling step */

                        /* quantize/couple */
                        /* incomplete implementation that assumes the tree is all depth one, or no tree at all */
                        _vp_couple_quantize_normalize(k, ci.psy_g_param, ref psy_look, info, gmdct, iwork, nonzero, ci.psy_g_param.sliding_lowpass[vb.W, k], vi.channels);

                        /* classify and encode by submap */
                        for (i = 0; i < info.submaps; i++)
                        {
                            int   ch_in_bundle = 0;
                            int **classifications;
                            int   resnum = info.residuesubmap[i];

                            for (j = 0; j < vi.channels; j++)
                            {
                                if (info.chmuxlist[j] == i)
                                {
                                    zerobundle[ch_in_bundle] = 0;

                                    if (nonzero[j] != 0)
                                    {
                                        zerobundle[ch_in_bundle] = 1;
                                    }

                                    couple_bundle[ch_in_bundle++] = iwork[j];
                                }
                            }

                            classifications = _residue_P[ci.residue_type[resnum]]._class(ref vb, b.residue[resnum], couple_bundle, zerobundle, ch_in_bundle);
                            ch_in_bundle    = 0;

                            for (j = 0; j < vi.channels; j++)
                            {
                                if (info.chmuxlist[j] == i)
                                {
                                    couple_bundle[ch_in_bundle++] = iwork[j];
                                }
                            }

                            _residue_P[ci.residue_type[resnum]].forward(ref opb, ref vb, b.residue[resnum], couple_bundle, zerobundle, ch_in_bundle, classifications, i);
                        }

                        /* ok, done encoding.  Next protopacket. */
                    }
                }

                return(0);
            }
        }