コード例 #1
0
ファイル: lab02.cpp プロジェクト: Guard96/2014
int main(int argc, char** argv)
{
	if (argc < 3) {
		return __exception("Not found input file");
	}

	int mRows1 = 0;
	int mCols1 = 0;
	int mRows2 = 0;
	int mCols2 = 0;
	double** matrix1 = __loadMatrix(argv[1], &mRows1, &mCols1);
	double** matrix2 = __loadMatrix(argv[2], &mRows2, &mCols2);

	fprintf(stdout, "Matrix N1:\n");
	__printMatrix(matrix1, mRows1, mCols1);
	fprintf(stdout, "Matrix N2:\n");
	__printMatrix(matrix2, mRows2, mCols2);

	double max1 = __findMaxElement(matrix1, mRows1, mCols1);
	double max2 = __findMaxElement(matrix2, mRows2, mCols2);

	if (max1 < max2) {
		fprintf(stdout, "Output matrix N1:\n");
		__outputMaxElements(matrix1, mRows1, mCols1);
	}
	else {
		fprintf(stdout, "Output matrix N2:\n");
		__outputMaxElements(matrix2, mRows2, mCols2);
	}
	__destroyMatrix(matrix1, mRows1, mCols1);
	__destroyMatrix(matrix2, mRows2, mCols2);
	system("pause");
	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: lab2.cpp プロジェクト: Guard96/2014
int main(int argc, char **argv)
{
	if (argc < 3)
		return __exception("Not found input file");

	setlocale(0, "Russian");
	int  mRows1,mCols1,mRows2,mCols2,mtx1,mtx2 = 0;
	
	double ** matrix1 = __loadMatrix(argv[1], &mRows1, &mCols1);
	double ** matrix2 = __loadMatrix(argv[2], &mRows2, &mCols2);

	fprintf(stdout, "Матрица 1:\n");
	__printMatrix(matrix1, mRows1, mCols1);
	fprintf(stdout, "Матрица 2:\n");
	__printMatrix(matrix2, mRows2, mCols2);
	
	mtx1 = __calculate(matrix1, mRows1, mCols1);
	mtx2 = __calculate(matrix2, mRows2, mCols2);

	if (mtx1 < mtx2) {
		printf("Среднее арифметическое положительных элементов 1 матрици меньше.\n");
		__Count(matrix1, mRows1, mCols1);
	} else {
		printf("Среднее арифметическое положительных элементов 2 матрици меньше.\n");
		__Count(matrix2, mRows2, mCols2);
	}
	
	__destroyMatrix(matrix1, mRows1, mCols1);
	__destroyMatrix(matrix2, mRows2, mCols2);

	system("pause");
	return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: Formatting.cpp プロジェクト: gtgalone/pytorch
std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesize) {
  FormatGuard guard(stream);
  if(!tensor_.defined()) {
    stream << "[ Tensor (undefined) ]";
  } else if (tensor_.is_sparse()) {
    stream << "[ " << tensor_.pImpl->toString() << "{}\n";
    stream << "indices:\n" << tensor_._indices() << "\n";
    stream << "values:\n" << tensor_._values() << "\n";
    stream << "size:\n" << tensor_.sizes() << "\n";
    stream << "]";
  } else {
    Type& cpudouble = tensor_.type().toBackend(kCPU).toScalarType(kDouble);
    Tensor tensor = tensor_.toType(cpudouble).contiguous();
    if(tensor.ndimension() == 0) {
      stream << defaultfloat << tensor.data<double>()[0] << std::endl;
      stream << "[ " << tensor_.pImpl->toString() << "{} ]";
    } else if(tensor.ndimension() == 1) {
      if (tensor.numel() == 0) {
        stream << "[ Tensor (empty) ]";
      }
      else {
        double scale;
        int64_t sz;
        std::tie(scale, sz) =  __printFormat(stream, tensor);
        if(scale != 1) {
          printScale(stream, scale);
        }
        double* tensor_p = tensor.data<double>();
        for(int64_t i = 0; i < tensor.size(0); i++) {
          stream << std::setw(sz) << tensor_p[i]/scale << std::endl;
        }
        stream << "[ " << tensor_.pImpl->toString() << "{" << tensor.size(0) << "} ]";
      }
    } else if(tensor.ndimension() == 2) {
      __printMatrix(stream, tensor, linesize, 0);
      stream << "[ " << tensor_.pImpl->toString() << "{" << tensor.size(0) << "," <<  tensor.size(1) << "} ]";
    } else {
        __printTensor(stream, tensor, linesize);
        stream << "[ " << tensor_.pImpl->toString() << "{" << tensor.size(0);
        for(int64_t i = 1; i < tensor.ndimension(); i++) {
          stream << "," << tensor.size(i);
        }
        stream << "} ]";
    }
  }
  return stream;
}
コード例 #4
0
ファイル: Formatting.cpp プロジェクト: gtgalone/pytorch
void __printTensor(std::ostream& stream, Tensor& self, int64_t linesize)
{
  std::vector<int64_t> counter(self.ndimension()-2);
  bool start = true;
  bool finished = false;
  counter[0] = -1;
  for(size_t i = 1; i < counter.size(); i++)
    counter[i] = 0;
  while(true) {
    for(int64_t i = 0; self.ndimension()-2; i++) {
      counter[i] = counter[i] + 1;
      if(counter[i] >= self.size(i)) {
        if(i == self.ndimension()-3) {
          finished = true;
          break;
        }
        counter[i] = 0;
      } else {
        break;
      }
    }
    if(finished) {
      break;
    }
    if(start) {
      start = false;
    } else {
      stream << std::endl;
    }
    stream << "(";
    Tensor tensor = self;
    for(int64_t i=0; i < self.ndimension()-2; i++) {
      tensor = tensor.select(0, counter[i]);
      stream << counter[i]+1 << ",";
    }
    stream << ".,.) = " << std::endl;
    __printMatrix(stream, tensor, linesize, 1);
  }
}