当前位置: 首页>>代码示例>>C++>>正文


C++ Scanner::nextInColumn方法代码示例

本文整理汇总了C++中Scanner::nextInColumn方法的典型用法代码示例。如果您正苦于以下问题:C++ Scanner::nextInColumn方法的具体用法?C++ Scanner::nextInColumn怎么用?C++ Scanner::nextInColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scanner的用法示例。


在下文中一共展示了Scanner::nextInColumn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char *argv[])
{
    // argc should be 4 for correct execution
    if (argc != 4)
    {
        std::cout << "Wrong input. Usage: strassen mode dimension inputfile" << std::endl;
        return 1;
    }

    // get parameters
    else
    {
        const unsigned short int mode = atoi(argv[1]);
        std::cout << mode << std::endl;
        const unsigned int dimension = atoi(argv[2]);
        char * inputfile = argv[3];

        switch(mode)
        {
          // Read inout from the file
          case 0:
          {
            std::ifstream infile;
            infile.open (inputfile);
            unsigned int len = dimension*dimension;
            char* line = (char*) malloc(sizeof(char)*10);
            if (infile.is_open())
            {
              int * dataA = (int*) malloc(sizeof(int)*len);
              int * dataB = (int*) malloc(sizeof(int)*len);
              if(dataA == NULL || dataB == NULL)
              {
                std::cout << "error allocating memory" << std::endl;
                return 1;
              }
              for (unsigned int i = 0; i < len; ++i)
              {
                infile >> line;
                dataA[i] = atoi(line);
              }
              for (unsigned int j = 0; j < dimension; ++j)
              {
                for (unsigned int i = 0; i < dimension; ++i)
                {
                  infile >> line;
                  dataB[i*dimension+j] = atoi(line);
                }
              }
              free(line);

              // input matrices to work with
              Scanner matrixA = Scanner(dataA, true, dimension, dimension, dimension, dimension);
              Scanner matrixB = Scanner(dataB, false, dimension, dimension, dimension, dimension);
              MatrixOps matmath = MatrixOps();
              Scanner matrixC = matmath.strassensWrapper(matrixA, matrixB);
              std::cout << matrixC.current() << std::endl;
              matrixC.nextInRow();
              for (unsigned int i = 1; i < dimension; i++)
              {
                std::cout << matrixC.nextInColumn() << std::endl;
                matrixC.nextInRow();
              }
              std::cout << std::endl;
              free(dataA);
              free(dataB);
            }
            infile.close();
            break;
          }
          // used for determining crossover
          case 1:
          {
            MatrixOps matmath = MatrixOps();
            int * dataA = new int[dimension*dimension+1];
            for (unsigned int i = 0; i < dimension; ++i)
            {
              for (unsigned int j = 0; j < dimension; ++j)
              {
                dataA[i * dimension + j] = rand() % 3 - 1;
              }
            }
            int * dataB = new int[dimension*dimension+1];
            for (unsigned int i = 0; i < dimension; ++i)
            {
              for (unsigned int j = 0; j < dimension; ++j)
              {
                dataB[i * dimension + j] = rand() % 3 - 1;
              }
            }

            Scanner A = Scanner(dataA, true, dimension, dimension, dimension, dimension);
            Scanner B = Scanner(dataB, false, dimension, dimension, dimension, dimension);
            double prevTime = DBL_MAX;
            unsigned int bestPoint = -1;
            unsigned int crossPoint = 8;
            while (crossPoint < dimension)
            {
              double runtime = 0;
              clock_t t = clock();
              matmath.strassensWrapper(A, B, crossPoint);
//.........这里部分代码省略.........
开发者ID:abbylyons,项目名称:181practicals,代码行数:101,代码来源:strassen.cpp


注:本文中的Scanner::nextInColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。