本文整理汇总了C++中viennacl::matrix::size1方法的典型用法代码示例。如果您正苦于以下问题:C++ matrix::size1方法的具体用法?C++ matrix::size1怎么用?C++ matrix::size1使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viennacl::matrix
的用法示例。
在下文中一共展示了matrix::size1方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runNormalization
FeatureNormalize<Scalar>::FeatureNormalize(const viennacl::matrix<Scalar> &X):
blas_matrix_(X.size1(), X.size2()),
normalized_matrix_(X.size1(), X.size2()),
mu_(X.size2()), sigma_(X.size2()) {
viennacl::copy(X, blas_matrix_);
runNormalization();
}
示例2: luT
double luT(
viennacl::matrix<T> &vclX,
viennacl::vector_base<T> &vclD) {
double logdet=-99.9;
viennacl::linalg::lu_factorize(vclX);
// pointer to the actual diagonal
viennacl::vector_base<T> diagOfVar(
vclX.handle(), vclX.size1(), 0,
vclX.internal_size2() + 1);
// compute log determinant
vclD = viennacl::linalg::element_log(diagOfVar);
logdet = viennacl::linalg::sum(vclD);
// OPERATION_UNARY_LOG_TYPE
//http://viennacl.sourceforge.net/doc/scheduler_8cpp-example.html#a11
// put the diagonals in D, and 1's on the diagonal of L
vclD = diagOfVar;
//diagOfVar = T(1); // problem here
return(logdet);
}
示例3: init_random
void init_random(viennacl::matrix<T, F> & M)
{
std::vector<T> cM(M.internal_size());
for (std::size_t i = 0; i < M.size1(); ++i)
for (std::size_t j = 0; j < M.size2(); ++j)
cM[F::mem_index(i, j, M.internal_size1(), M.internal_size2())] = T(rand())/T(RAND_MAX);
viennacl::fast_copy(&cM[0],&cM[0] + cM.size(),M);
}
示例4: matrix_print
void matrix_print(viennacl::matrix<ScalarType, MatrixLayout>& A)
{
for (unsigned int i = 0; i < A.size1(); i++) {
for (unsigned int j = 0; j < A.size2(); j++)
std::cout << std::fixed << A(i, j) << "\t";
std::cout << "\n";
}
}
示例5: fill_matrix
void fill_matrix(viennacl::matrix<NumericT> & mat)
{
for (std::size_t i = 0; i < mat.size1(); ++i)
{
for (std::size_t j = 0; j < mat.size2(); ++j)
mat(i, j) = static_cast<NumericT>(-0.5) * random<NumericT>();
mat(i, i) = NumericT(1.0) + NumericT(2.0) * random<NumericT>(); //some extra weight on diagonal for stability
}
}
示例6: householder_c
bool householder_c(viennacl::matrix<SCALARTYPE, row_major, ALIGNMENT>& A,
viennacl::matrix<SCALARTYPE, row_major, ALIGNMENT>& Q,
viennacl::vector<SCALARTYPE, ALIGNMENT>& D,
vcl_size_t row_start, vcl_size_t col_start)
{
viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(A).context());
if (row_start + 1 >= A.size1())
return false;
prepare_householder_vector(A, D, A.size1(), row_start, col_start, row_start, true);
{
viennacl::ocl::kernel& kernel = ctx.get_kernel(viennacl::linalg::opencl::kernels::svd<SCALARTYPE>::program_name(), SVD_HOUSEHOLDER_UPDATE_A_LEFT_KERNEL);
viennacl::ocl::enqueue(kernel(
A,
D,
static_cast<cl_uint>(row_start),
static_cast<cl_uint>(col_start),
static_cast<cl_uint>(A.size1()),
static_cast<cl_uint>(A.size2()),
static_cast<cl_uint>(A.internal_size2()),
viennacl::ocl::local_mem(static_cast<cl_uint>(128 * sizeof(SCALARTYPE)))
));
}
{
viennacl::ocl::kernel& kernel = ctx.get_kernel(viennacl::linalg::opencl::kernels::svd<SCALARTYPE>::program_name(), SVD_HOUSEHOLDER_UPDATE_QL_KERNEL);
viennacl::ocl::enqueue(kernel(
Q,
D,
static_cast<cl_uint>(A.size1()),
// static_cast<cl_uint>(A.size2()),
static_cast<cl_uint>(Q.internal_size2()),
viennacl::ocl::local_mem(static_cast<cl_uint>(128 * sizeof(SCALARTYPE)))
));
}
return true;
}
示例7: matrix_print
void matrix_print(viennacl::matrix<ScalarType>& A_orig)
{
ublas::matrix<ScalarType> A(A_orig.size1(), A_orig.size2());
viennacl::copy(A_orig, A);
std::cout << "matrix_print!\n";
for (unsigned int i = 0; i < A.size1(); i++) {
for (unsigned int j = 0; j < A.size2(); j++)
std::cout << A(i, j) << "\t";
std::cout << "\n";
}
}
示例8: sharedCol
viennacl::vector_range<viennacl::vector_base<T> > sharedCol(){
// viennacl::vector_base<T> tmp(ptr_matrix->handle(), ptr_matrix->internal_size(), 0, 1);
// std::cout << "returning column" << std::endl;
viennacl::vector_base<T> tmp(ptr_matrix->handle(), ptr_matrix->size1(), begin, ptr_matrix->internal_size2());
// std::cout << "got column" << std::endl;
viennacl::vector_range<viennacl::vector_base<T> > v_sub(tmp, r);
// std::cout << "got range" << std::endl;
return v_sub;
}
示例9: check_bidiag
bool check_bidiag(viennacl::matrix<ScalarType>& A)
{
const ScalarType EPS = 0.0001f;
std::vector<ScalarType> aA(A.size1() * A.size2());
viennacl::fast_copy(A, &aA[0]);
for(std::size_t i = 0; i < A.size1(); i++)
{
for(std::size_t j = 0; j < A.size2(); j++)
{
ScalarType val = aA[i * A.size2() + j];
if((fabs(val) > EPS) && (i != j) && ((i + 1) != j))
{
std::cout << "Failed at " << i << " " << j << " " << val << std::endl;
return false;
}
}
}
return true;
}
示例10: bidiag
void bidiag(viennacl::matrix<SCALARTYPE, row_major, ALIGNMENT> & Ai,
viennacl::matrix<SCALARTYPE, row_major, ALIGNMENT> & QL,
viennacl::matrix<SCALARTYPE, row_major, ALIGNMENT> & QR)
{
vcl_size_t row_num = Ai.size1();
vcl_size_t col_num = Ai.size2();
vcl_size_t to = std::min(row_num, col_num);
vcl_size_t big_to = std::max(row_num, col_num);
//for storing householder vector
viennacl::vector<SCALARTYPE, ALIGNMENT> hh_vector(big_to, viennacl::traits::context(Ai));
QL = viennacl::identity_matrix<SCALARTYPE>(QL.size1(), viennacl::traits::context(QL));
QR = viennacl::identity_matrix<SCALARTYPE>(QR.size1(), viennacl::traits::context(QR));
for (vcl_size_t i = 0; i < to; i++)
{
householder_c(Ai, QL, hh_vector, i, i);
householder_r(Ai, QR, hh_vector, i, i+1);
}
}
示例11: diff
NumericT diff(std::vector<std::vector<NumericT> > const & A1, viennacl::matrix<NumericT> const & A2)
{
std::vector<NumericT> host_values(A2.internal_size());
for (std::size_t i=0; i<A2.size1(); ++i)
for (std::size_t j=0; j<A2.size2(); ++j)
host_values[i*A2.internal_size2() + j] = A1[i][j];
std::vector<NumericT> device_values(A2.internal_size());
viennacl::fast_copy(A2, &device_values[0]);
viennacl::vector<NumericT> vcl_device_values(A2.internal_size()); // workaround to avoid code duplication
viennacl::copy(device_values, vcl_device_values);
return diff(host_values, vcl_device_values);
}
示例12: check_tridiag
bool check_tridiag(viennacl::matrix<ScalarType, MatrixLayout>& A_orig)
{
ublas::matrix<ScalarType> A(A_orig.size1(), A_orig.size2());
viennacl::copy(A_orig, A);
for (unsigned int i = 0; i < A.size1(); i++) {
for (unsigned int j = 0; j < A.size2(); j++) {
if ((std::abs(A(i, j)) > EPS) && ((i - 1) != j) && (i != j) && ((i + 1) != j))
{
// std::cout << "Failed at " << i << " " << j << " " << A(i, j) << "\n";
return false;
}
}
}
return true;
}
示例13: check_hessenberg
bool check_hessenberg(viennacl::matrix<ScalarType, MatrixLayout>& A_orig)
{
ublas::matrix<ScalarType> A(A_orig.size1(), A_orig.size2());
viennacl::copy(A_orig, A);
for (std::size_t i = 0; i < A.size1(); i++) {
for (std::size_t j = 0; j < A.size2(); j++) {
if ((std::abs(A(i, j)) > EPS) && (i > (j + 1)))
{
// std::cout << "Failed at " << i << " " << j << " " << A(i, j) << "\n";
return false;
}
}
}
return true;
}
示例14: diff
ScalarType diff(ublas::matrix<ScalarType> & mat1, viennacl::matrix<ScalarType, F, ALIGNMENT> & mat2)
{
ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
copy(mat2, mat2_cpu);
ScalarType ret = 0;
ScalarType act = 0;
for (unsigned int i = 0; i < mat2_cpu.size1(); ++i)
{
for (unsigned int j = 0; j < mat2_cpu.size2(); ++j)
{
act = fabs(mat2_cpu(i,j) - mat1(i,j)) / std::max( fabs(mat2_cpu(i, j)), fabs(mat1(i,j)) );
if (act > ret)
ret = act;
}
}
//std::cout << ret << std::endl;
return ret;
}
示例15: read_matrix_body
void read_matrix_body(std::fstream& f, viennacl::matrix<ScalarType, MatrixLayout>& A)
{
if(!f.is_open())
{
throw std::invalid_argument("File is not opened");
}
boost::numeric::ublas::matrix<ScalarType> h_A(A.size1(), A.size2());
for(std::size_t i = 0; i < h_A.size1(); i++) {
for(std::size_t j = 0; j < h_A.size2(); j++) {
ScalarType val = 0.0;
f >> val;
h_A(i, j) = val;
}
}
viennacl::copy(h_A, A);
}