コード例 #1
0
        public static void ArraySet <[AnyPrimitive] TScalar>(
            MFullArray <TScalar> array, MFullArray <double> indices, TScalar value)
        {
            Contract.Requires(array != null);
            Contract.Requires(indices != null);

            var indicesShape = indices.shape;

            if (!indicesShape.IsVector)
            {
                throw MArrayShapeException.CreateFormatted("Array index must be a vector but has shape {0}.", indicesShape);
            }

            int indexCount = indices.Count;

            for (int i = 0; i < indexCount; i++)
            {
                array[ToInt(indices[i]) - 1] = value;
            }
        }
コード例 #2
0
        public static void ArraySet <[AnyPrimitive] TScalar>(
            MFullArray <TScalar> array, MFullArray <double> indices, MFullArray <TScalar> values)
        {
            Contract.Requires(array != null);
            Contract.Requires(indices != null);
            Contract.Requires(values != null);

            if (indices.IsEmpty)
            {
                return;
            }
            if (values.IsScalar)
            {
                ArraySet(array, indices, values[0]);
                return;
            }

            var indicesShape = indices.shape;

            if (!indicesShape.IsVector)
            {
                throw MArrayShapeException.CreateFormatted("Array index must be a vector but has shape {0}.", indicesShape);
            }

            if (indicesShape != values.shape)
            {
                throw new MArrayShapeException("Assigned value shape must match index shape.");
            }

            int indexCount = indicesShape.Count;

            for (int i = 0; i < indexCount; ++i)
            {
                array[ToInt(indices[i]) - 1] = values[i];
            }
        }