本文整理汇总了C++中Matrix::GetCols方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::GetCols方法的具体用法?C++ Matrix::GetCols怎么用?C++ Matrix::GetCols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::GetCols方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Diag
/**
* returns a diagonal matrix
* @param v a vector
* @return a diagonal matrix with the given vector v on the diagonal
*/
Matrix Diag(const Matrix& v)
{
Matrix res;
if (v.GetCols() == 1)
{
// the given matrix is a vector n x 1
int rows = v.GetRows();
res = Matrix(rows, rows);
// copy the values of the vector to the matrix
for (int r=1; r <= rows; r++)
{
res(r, r) = v.get(r, 1);
}
}
else if (v.GetRows() == 1)
{
// the given matrix is a vector 1 x n
int cols = v.GetCols();
res = Matrix(cols, cols);
// copy the values of the vector to the matrix
for (int c=1; c <= cols; c++)
{
res(c, c) = v.get(1, c);
}
}
else
{
throw Exception("Parameter for diag must be a vector");
}
return res;
}
示例2: mean
// / Calculates the mean value of the elements in a matrix.
double mean(Matrix < double >&m)
{
double sum = 0.;
for (int r = 0; r < m.GetRows(); r++)
for (int c = 0; c < m.GetCols(); c++)
sum += m[r][c];
return sum / double (m.GetRows() * m.GetCols());
}
示例3: scalprod
Complex scalprod(Matrix < Complex > &m1, Matrix < double >&m2)
{
assert((m1.GetRows() == m2.GetRows()) && (m1.GetCols() == m2.GetCols()));
Complex sum(0, 0);
for (int r = 0; r < m1.GetRows(); r++)
for (int c = 0; c < m1.GetCols(); c++)
sum += m1[r][c] * m2[r][c];
return sum;
}
示例4: variance
// / Calculates the varaince of the elements in a matrix.
double variance(Matrix < double >&m)
{
double sum = 0.;
double average = mean(m);
for (int r = 0; r < m.GetRows(); r++)
for (int c = 0; c < m.GetCols(); c++)
sum += (m[r][c] - average) * (m[r][c] - average);
return sum / double (m.GetRows() * m.GetCols() - 1);
}
示例5: scalconj
Complex scalconj(Matrix < Complex > &m1, Matrix < Complex > &m2) // total(A.B*)
{
assert((m1.GetRows() == m2.GetRows()) && (m1.GetCols() == m2.GetCols()));
Complex sum(0, 0);
for (int r = 0; r < m1.GetRows(); r++)
for (int c = 0; c < m1.GetCols(); c++)
sum += m1[r][c] * conj(m2[r][c]);
return sum;
}
示例6: fft2
Matrix fft2(Matrix &m, int isign)
{
assert(m.bComplex == TRUE);
int ndim = 2;
long row = m.GetRows();
long col = m.GetCols();
Matrix ret(m);
unsigned long nn[3];
nn[1] = row;
nn[2] = col / 2;
#if 1
float *pdata = new float[row * col + 1];
memcpy( pdata + 1, m.p, sizeof(float) * row * col);
fourn( pdata, nn, ndim, isign );
memcpy( ret.p, pdata + 1, sizeof(float) * row * col);
delete[] pdata;
#else
float* pdata = new float[row * col];
memcpy(pdata, m.p, sizeof(float) * row * col);
CUFFT::fft(pdata, col / 2, row, isign == 1);
CUFFT::fft(pdata, col / 2, row, isign != 1);
memcpy(ret.p, pdata, sizeof(float) * row * col);
delete [] pdata;
#endif
ret.bComplex = TRUE;
return ret;
}
示例7: WhitenFrame
Matrix WhitenFrame(Matrix &m)
{
int nRow = m.GetRows();
int nCol = m.GetCols();
assert(nRow == nCol);
Matrix fx(nRow), fy(nRow);
Meshgrid(fx, -nRow / 2, nRow / 2 - 1, fy, -nRow / 2, nRow / 2 - 1);
Matrix theta = fx;
Matrix rho = fx;
cart2pol( fx,fy,theta,rho );
#if 1
Matrix complex = Complex(m);
Matrix fftm = fft2(complex, 1);
Matrix imF = fftshift(fftm);
Matrix time = times(rho, imF);
Matrix imW = fftshift(time);
#else
Matrix complex = Complex(m);
Matrix fftm = fft2(complex, 1);
Matrix imF = fftshift(fftm);
Matrix time = times(rho, imF);
Matrix imW = fftshift(time);
#endif
return imW;
}
示例8: ZeroUnPad
void ZeroUnPad(Matrix < Complex > &unpadded, Matrix < Complex > &padded) // for
// square
// matrices
{
// remove zero padding
int unpadded_size = unpadded.GetCols();
int padded_size = padded.GetCols();
int low = (padded_size - unpadded_size) / 2;
int high = (padded_size + unpadded_size) / 2;
for (int ii = low; ii < high; ii++)
for (int jj = low; jj < high; jj++)
unpadded[ii - high][jj - high] = padded[ii][jj];
}
示例9: total
Complex total(Matrix < Complex > &m)
{
Complex sum(0, 0);
for (int r = 0; r < m.GetRows(); r++)
for (int c = 0; c < m.GetCols(); c++)
sum += m[r][c];
return sum;
}
示例10: ZeroPad
void ZeroPad(Matrix < Complex > &unpadded, Matrix < Complex > &padded) // for
// square
// matrices
{
// Pad a matrix to padding x padding
int unpadded_size = unpadded.GetCols();
int padded_size = padded.GetCols();
int low = (padded_size - unpadded_size) / 2;
int high = (padded_size + unpadded_size) / 2;
for (int ii = low; ii < high; ii++)
for (int jj = low; jj < high; jj++)
padded[ii][jj] = unpadded[ii - low][jj - low];
}
示例11: norm2
double norm2(Matrix < Complex > &m)
{
double sum = 0.;
for (int r = 0; r < m.GetRows(); r++)
for (int c = 0; c < m.GetCols(); c++)
sum += norm(m[r][c]);
return sum;
}
示例12: ExtractCode
int ExtractCode( Image < uint8 > & DATANOR, Code < float > & codedata, Matrix < float > & Feat,
struct osiris_parameter & param, Filtres < float > & Gabor, Appoints & points )
{
Feat = Featextract( DATANOR, Gabor, points );
codedata.SetSize( Feat.GetRows(), Feat.GetCols() );
codedata.TMPLATE = TMextract( Feat );
codedata.MASK.init( 1 );
return ( 0 );
}
示例13: ShowMatrix
void ShowMatrix(ostream& os, const Matrix<T>& m)
{
const size_t MaxR = m.GetRows();
const size_t MaxC = m.GetCols();
size_t r, c;
for (r = 0; r < MaxR; ++r)
{
os << "[ ";
for (c = 0; c < MaxC; ++c)
os << setw(3) << m.Get(r,c) << " ";
os << "]\r\n";
}
}
示例14: toBoolean
bool IfFilterFactory::toBoolean(const Value& value)
{
bool result = false;
wchar_t type = value.GetType();
switch (type)
{
case 'i':
{
int i = value.GetInteger();
result = (i != 0);
}
break;
case 'f':
{
double f = value.GetFloat();
result = (f != 0.0 && f == f);
}
break;
case 'b':
{
result = value.GetBool();
}
break;
case 's':
{
wstring s = value.GetString();
result = s.length() > 0 && s != L"false" && s != L"0";
}
break;
case 'm':
{
Matrix<Value> m = value.GetArray();
result = m.GetRows() > 0 && m.GetCols() > 0;
}
break;
default:
result = false;
break;
}
return result;
}
示例15: mat2fits
// / Converts a matrix composed of doubles into a FITS file
void mat2fits(Matrix < double >&m, const char *filename)
{
int status = 0;
fitsfile *fptr;
long fpixel = 1, naxis = 2, nelements;
long naxes[2];
// Initialise storage
naxes[0] = (long)m.GetRows();
naxes[1] = (long)m.GetCols();
nelements = naxes[0] * naxes[1];
double *ptrimg;
// Create pointer image
ptrimg = (double *)malloc(nelements * sizeof(double));
for (int ii = 0; ii < naxes[0]; ii++)
for (int jj = 0; jj < naxes[1]; jj++)
ptrimg[ ii + jj * naxes[0] ] = m[ii][jj];
// Create new file, write image, then close file
if (status == 0)
fits_create_file(&fptr, filename, &status);
if (status == 0)
fits_create_img(fptr, DOUBLE_IMG, naxis, naxes, &status);
if (status == 0)
fits_write_img(fptr, TDOUBLE, fpixel, nelements, &ptrimg[0], &status);
if (status == 0)
fits_close_file(fptr, &status);
free(ptrimg);
fits_report_error(stderr, status);
}