⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix_int.c

📁 QccPack-0.54-1 released (2007-04-30) is being developed and tested on Fedora Core Linux. QccPack pro
💻 C
字号:
/* *  * QccPack: Quantization, compression, and coding libraries * Copyright (C) 1997-2007  James E. Fowler *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. *  * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, * MA 02139, USA. *  */#include "libQccPack.h"QccMatrixInt QccMatrixIntAlloc(int num_rows,                               int num_cols){  QccMatrixInt matrix;  int row;    if ((num_rows <= 0) || (num_cols <= 0))    return(NULL);  if ((matrix =        (QccMatrixInt)malloc(sizeof(QccVectorInt) * num_rows)) == NULL)    {      QccErrorAddMessage("(QccMatrixIntAlloc): Error allocating memory");      return(NULL);    }    for (row = 0; row < num_rows; row++)    if ((matrix[row] = QccVectorIntAlloc(num_cols)) == NULL)      {        QccErrorAddMessage("(QccMatrixIntAlloc): Error allocating memory");        QccFree(matrix);        return(NULL);      }    return(matrix);}void QccMatrixIntFree(QccMatrixInt matrix,                      int num_rows){  int row;    if (matrix != NULL)    {      for (row = 0; row < num_rows; row++)        QccVectorIntFree(matrix[row]);      QccFree(matrix);    }}int QccMatrixIntZero(QccMatrixInt matrix,                     int num_rows,                     int num_cols){  int row, col;  if (matrix == NULL)    return(0);  for (row = 0; row < num_rows; row++)    for (col = 0; col < num_cols; col++)      matrix[row][col] = 0;  return(0);}int QccMatrixIntCopy(QccMatrixInt matrix1,                     const QccMatrixInt matrix2,                     int num_rows,                     int num_cols){  int row, col;  if ((matrix1 == NULL) ||       (matrix2 == NULL) ||      (num_rows <= 0) ||      (num_cols <= 0))    return(0);  for (row = 0; row < num_rows; row++)    for (col = 0; col < num_cols; col++)      matrix1[row][col] = matrix2[row][col];  return(0);}int QccMatrixIntMaxValue(const QccMatrixInt matrix,                         int num_rows,                         int num_cols){  int row;  int max_value = -MAXINT;  int tmp;    if (matrix != NULL)    for (row = 0; row < num_rows; row++)      {        tmp = QccVectorIntMaxValue(matrix[row], num_cols, NULL);        if (tmp > max_value)          max_value = tmp;      }  return(max_value);}int QccMatrixIntMinValue(const QccMatrixInt matrix,                         int num_rows,                         int num_cols){  int row;  int min_value = MAXINT;  int tmp;    if (matrix != NULL)    for (row = 0; row < num_rows; row++)      {        tmp = QccVectorIntMinValue(matrix[row], num_cols, NULL);        if (tmp < min_value)          min_value = tmp;      }  return(min_value);}int QccMatrixIntPrint(const QccMatrixInt matrix,                      int num_rows,                      int num_cols){  int row, col;  if (matrix == NULL)    return(0);  for (row = 0; row < num_rows; row++)    {      for (col = 0; col < num_cols; col++)        printf("%d ", matrix[row][col]);      printf("\n");    }  return(0);}int QccMatrixIntTranspose(const QccMatrixInt matrix1,                          QccMatrixInt matrix2,                          int num_rows,                          int num_cols){  int row, col;  if (matrix1 == NULL)    return(0);  if (matrix2 == NULL)    return(0);  for (row = 0; row < num_rows; row++)    for (col = 0; col < num_cols; col++)      matrix2[col][row] = matrix1[row][col];  return(0);}int QccMatrixIntAdd(QccMatrixInt matrix1,                    const QccMatrixInt matrix2,                    int num_rows,                    int num_cols){  int row;  if (matrix1 == NULL)    return(0);  if (matrix2 == NULL)    return(0);  for (row = 0; row < num_rows; row++)    if (QccVectorIntAdd(matrix1[row], matrix2[row], num_cols))      {        QccErrorAddMessage("(QccMatrixIntAdd): Error calling QccVectorIntAdd()");        return(1);      }  return(0);}int QccMatrixIntSubtract(QccMatrixInt matrix1,                         const QccMatrixInt matrix2,                         int num_rows,                         int num_cols){  int row;  if (matrix1 == NULL)    return(0);  if (matrix2 == NULL)    return(0);  for (row = 0; row < num_rows; row++)    if (QccVectorIntSubtract(matrix1[row], matrix2[row], num_cols))      {        QccErrorAddMessage("(QccMatrixIntSubtract): Error calling QccVectorIntSubtract()");        return(1);      }  return(0);}double QccMatrixIntMean(const QccMatrixInt matrix,                        int num_rows,                        int num_cols){  double sum = 0.0;  int row, col;    for (row = 0; row < num_rows; row++)    for (col = 0; col < num_cols; col++)      sum += matrix[row][col];    sum /= num_rows * num_cols;    return(sum);}double QccMatrixIntVariance(const QccMatrixInt matrix,                            int num_rows,                            int num_cols){  double variance = 0.0;  double mean;  int row, col;  mean = QccMatrixIntMean(matrix, num_rows, num_cols);  for (row = 0; row < num_rows; row++)    for (col = 0; col < num_cols; col++)      variance +=        (matrix[row][col] - mean) *        (matrix[row][col] - mean);  variance /= (num_rows * num_cols);  return(variance);}int QccMatrixIntVectorMultiply(const QccMatrixInt matrix,                               const QccVectorInt vector1,                               QccVectorInt vector2,                               int num_rows,                               int num_cols){  int row;  if (matrix == NULL)    return(0);  if (vector1 == NULL)    return(0);  if (vector2 == NULL)    return(0);  for (row = 0; row < num_rows; row++)    vector2[row] =      QccVectorIntDotProduct(matrix[row], vector1, num_cols);  return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -