Esempio n. 1
0
        /// <summary>
        /// this helper function is used from all constructors
        /// </summary>
        /// <param name="data">storage of source array</param>
        /// <param name="indexOffset">ILIndexOffset mapping for reference arrays</param>
        /// <param name="dimensions">Dimension specification</param>
        /// <param name="startPos">enumeration value where to set the initial element position </param>
        /// <param name="leadingDimension">the dimension, the iterator is going to walk along</param>
        private void commonConstruct(BaseT[] data, ILDimension dimensions, ILIteratorPositions startPos, int leadingDimension)
        {
            m_data             = data;
            m_leadDim          = leadingDimension % dimensions.NumberOfDimensions;
            m_dataLenghtMinus1 = m_data.Length - 1;

            m_increment = dimensions.SequentialIndexDistance(leadingDimension);
            switch (startPos)
            {
            case ILIteratorPositions.ILStart:
                m_pos = 0;
                break;

            case ILIteratorPositions.ILMiddle:
                m_pos = (int)(m_data.Length / 2);
                break;

            case ILIteratorPositions.ILEnd:
                m_pos = m_dataLenghtMinus1;
                break;
            }

            // determine if this storage can be altered
            m_readonly = false;
        }
Esempio n. 2
0
 /// <summary>
 /// create ILIterator - this is not for public use! Use <see cref="ILNumerics.ILArray&lt;T&gt;.CreateIterator()"/> instead!
 /// </summary>
 /// <param name="data">storage of source array</param>
 /// <param name="indexOffset">ILIndexOffset mapping for reference arrays</param>
 /// <param name="dimensions">Dimension specification</param>
 /// <param name="startPos">enumeration value where to set the initial element position </param>
 /// <param name="leadingDimension">the dimension, the iterator is going to walk along</param>
 public ILIterator(BaseT[] data, ILDimension dimensions, ILIteratorPositions startPos, int leadingDimension)
 {
     commonConstruct(data, dimensions, startPos, leadingDimension);
 }
Esempio n. 3
0
        /// <summary>
        /// this helper function is used from all constructors
        /// </summary>
        /// <param name="data">storage of source array</param>
        /// <param name="indexOffset">ILIndexOffset mapping for reference arrays</param>
        /// <param name="dimensions">Dimension specification</param>
        /// <param name="startPos">enumeration value where to set the initial element position </param>
        /// <param name="leadingDimension">the dimension, the iterator is going to walk along</param>
        private void commonConstruct(BaseT[] data, ILIndexOffset indexOffset,
                                     ILDimension dimensions, ILIteratorPositions startPos, int leadingDimension)
        {
            m_data             = data;
            m_leadDim          = leadingDimension % dimensions.NumberOfDimensions;
            m_dataLenghtMinus1 = m_data.Length - 1;
            if (indexOffset == null)
            {
                m_increment = dimensions.SequentialIndexDistance(leadingDimension);
                switch (startPos)
                {
                case ILIteratorPositions.ILStart:
                    m_pos = 0;
                    break;

                case ILIteratorPositions.ILMiddle:
                    m_pos = (int)(m_data.Length / 2);
                    break;

                case ILIteratorPositions.ILEnd:
                    m_pos = m_dataLenghtMinus1;
                    break;
                }
            }
            else
            {
                int nrDims    = indexOffset.Length;
                int curDim    = (m_leadDim + 1) % nrDims;
                int curDimLen = dimensions[curDim];
                m_indexOffset   = indexOffset;
                m_leadDimIdx    = indexOffset[curDim];
                m_higherDimsIdx = new int[dimensions.NumberOfElements / dimensions[m_leadDim]];
                int[] curPos = new int[dimensions.NumberOfDimensions];
                // create int vector holding presummed higher dimension indices
                unsafe
                {
                    fixed(int *tmpHighDims = m_higherDimsIdx, tmpLeadDim = m_leadDimIdx,
                          pCurPos          = curPos)
                    {
                        int *pHighDimsIdx  = tmpHighDims;
                        int *pHighDimsLast = pHighDimsIdx + m_higherDimsIdx.Length;
                        int *pLeadDimIdx   = tmpLeadDim;
                        int *pCurPosDim    = pCurPos;
                        int  curIdxSum     = 0;
                        int  d;

                        // sum all idxOffset[d,0] as start value
                        for (d = 2; d < nrDims; d++)
                        {
                            curIdxSum += indexOffset[(m_leadDim + d) % nrDims, 0];
                        }
                        do
                        {
                            // tmp leadDim is 1 dim larger than real leadDim
                            // sum leadDim
                            for (int i = 0; i < curDimLen; i++)
                            {
                                *pHighDimsIdx++ = curIdxSum + *pLeadDimIdx++;
                            }
                            // start increasing at 2 dims higher than lead dim
                            pLeadDimIdx = tmpLeadDim;
                            for (d = 2; pHighDimsIdx < pHighDimsLast && d < nrDims; d++)
                            {
                                curDim      = (d + m_leadDim) % nrDims;
                                pCurPosDim  = pCurPos + curDim;
                                curIdxSum  -= m_indexOffset[curDim, *pCurPosDim];
                                *pCurPosDim = *pCurPosDim + 1;
                                if (*pCurPosDim < dimensions[curDim])
                                {
                                    curIdxSum += m_indexOffset[curDim, *pCurPosDim];
                                    break;
                                }
                                *pCurPosDim = 0;
                                curIdxSum  += m_indexOffset[curDim, *pCurPosDim];
                            }
                        } while (pHighDimsIdx < pHighDimsLast && d < nrDims);
                    }
                }
                m_leadDimIdx = indexOffset[m_leadDim];
                // get start/ end positions
                switch (startPos)
                {
                case ILIteratorPositions.ILStart:
                    m_curLeadIdx = 0;
                    m_curHighDim = 0;
                    m_pos        = m_leadDimIdx[0] + m_higherDimsIdx[0];
                    break;

                case ILIteratorPositions.ILMiddle:
                    m_curLeadIdx = 0;
                    m_curHighDim = (int)(m_higherDimsIdx.Length / 2.0);
                    m_pos        = m_leadDimIdx[0] + m_higherDimsIdx[m_curHighDim];
                    break;

                case ILIteratorPositions.ILEnd:
                    m_curLeadIdx = m_leadDimIdx.Length - 1;
                    m_curHighDim = m_higherDimsIdx.Length - 1;
                    m_pos        = m_leadDimIdx[m_curLeadIdx]
                                   + m_higherDimsIdx[m_curHighDim];
                    break;
                }
            }
            // determine if this storage can be altered
            if (ILArray <BaseT> .GetNumberOfReferences(m_data) > 1)
            {
                m_readonly = true;
            }
            else
            {
                m_readonly = false;
            }
        }