text:
#ifndef PICTUREFRAMES_H
#define PICTUREFRAMES_H

#include "framebase.h"
#include <QString>
//#include <vector>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <QtGui/QImage>

struct IplImageDeleter
    {
    void operator() (IplImage* aImage)
        {
        cvReleaseImage(&aImage);
        }
    };

namespace media {

template <int ChannelsNo>
class IplImageFrame : public MultiChannelFrame
    {
public:
    enum { Width, Height, Channels, Dimensions };

    explicit IplImageFrame(int aDepth = IPL_DEPTH_8U) :
        MultiChannelFrame(Dimensions),
        mDepth(aDepth),
        mIplImage(NULL)
        {
        mDimensions[Channels].mResolution = ChannelsNo;
        mDimensions[Width].mDelta = mDimensions[Height].mDelta = mDimensions[Channels].mDelta = 1;
        release();
        }

    virtual ~IplImageFrame()
        {
        release();
        }

    qreal getSampleT(const int *aPoint) const
        {
        Q_ASSERT(mIplImage != NULL);
        Q_ASSERT(aPoint[Width] < mIplImage->width);
        Q_ASSERT(aPoint[Height] < mIplImage->height);
        Q_ASSERT(aPoint[Channels] < mIplImage->nChannels);
        Q_ASSERT((mIplImage->imageSize > aPoint[Height]*mIplImage->widthStep + aPoint[Width]*mIplImage->nChannels + aPoint[Channels]));
        return static_cast<quint8>(mIplImage->imageData[aPoint[Height]*mIplImage->widthStep + aPoint[Width]*mIplImage->nChannels + aPoint[Channels]]);
        }

    void setSampleT(const int *aPoint, qreal aValue)
        {
        Q_ASSERT(mIplImage != NULL);
        Q_ASSERT(aPoint[Width] < mIplImage->width);
        Q_ASSERT(aPoint[Height] < mIplImage->height);
        Q_ASSERT(aPoint[Channels] < mIplImage->nChannels);
        Q_ASSERT((mIplImage->imageSize > aPoint[Height]*mIplImage->widthStep + aPoint[Width]*mIplImage->nChannels + aPoint[Channels]));
        mIplImage->imageData[aPoint[Height]*mIplImage->widthStep + aPoint[Width]*mIplImage->nChannels + aPoint[Channels]] = aValue;
        }

    operator IplImage*() const { return mIplImage; }

    void resize(const int *aSize) { resize(aSize[Width], aSize[Height]); }
    void resize(int aWidth, int aHeight)
        {
        if (mIplImage && ((mDimensions[Width].mResolution != aWidth) || (mDimensions[Height].mResolution != aHeight)))
            release();
        if (!mIplImage)
            {
            mIplImage = cvCreateImage(cvSize(aWidth, aHeight), mDepth, mDimensions[Channels].mResolution);
            mDimensions[Width].mResolution = aWidth;
            mDimensions[Height].mResolution = aHeight;
            }
        }

    bool resizeAndCopyFrame(const FrameBase& aFrame)
        {
        if (!MultiChannelFrame::isCopyable(aFrame))
            return false;

        if (aFrame.getMaxDimension() < getMaxDimension())
            return MultiChannelFrame::resizeAndCopyFrame(aFrame);
        //else
        if (aFrame.getDimensionT(Channels).mResolution >= 3)
            {
            IplImageFrame<3> frame;
            frame.MultiChannelFrame::resizeAndCopyFrame(aFrame);
            this->operator =(*(IplImage*)frame);
            }
        else if (aFrame.getDimensionT(Channels).mResolution >= 1)
            {
            IplImageFrame<1> frame;
            frame.MultiChannelFrame::resizeAndCopyFrame(aFrame);
            this->operator =(*(IplImage*)frame);
            }
        return true;
        }

    void release()
        {
        if (mIplImage)
            {
            cvReleaseImage(&mIplImage);
            mIplImage = NULL;
            }
        mDimensions[Width].mResolution = mDimensions[Height].mResolution = 0;
        }

    void clear()
        {
        if (mIplImage)
            cvZero(mIplImage);
        }

    const IplImageFrame& operator=(const IplImage &aIplImage)
        {
        resize(aIplImage.width, aIplImage.height);
        if (aIplImage.nChannels > mDimensions[Channels].mResolution)
            cvCvtColor(&aIplImage, mIplImage, CV_RGB2GRAY);
        else if (aIplImage.nChannels < mDimensions[Channels].mResolution)
            cvCvtColor(&aIplImage, mIplImage, CV_GRAY2RGB);
        else
            cvCopy(&aIplImage, mIplImage);
        return *this;
        }

    const IplImageFrame& operator=(const cv::Mat &aMat)
        {
        return operator=((IplImage)aMat);
        }

    const IplImageFrame& operator=(const QImage &aImage)
        {
        IplImage* img = QImage2Ipl(aImage);
        operator=(*img);
        cvReleaseImage(&img);
        return *this;
        }

    /**
      * @brief source: https://code.google.com/p/find-object/
      */
    static IplImage* QImage2Ipl(const QImage & image)
        {
        IplImage * iplTmp = 0;
        if(!image.isNull() && image.depth() == 32 && image.format() == QImage::Format_RGB32)
            {
            int x;
            int y;

            // assume RGB (3 channels)
            int channels = 3;
            iplTmp = cvCreateImage(cvSize(image.width(), image.height()), IPL_DEPTH_8U, channels);
            char* data = iplTmp->imageData;
            for( y = 0; y < image.height(); ++y, data+=iplTmp->widthStep)
                {
                for( x = 0; x < image.width(); ++x)
                    {
                    QRgb rgb = image.pixel(x, y);
                    data[x * channels+2] = qRed(rgb); //r
                    data[x * channels+1] = qGreen(rgb); //g
                    data[x * channels] = qBlue(rgb); //b
                    }
                }
            }
        else
            {
            printf("failed to convert image : depth=%d(!=32) format=%d(!=%d)\n", image.depth(), image.format(), QImage::Format_RGB32);
            }
        return iplTmp;
        }

private:
    int mDepth;
    IplImage* mIplImage;
    };

typedef IplImageFrame<1> PictureGrayFrame;
typedef IplImageFrame<3> PictureRGBFrame;

//
// TODO: add binary points frame for contour approx. (e.g. approxPolyDP)
// TODO: add 2+5-dim points frame for ellipse approx.
//
class PointsFrame : public FrameBase
    {
public:
    enum { XAxis, YAxis, MaxAxis };
    enum { Index, Axis, Dimensions };
    explicit PointsFrame();

    qreal getSampleT(const int *aPoint) const;
    void setSampleT(const int *aPoint, qreal aValue);

    void resize(const int* aPoint)
        {
        mPoints.resize(aPoint[Index]);
        mDimensions[Index].mResolution = mPoints.size();
        }

    const PointsFrame& operator=(const std::vector<cv::Point> aPoints)
        {
        int size[] = { (int)aPoints.size(), MaxAxis };
        resize(size);
        mPoints = aPoints;
        return *this;
        }

    const PointsFrame& operator=(const std::vector<CvPoint> aPoints)
        {
        int size[] = { (int)aPoints.size(), MaxAxis };
        resize(size);
        for (int i = 0; i < (int)aPoints.size(); ++i)
            {
            mPoints[i].x = aPoints[i].x;
            mPoints[i].y = aPoints[i].y;
            }
        return *this;
        }

    void copyTo(std::vector<CvPoint> aPoints)
        {
        aPoints.resize(mPoints.size());
        for (int i = 0; i < (int)mPoints.size(); ++i)
            {
            aPoints[i].x = mPoints[i].x;
            aPoints[i].y = mPoints[i].y;
            }
        }

    bool isCopyable(const FrameBase& aFrame) const
        {
        return FrameBase::isCopyable(aFrame)
            && (aFrame.getDimensionT(Axis).mResolution == MaxAxis);
        }

private:
    bool readFromFile(const QString& aFileName);
    void writeToFile(const QString& aFileName) const;

    std::vector<cv::Point> mPoints;
    };

} // namespace media

#endif // PICTUREFRAMES_H


text:
from .basepattern import BasePattern

class Grid(BasePattern):
    def get_cell(self, row, column):
        raise NotImplementedError(
            'Get the cell element by location'
        )

    @property
    def row_count(self):
        raise NotImplementedError(
            'Get row count'
        )

    @property
    def column_count(self):
        raise NotImplementedError(
            'Get column count'
        )

redpajama_set_name: RedPajamaGithub


text: {{symbol}} = new {{call_constructor}};


text:
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.operator.scalar;

import com.facebook.presto.spi.block.Block;
import com.facebook.presto.spi.function.Description;
import com.facebook.presto.spi.function.OperatorDependency;
import com.facebook.presto.spi.function.ScalarFunction;
import com.facebook.presto.spi.function.SqlNullable;
import com.facebook.presto.spi.function.SqlType;
import com.facebook.presto.spi.function.TypeParameter;
import com.facebook.presto.spi.type.StandardTypes;
import com.facebook.presto.spi.type.Type;
import io.airlift.slice.Slice;

import java.lang.invoke.MethodHandle;

import static com.facebook.presto.operator.scalar.ArrayMinMaxUtils.booleanArrayMinMax;
import static com.facebook.presto.operator.scalar.ArrayMinMaxUtils.doubleArrayMinMax;
import static com.facebook.presto.operator.scalar.ArrayMinMaxUtils.longArrayMinMax;
import static com.facebook.presto.operator.scalar.ArrayMinMaxUtils.sliceArrayMinMax;
import static com.facebook.presto.spi.function.OperatorType.LESS_THAN;
import static com.facebook.presto.util.Failures.internalError;

@ScalarFunction("array_min")
@Description("Get minimum value of array")
public final class ArrayMinFunction
{
    private ArrayMinFunction() {}

    @TypeParameter("T")
    @SqlType("T")
    @SqlNullable
    public static Long longArrayMin(
            @OperatorDependency(operator = LESS_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle compareMethodHandle,
            @TypeParameter("T") Type elementType,
            @SqlType("array(T)") Block block)
    {
        return longArrayMinMax(compareMethodHandle, elementType, block);
    }

    @TypeParameter("T")
    @SqlType("T")
    @SqlNullable
    public static Boolean booleanArrayMin(
            @OperatorDependency(operator = LESS_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle compareMethodHandle,
            @TypeParameter("T") Type elementType,
            @SqlType("array(T)") Block block)
    {
        return booleanArrayMinMax(compareMethodHandle, elementType, block);
    }

    @TypeParameter("T")
    @SqlType("T")
    @SqlNullable
    public static Double doubleArrayMin(
            @OperatorDependency(operator = LESS_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle compareMethodHandle,
            @TypeParameter("T") Type elementType,
            @SqlType("array(T)") Block block)
    {
        return doubleArrayMinMax(compareMethodHandle, elementType, block);
    }

    @TypeParameter("T")
    @SqlType("T")
    @SqlNullable
    public static Slice sliceArrayMin(
            @OperatorDependency(operator = LESS_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle compareMethodHandle,
            @TypeParameter("T") Type elementType,
            @SqlType("array(T)") Block block)
    {
        return sliceArrayMinMax(compareMethodHandle, elementType, block);
    }

    @TypeParameter("T")
    @SqlType("T")
    @SqlNullable
    public static Block blockArrayMin(
            @OperatorDependency(operator = LESS_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle compareMethodHandle,
            @TypeParameter("T") Type elementType,
            @SqlType("array(T)") Block block)
    {
        try {
            if (block.getPositionCount() == 0) {
                return null;
            }

            Block selectedValue = (Block) elementType.getObject(block, 0);
            for (int i = 0; i < block.getPositionCount(); i++) {
                if (block.isNull(i)) {
                    return null;
                }
                Block value = (Block) elementType.getObject(block, i);
                if ((boolean) compareMethodHandle.invokeExact(value, selectedValue)) {
                    selectedValue = value;
                }
            }

            return selectedValue;
        }
        catch (Throwable t) {
            throw internalError(t);
        }
    }
}