本文整理汇总了C++中read_matrix函数的典型用法代码示例。如果您正苦于以下问题:C++ read_matrix函数的具体用法?C++ read_matrix怎么用?C++ read_matrix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_matrix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void) {
FILE *fin = fopen( "matrix2.in", "r" );
if( fin == NULL ) {
printf( "Error: could not open matrix2.in\n" );
exit( EXIT_FAILURE );
}
Matrix *a = read_matrix( fin );
Matrix *b = read_matrix( fin );
fclose( fin );
Matrix *c = product_matrix( a, b );
FILE *output = fopen( "matrix2.out", "w" );
if( output == NULL ) {
printf( "Error: could not open matrix2.out\n" );
exit( EXIT_FAILURE );
}
print_matrix( output, c );
fclose( output );
destroy_matrix( a );
destroy_matrix( b );
destroy_matrix( c );
return 0;
}
示例2: main
void main()
{
int row1, column1, row2, column2;
int matrix1[100][100], matrix2[100][100], final_matrix[100][100];
printf("Enter number of rows and columns of matrix 1\n");
scanf_s("%d%d", &row1, &column1);
printf("Enter elements of matrix 1\n");
read_matrix(row1, column1, matrix1);
printf("Enter number of rows and columns of matrix 2\n");
scanf_s("%d%d", &row2, &column2);
if (column1 != row2)
printf("Matrices cannot be multiplied \n");
else
{
printf("Enter elements of matrix 2\n");
read_matrix(row2, column2, matrix2);
}
printf("Matrix 1 is as follows \n");
display_matrix(row1, column1, matrix1);
printf("Mtrix 2 is as follows \n");
display_matrix(row2, column2, matrix2);
multiply_matrix(row1, column1, matrix1, row2, column2, matrix2, final_matrix);
printf("Resultant Matrix is as follows \n");
display_matrix(row1, column2, final_matrix);
getchar();
getchar();
getchar();
}
示例3: printf
void *read_all()
{
printf("---!!! READ ALL THREAD START !!!---\n");
read_matrix(matrixa);
read_matrix(matrixb);
printf("---!!! READ ALL THREAD END !!!---\n");
sem_post(&mutex);
return 0;
}
示例4: load_data
// Read binary ROM data for basis functions and coefficients
static int load_data(const char dir[], gsl_vector *cvec_amp, gsl_vector *cvec_phi, gsl_matrix *Bamp, gsl_matrix *Bphi, gsl_vector *cvec_amp_pre) {
// Load binary data for amplitude and phase spline coefficients as computed in Mathematica
int ret = XLAL_SUCCESS;
ret |= read_vector(dir, "SEOBNRv1ROM_SS_Amp_ciall.dat", cvec_amp);
ret |= read_vector(dir, "SEOBNRv1ROM_SS_Phase_ciall.dat", cvec_phi);
ret |= read_matrix(dir, "SEOBNRv1ROM_SS_Bamp_bin.dat", Bamp);
ret |= read_matrix(dir, "SEOBNRv1ROM_SS_Bphase_bin.dat", Bphi);
ret |= read_vector(dir, "SEOBNRv1ROM_SS_AmpPrefac_ci.dat", cvec_amp_pre);
return(ret);
}
示例5: main
int main()
{
int N;
scanf("%d",&N);
int *matrix_a = (int *)malloc(N * N * sizeof(int));
int *matrix_b = (int *)malloc(N * N * sizeof(int));
int *matrix_c = (int *)malloc(N * N * sizeof(int));
read_matrix(matrix_a, N);
read_matrix(matrix_b, N);
multiply_matrix_3(matrix_a, matrix_b, matrix_c, N);
display_matrix(matrix_c, N);
}
示例6: fclib_read_local
/** read local problem;
* return problem on success; NULL on failure */
struct fclib_local* fclib_read_local (const char *path)
{
struct fclib_local *problem;
hid_t file_id, main_id, id;
if ((file_id = H5Fopen (path, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
{
fprintf (stderr, "ERROR: opening file failed\n");
return NULL;
}
if (!H5Lexists (file_id, "/fclib_local", H5P_DEFAULT))
{
fprintf (stderr, "ERROR: spurious input file %s :: fclib_local group does not exists", path);
return NULL;
}
MM (problem = calloc (1, sizeof (struct fclib_local)));
IO (main_id = H5Gopen (file_id, "/fclib_local", H5P_DEFAULT));
IO (H5LTread_dataset_int (file_id, "/fclib_local/spacedim", &problem->spacedim));
IO (id = H5Gopen (file_id, "/fclib_local/W", H5P_DEFAULT));
problem->W = read_matrix (id);
IO (H5Gclose (id));
if (H5Lexists (file_id, "/fclib_local/V", H5P_DEFAULT))
{
IO (id = H5Gopen (file_id, "/fclib_local/V", H5P_DEFAULT));
problem->V = read_matrix (id);
IO (H5Gclose (id));
IO (id = H5Gopen (file_id, "/fclib_local/R", H5P_DEFAULT));
problem->R = read_matrix (id);
IO (H5Gclose (id));
}
IO (id = H5Gopen (file_id, "/fclib_local/vectors", H5P_DEFAULT));
read_local_vectors (id, problem);
IO (H5Gclose (id));
if (H5Lexists (file_id, "/fclib_local/info", H5P_DEFAULT))
{
IO (id = H5Gopen (file_id, "/fclib_local/info", H5P_DEFAULT));
problem->info = read_problem_info (id);
IO (H5Gclose (id));
}
IO (H5Gclose (main_id));
IO (H5Fclose (file_id));
return problem;
}
示例7: main
int main(void) {
matrix a,b,c;
printf("enter first matrix\n");
read_matrix(&a);
print_matrix(&a);
printf("enter second matrix\n");
read_matrix(&b);
print_matrix(&b);
printf("matrix product\n");
multiply(&a, &b, &c);
print_matrix(&c);
return 0;
}
示例8: main
int main(int argc, char ** argv){
matrix * matrix_a;
matrix * matrix_b;
int thread_count = 0;
// if(argc != 7){
// fprintf(stderr, "%s", "Not enough arguments");
// exit(-1);
// }
for(int i = 1; i < argc; i ++){
if(strcmp(argv[i],"-a") == 0){
matrix_a = read_matrix(argv[i+1]);
}
if(strcmp(argv[i],"-b") == 0){
matrix_b = read_matrix(argv[i+1]);
}
if(strcmp(argv[i],"-t") == 0){
thread_count = atoi(argv[i+1]);
}
}
if(matrix_a->cols != matrix_b->rows){
fprintf(stderr, "%s", "a and b not computable");
exit(-1);
}
printf("Read ready, start computing");
pthread_t thread_id;
int err;
in_arg * arg = (in_arg *)malloc(sizeof(in_arg));
out_arg * result = (out_arg *)malloc(sizeof(out_arg));
arg->a = matrix_a;
arg->b = matrix_b;
arg->from_row = 0;
arg->to_row = matrix_a->rows - 1;
err = pthread_create(&thread_id, NULL, compute_thread, (void*)arg);
err = pthread_join(thread_id, (void**)result);
// double * result_matrix = (double *)malloc(matrix_a->rows * matrix_b->cols * sizeof(double));
// for(int i = 0 ; i < matrix_a->rows; i++){
// double *one_strip = compute_strip(matrix_a,matrix_b,i);
// for(int j = 0 ; j < matrix_a->cols; j++){
// result_matrix[i * matrix_b->cols + j] = one_strip[j];
// }
// free(one_strip);
// }
for(int i = 0 ; i < matrix_a->rows * matrix_b->cols; i ++){
printf("%f ",result->result[i]);
if(i % matrix_b->cols == matrix_b->cols-1)
printf("\n");
}
}
示例9: Call_Inverse
void Call_Inverse( int n)
{
POLY ds;
POLY M1[n][n], t_M1[n][n], product[n][n];
int k;
printf("Please choose the test matrix: ");
printf("1 random matrix.\n");
printf("2 input your own matrix.\n");
scanf("%d", &k ); printf("%d\n", k);
if(k==1) random_matrix ( n, n, M1);
if(k==2) read_matrix( n, n, M1 );
printf("the original matrix generated :\n");
print( n, n, M1);
copy(n, n, M1, t_M1);
ds = Inverse_Poly ( n, M1 );
printf(" The inverse matrix of the matrix is :\n" );
print(n, n, M1 );
printf(" The polynomial ds is :\n" );
Print_Poly( ds.d, ds.p );
printf("The product (without ds) of the original matrix");
printf(" and the inverse matrix is:\n");
Multiply(n, n, n, M1, t_M1, product);
print(n, n, product);
free_matrix(n, n, M1);
free_matrix(n, n, t_M1);
free_matrix(n, n, product);
}
示例10: main
main ()
{
int n;
MATRIX (A, MAX*MAX, MAX, MAX)
read_matrix (A);
if (DIM(A,0) != DIM(A,1))
{
printf ("La matrice doit etre carree\n");
return;
}
n = DIM(A,0);
MATRIX (B, MAX*MAX, n, n)
printf ("Inversion de la matrice : ");
print_matrix (A);
pivot (A, B);
printf ("Matrice inverse : ");
print_matrix (B);
ENDMAT ENDMAT
}
示例11: stripBlankEnds
bool SimGPS::OnStartUp()
{
list<string> sParams;
m_MissionReader.EnableVerbatimQuoting(false);
if(m_MissionReader.GetConfiguration(GetAppName(), sParams)) {
list<string>::iterator p;
for(p=sParams.begin(); p!=sParams.end(); p++) {
string original_line = *p;
string param = stripBlankEnds(toupper(biteString(*p, '=')));
string value = stripBlankEnds(*p);
if(param == "GPS_COVARIANCE") {
GPS_covariance = read_matrix(value);
}
if(param == "MAX_DEPTH"){
max_depth = atof(value.c_str());
}
if(param == "ADD_NOISE"){
add_noise = (tolower(value) == "true");
}
if(param == "BACKGROUND_MODE"){
if (tolower(value) == "true")
in_prefix = "NAV";
else
in_prefix = "SIM";
}
}
}
distribution = normal_distribution<double>(0.0,sqrt(GPS_covariance(0,0)));
RegisterVariables();
return(true);
}
示例12: main
int main(int argc, char *argv[])
{
double* matA = _mm_malloc(WIDTH*HEIGHT*sizeof(double), 64);
double* matB = _mm_malloc((WIDTH*HEIGHT)*sizeof(double), 64);
double* prod = _mm_malloc(WIDTH*HEIGHT*sizeof(double), 64);
double* prod_ref = _mm_malloc(WIDTH*HEIGHT*sizeof(double), 64);
int read_flag = read_matrix(TEST_FILENAME, prod_ref, matA, matB);
if (read_flag == 1)
printf("Cannot open test file\n");
else if (read_flag == 2)
printf("Error while reading data from test file");
else if (read_flag == 3)
printf("Error while closing the test file");
if (read_flag)
return 0;
uint64_t start = timestamp_us();
matmul_optimize(prod, matA, matB); /* run the optimization functions. */
uint64_t time = timestamp_us() - start;
if (compare_matrix(prod, prod_ref)) {
printf("%lu incorrect\n", time);
} else {
printf("%lu\n", time);
}
_mm_free(prod_ref);
_mm_free(prod);
_mm_free(matB);
_mm_free(matA);
return 0;
}
示例13: main
int main () {
// read two N x N matrices
read_matrix (X);
read_matrix (Y);
// multiply the matrices
matrix_multiply (X, Y, Z);
// output the resulting matrix
print_matrix (Z);
return 0;
}
示例14: zbuildshadingpattern
/* <pattern> <matrix> <shading> .buildshadingpattern <pattern> <instance> */
static int
zbuildshadingpattern(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
os_ptr op2 = op - 2;
gs_matrix mat;
gs_pattern2_template_t templat;
int_pattern *pdata;
gs_client_color cc_instance;
int code;
check_type(*op2, t_dictionary);
check_dict_read(*op2);
gs_pattern2_init(&templat);
if ((code = read_matrix(imemory, op - 1, &mat)) < 0 ||
(code = dict_uid_param(op2, &templat.uid, 1, imemory, i_ctx_p)) != 1 ||
(code = shading_param(op, &templat.Shading)) < 0 ||
(code = int_pattern_alloc(&pdata, op2, imemory)) < 0
)
return_error((code < 0 ? code : gs_error_rangecheck));
templat.client_data = pdata;
code = gs_make_pattern(&cc_instance,
(const gs_pattern_template_t *)&templat,
&mat, igs, imemory);
if (code < 0) {
ifree_object(pdata, "int_pattern");
return code;
}
make_istruct(op - 1, a_readonly, cc_instance.pattern);
pop(1);
return code;
}
示例15: get_proxy
int get_proxy(char * proxypath,char sep){
/* int i=8; */
/* fprintf(stderr,"in mcmc AS[%d]=%d\n",i,23); */
int ff;
char fff[20];
int midx = 0;
fprintf(stderr,"MODE in sir %d\n",MODE);
ADJL = (double ***)calloc((lastPROXY-firstPROXY+1), sizeof(double**));
for (ff = firstPROXY; ff <= lastPROXY; ff++){
/* fprintf(stderr,"proxy numero %d\n",ff); */
char * file = (char *)calloc(1000,sizeof(char));
file = strcat(file,proxypath);
/* fprintf(stderr,"proxy file %s\n",file); */
if((MODE == 2)||(MODE==3))
file = strcat(file,"/Adj_");
if((MODE == 0)||(MODE==1))
file = strcat(file,"/Adj_");
sprintf(fff,"%d",ff);
//if((MODE == 2)||(MODE==3)){
//sprintf(fff,"%d",0); //// PRENDOLASOMMATOTALE!!! 0
// sprintf(fff,"%s","0binary"); //// PRENDOLASOMMATOTALE BINARIZZATA!!! 0binary
//}
file = strcat(file,fff);
/* fprintf(stderr,"proxy file %s\n",file); */
ADJL[midx] = (double **) calloc ((N+1), sizeof(double*));
read_matrix(ADJL[midx], file, midx, sep);
midx++;
/* fprintf(stderr,"proxy dopo numero %d\n",midx); */
free(file);
}
return 0;
}