#include <oct.h>

Go to the source code of this file.
Functions | |
| double * | oct_GetPr (octave_value arg) |
| double * | oct_GetPi (octave_value arg) |
| double * | oct_GetSparsePr (octave_value arg) |
| double * | oct_GetSparsePi (octave_value arg) |
| int * | oct_GetSparseIr (octave_value arg) |
| int * | oct_GetSparseJc (octave_value arg) |
| int | convert_octave_arguments (gs_problem_t *pd, octave_value_list oct_args) |
| int | convert_matrix (gs_argument_t *argp, octave_value_list octval, int i) |
| int | convert_sparse_matrix (gs_problem_t *pd, gs_argument_t *argp, octave_value_list octval, int i) |
| int | convert_vector (gs_argument_t *argp, octave_value_list octval, int i) |
| int | convert_scalar (gs_argument_t *argp, octave_value_list octval, int i) |
| int | convert_file_argument (gs_argument_t *argp, octave_value_list octval, int index) |
| int | convert_packed_file_argument (gs_argument_t *argp, octave_value_list octval, int index) |
| int | process_gs_out_arguments (gs_problem_t *pd) |
| int | convert_output_objects (gs_problem_t *pd, octave_value_list &retvals) |
| int | fill_matrix (gs_argument_t *argp, octave_value_list &retval) |
| int | fill_sparse_matrix (gs_problem_t *pd, gs_argument_t *argp, octave_value_list &retval) |
| int | fill_vector (gs_argument_t *argp, octave_value_list &retval) |
| int | fill_scalar (gs_argument_t *argp, octave_value_list &retval) |
| int | fill_file_argument (gs_argument_t *argp, octave_value_list &retval) |
| int | fill_packed_file_argument (gs_argument_t *argp, octave_value_list &retval) |
| int | verify_allocation (void *ptr) |
| int | sparsematrix_octcsc_to_gscsr (int m, int n, int nnz, int datatype, double *a, double *ai, int *colind, int *rowptr, void *at, int *rowind, int *colptr) |
| int convert_file_argument | ( | gs_argument_t * | argp, | |
| octave_value_list | octval, | |||
| int | index | |||
| ) |
Definition at line 550 of file oct_object_convert.cpp.
{
if (!octval(index).is_string()) {
fprintf(stderr, "Input argument %d should be a file name (string)\n");
return -1;
}
int nrows = octval(index).rows();
int ncolumns = octval(index).columns();
char *fname = (char *) malloc(gs_datatype_sizeof(
argp->datatype) * (nrows * ncolumns + 1));
if (verify_allocation(fname) < 0) return -1;
for (int j = 0; j < ncolumns; j++) {
for (int i = 0; i < nrows; i++) {
fname[i + j * nrows] = (char) (octval(index).char_matrix_value())(i, j);
}
}
fname[nrows * ncolumns] = '\0';
argp->data = fname;
return 0;
}


| int convert_matrix | ( | gs_argument_t * | argp, | |
| octave_value_list | octval, | |||
| int | i | |||
| ) |
Definition at line 213 of file oct_object_convert.cpp.
{
int nrows, ncolumns;
double *pr, *pi;
int *imat;
float *fmat;
double *dmat;
gs_scomplex *scmat;
gs_dcomplex *dcmat;
char *cmat;
nrows = octval(index).rows();
ncolumns = octval(index).columns();
if (argp->datatype == GS_CHAR) {
if (!octval(index).is_string()) {
fprintf(stderr, "Input argument %d should be a string\n", index);
return -1;
}
cmat = (char *) malloc(gs_datatype_sizeof(
argp->datatype) * (nrows * ncolumns + 1));
if (verify_allocation(cmat) < 0) return -1;
for (int j = 0; j < ncolumns; j++) {
for (int i = 0; i < nrows; i++) {
cmat[i + j * nrows] = (char) (octval(index).char_matrix_value())(i, j);
}
}
cmat[nrows * ncolumns] = '\0';
argp->data = cmat;
return 0;
} else {
pr = oct_GetPr(octval(index));
pi = oct_GetPi(octval(index));
}
switch (argp->datatype) {
case GS_INT:
imat = (int *) malloc(gs_datatype_sizeof(argp->datatype) * nrows * ncolumns);
if (verify_allocation(imat) < 0) return -1;
for (int i = 0; i < nrows * ncolumns; i++) {
imat[i] = (int) pr[i];
}
argp->data = imat;
break;
case GS_FLOAT:
fmat = (float *) malloc(gs_datatype_sizeof(argp->datatype) * nrows * ncolumns);
if (verify_allocation(fmat) < 0) return -1;
for (int i = 0; i < nrows * ncolumns; i++) {
fmat[i] = (float) pr[i];
}
argp->data = fmat;
break;
case GS_DOUBLE:
dmat = (double *) malloc(gs_datatype_sizeof(argp->datatype) * nrows * ncolumns);
if (verify_allocation(dmat) < 0) return -1;
for (int i = 0; i < nrows * ncolumns; i++) {
dmat[i] = pr[i];
}
argp->data = dmat;
break;
case GS_SCOMPLEX:
scmat = (gs_scomplex *) malloc(gs_datatype_sizeof(argp->datatype) * nrows * ncolumns);
if (verify_allocation(scmat) < 0) return -1;
for (int i = 0; i < nrows * ncolumns; i++) {
scmat[i].r = (float) pr[i];
scmat[i].i = (float) pi[i];
}
argp->data = scmat;
break;
case GS_DCOMPLEX:
dcmat = (gs_dcomplex *) malloc(gs_datatype_sizeof(argp->datatype) * nrows * ncolumns);
if (verify_allocation(dcmat) < 0) return -1;
for (int i = 0; i < nrows * ncolumns; i++) {
dcmat[i].r = pr[i];
dcmat[i].i = pi[i];
}
argp->data = dcmat;
break;
case GS_CHAR:
break;
case GS_BAD_DTYPE:
break;
}
return 0;
}


| int convert_octave_arguments | ( | gs_problem_t * | pd, | |
| octave_value_list | oct_args | |||
| ) |
Definition at line 147 of file oct_object_convert.cpp.
{
gs_argument_t *argp;
int i = 1;
//first process scalar input arguments
for (argp = pd->arglist; argp != NULL; argp = argp->next) {
if (argp->inout == GS_OUT ||
argp->inout == GS_VAROUT ||
argp->inout == GS_WORKSPACE) continue;
if (is_sparse_index_or_pointer(argp, pd)) continue;
if (argp->objecttype == GS_SCALAR) {
if (convert_scalar(argp, oct_args, i) < 0) return -1;
}
i++;
}
//compute the size of each nonscalar input arguments
if (gs_receiver_compute_arg_sizes(pd, GS_IN) < 0) {
fprintf(stderr, "Failure to compute argument sizes\n");
return -1;
}
i = 1;
//then process nonscalar input arguments
for (argp = pd->arglist; argp != NULL; argp = argp->next) {
if (argp->inout == GS_OUT ||
argp->inout == GS_VAROUT ||
argp->inout == GS_WORKSPACE) continue;
if (is_sparse_index_or_pointer(argp, pd)) {
continue;
}
switch (argp->objecttype) {
case GS_MATRIX:
if (convert_matrix(argp, oct_args, i) < 0) return -1;
break;
case GS_SPARSEMATRIX:
if (convert_sparse_matrix(pd, argp, oct_args, i) < 0) return -1;
break;
case GS_VECTOR:
if (convert_vector(argp, oct_args, i) < 0) return -1;
break;
case GS_SCALAR:
//Nothing to do here
break;
case GS_FILE:
if (convert_file_argument(argp, oct_args, i) < 0) return -1;
break;
case GS_PACKEDFILE:
if (convert_packed_file_argument(argp, oct_args, i) < 0) return -1;
break;
default:
break;
}
i++;
}
//last, process GS_OUT arguments
process_gs_out_arguments(pd);
}


| int convert_output_objects | ( | gs_problem_t * | pd, | |
| octave_value_list & | retvals | |||
| ) |
Definition at line 606 of file oct_object_convert.cpp.
{
gs_argument_t *argp;
for (argp = pd->arglist; argp != NULL; argp = argp->next) {
//for input or workspace arguments, do nothing
if (argp->inout == GS_IN || argp->inout == GS_WORKSPACE) continue;
if (is_sparse_index_or_pointer(argp, pd)) continue;
switch (argp->objecttype) {
case GS_MATRIX:
if (fill_matrix(argp, retvals) < 0) return -1;
break;
case GS_SPARSEMATRIX:
if (fill_sparse_matrix(pd, argp, retvals) < 0) return -1;
break;
case GS_VECTOR:
if (fill_vector(argp, retvals) < 0) return -1;
break;
case GS_SCALAR:
if (fill_scalar(argp, retvals) < 0) return -1;
break;
case GS_FILE:
if (fill_file_argument(argp, retvals) < 0) return -1;
break;
case GS_PACKEDFILE:
if (fill_packed_file_argument(argp, retvals) < 0) return -1;
break;
default:
break;
}
}
}


| int convert_packed_file_argument | ( | gs_argument_t * | argp, | |
| octave_value_list | octval, | |||
| int | index | |||
| ) |
Definition at line 575 of file oct_object_convert.cpp.
{
if (!octval(index).is_string()) {
fprintf(stderr, "Input argument %d should be a file name (string)\n");
return -1;
}
int nrows = octval(index).rows();
int ncolumns = octval(index).columns();
if (nrows != argp->rows) {
fprintf(stderr, "Bad string vector dimension for input packed file names\n");
return -1;
}
char **fnames = (char **) malloc(sizeof(char *) * nrows);
if (verify_allocation(fnames) < 0) return -1;
for (int i = 0; i < nrows; i++) {
fnames[i] = (char *) malloc(sizeof(char) * (ncolumns + 1));
if (verify_allocation(fnames[i]) < 0) return -1;
for (int j = 0; j < ncolumns; j++) {
fnames[i][j] = (char) (octval(index).char_matrix_value())(i, j);
}
fnames[i][ncolumns] = '\0';
}
argp->data = fnames;
return 0;
}


| int convert_scalar | ( | gs_argument_t * | argp, | |
| octave_value_list | octval, | |||
| int | i | |||
| ) |
Definition at line 498 of file oct_object_convert.cpp.
{
int nrows, ncolumns;
double *pr, *pi;
nrows = octval(index).rows();
ncolumns = octval(index).columns();
if (nrows != 1 || ncolumns != 1) {
printf("Input argument %d should be a scalar\n", index);
return -1;
}
if (argp->datatype == GS_CHAR) {
argp->scalar_val.char_val = (char) (octval(index).string_value())[0];
argp->data = &(argp->scalar_val);
return 0;
} else {
pr = oct_GetPr(octval(index));
pi = oct_GetPi(octval(index));
}
switch (argp->datatype) {
case GS_INT:
argp->scalar_val.int_val = (int) pr[0];
break;
case GS_FLOAT:
argp->scalar_val.float_val = (float) pr[0];
break;
case GS_DOUBLE:
argp->scalar_val.double_val = pr[0];
break;
case GS_SCOMPLEX:
argp->scalar_val.scomplex_val.r = (float) pr[0];
argp->scalar_val.scomplex_val.i = (float) pi[0];
break;
case GS_DCOMPLEX:
argp->scalar_val.dcomplex_val.r = pr[0];
argp->scalar_val.dcomplex_val.i = pi[0];
break;
case GS_CHAR:
break;
case GS_BAD_DTYPE:
break;
}
argp->data = &(argp->scalar_val);
return 0;
}


| int convert_sparse_matrix | ( | gs_problem_t * | pd, | |
| gs_argument_t * | argp, | |||
| octave_value_list | octval, | |||
| int | i | |||
| ) |
Definition at line 302 of file oct_object_convert.cpp.
{
gs_argument_t *arg_indices;
gs_argument_t *arg_pointer;
int nrows, ncolumns, nnz;
int *ir, *jc;
double *pr, *pi;
int *imat;
float *fmat;
double *dmat;
gs_scomplex *scmat;
gs_dcomplex *dcmat;
char *cmat;
nrows = octval(index).rows();
ncolumns = octval(index).columns();
if (argp->datatype == GS_CHAR) {
if (!octval(index).is_string()) {
fprintf(stderr, "Input argument %d should be a string\n", index);
return -1;
}
cmat = (char *) malloc(gs_datatype_sizeof(
argp->datatype) * (nrows * ncolumns + 1));
if (verify_allocation(cmat) < 0) return -1;
for (int j = 0; j < ncolumns; j++) {
for (int i = 0; i < nrows; i++) {
cmat[i + j * nrows] = (char) (octval(index).char_matrix_value())(i, j);
}
}
cmat[nrows * ncolumns] = '\0';
argp->data = cmat;
return 0;
} else {
ir = oct_GetSparseIr(octval(index).matrix_value());
jc = oct_GetSparseJc(octval(index).matrix_value());
nnz = *(jc + ncolumns);
pr = oct_GetSparsePr(octval(index).matrix_value());
pi = oct_GetSparsePi(octval(index).matrix_value());
}
arg_indices = gs_arg_lookup_by_name(argp->sparse_attr.indices, pd->arglist);
arg_pointer = gs_arg_lookup_by_name(argp->sparse_attr.pointer, pd->arglist);
if (arg_indices == NULL || arg_pointer == NULL) return -1;
arg_indices->data = ir;
arg_pointer->data = jc;
switch (argp->datatype) {
case GS_INT:
imat = (int *) malloc(gs_datatype_sizeof(argp->datatype) * nnz);
if (verify_allocation(imat) < 0) return -1;
for (int i = 0; i < nnz; i++) {
imat[i] = (int) pr[i];
}
argp->data = imat;
break;
case GS_FLOAT:
fmat = (float *) malloc(gs_datatype_sizeof(argp->datatype) * nnz);
if (verify_allocation(fmat) < 0) return -1;
for (int i = 0; i < nnz; i++) {
fmat[i] = (float) pr[i];
}
argp->data = fmat;
break;
case GS_DOUBLE:
dmat = (double *) malloc(gs_datatype_sizeof(argp->datatype) * nnz);
if (verify_allocation(dmat) < 0) return -1;
for (int i = 0; i < nnz; i++) {
dmat[i] = pr[i];
}
argp->data = dmat;
break;
case GS_SCOMPLEX:
scmat = (gs_scomplex *) malloc(gs_datatype_sizeof(argp->datatype) * nnz);
if (verify_allocation(scmat) < 0) return -1;
for (int i = 0; i < nnz; i++) {
scmat[i].r = (float) pr[i];
scmat[i].i = (float) pi[i];
}
argp->data = scmat;
break;
case GS_DCOMPLEX:
dcmat = (gs_dcomplex *) malloc(gs_datatype_sizeof(argp->datatype) * nnz);
if (verify_allocation(dcmat) < 0) return -1;
for (int i = 0; i < nnz; i++) {
dcmat[i].r = pr[i];
dcmat[i].i = pi[i];
}
argp->data = dcmat;
break;
case GS_CHAR:
break;
case GS_BAD_DTYPE:
break;
}
return 0;
}


| int convert_vector | ( | gs_argument_t * | argp, | |
| octave_value_list | octval, | |||
| int | i | |||
| ) |
Definition at line 404 of file oct_object_convert.cpp.
{
int nrows, ncolumns, nelems;
double *pr, *pi;
int *ivec;
float *fvec;
double *dvec;
gs_scomplex *scvec;
gs_dcomplex *dcvec;
char *cvec;
nrows = octval(index).rows();
ncolumns = octval(index).columns();
if (nrows != 1 && ncolumns != 1) {
printf("Input argument %d should be a vector (1xN or Nx1)\n", index);
return -1;
}
nelems = (nrows == 1) ? ncolumns : nrows;
if (argp->datatype == GS_CHAR) {
if (!octval(index).is_string()) {
fprintf(stderr, "Input argument %d should be a string\n", index);
return -1;
}
cvec = (char *) malloc(gs_datatype_sizeof(
argp->datatype) * (nelems + 1));
if (verify_allocation(cvec) < 0) return -1;
for (int i = 0; i < nelems; i++) {
cvec[i] = (char) (octval(index).string_value())[i];
}
cvec[nelems] = '\0';
argp->data = cvec;
return 0;
} else {
pr = oct_GetPr(octval(index));
pi = oct_GetPi(octval(index));
}
switch (argp->datatype) {
case GS_INT:
ivec = (int *) malloc(gs_datatype_sizeof(argp->datatype) * nelems);
if (verify_allocation(ivec) < 0) return -1;
for (int i = 0; i < nelems; i++) {
ivec[i] = (int) pr[i];
}
argp->data = ivec;
break;
case GS_FLOAT:
fvec = (float *) malloc(gs_datatype_sizeof(argp->datatype) * nelems);
if (verify_allocation(fvec) < 0) return -1;
for (int i = 0; i < nelems; i++) {
fvec[i] = (float) pr[i];
}
argp->data = fvec;
break;
case GS_DOUBLE:
dvec = (double *) malloc(gs_datatype_sizeof(argp->datatype) * nelems);
if (verify_allocation(dvec) < 0) return -1;
for (int i = 0; i < nelems; i++) {
dvec[i] = pr[i];
}
argp->data = dvec;
break;
case GS_SCOMPLEX:
scvec = (gs_scomplex *) malloc(gs_datatype_sizeof(argp->datatype) * nelems);
if (verify_allocation(scvec) < 0) return -1;
for (int i = 0; i < nelems; i++) {
scvec[i].r = (float) pr[i];
scvec[i].i = (float) pi[i];
}
argp->data = scvec;
break;
case GS_DCOMPLEX:
dcvec = (gs_dcomplex *) malloc(gs_datatype_sizeof(argp->datatype) * nelems);
if (verify_allocation(dcvec) < 0) return -1;
for (int i = 0; i < nelems; i++) {
dcvec[i].r = pr[i];
dcvec[i].i = pi[i];
}
argp->data = dcvec;
break;
case GS_CHAR:
break;
case GS_BAD_DTYPE:
break;
}
return 0;
}


| int fill_file_argument | ( | gs_argument_t * | argp, | |
| octave_value_list & | retval | |||
| ) |
Definition at line 1011 of file oct_object_convert.cpp.
{
char *str = strdup((char *) argp->data);
retval.append(string_vector(str));
free(argp->data);
return 0;
}

| int fill_matrix | ( | gs_argument_t * | argp, | |
| octave_value_list & | retval | |||
| ) |
Definition at line 640 of file oct_object_convert.cpp.
{
int nrows, ncolumns;
nrows = argp->rows;
ncolumns = argp->cols;
Matrix mat = Matrix(nrows, ncolumns);
ComplexMatrix cmat = ComplexMatrix(nrows, ncolumns);
charMatrix chmat = charMatrix(nrows, ncolumns);
switch (argp->datatype) {
case GS_INT:
for (int i = 0; i < mat.columns(); i++) {
for (int j = 0; j < mat.rows(); j++) {
if (argp->inout == GS_VAROUT) {
mat(j, i) = (int) (*(int **) argp->data)[i * mat.rows() + j];
} else {
mat(j, i) = (int) ((int *) argp->data)[i * mat.rows() + j];
}
}
}
retval.append(octave_value(mat));
free(argp->data);
break;
case GS_FLOAT:
for (int i = 0; i < mat.columns(); i++) {
for (int j = 0; j < mat.rows(); j++) {
if (argp->inout == GS_VAROUT) {
mat(j, i) = (float) (*(float **) argp->data)[i * mat.rows() + j];
} else {
mat(j, i) = (float) ((float *) argp->data)[i * mat.rows() + j];
}
}
}
retval.append(octave_value(mat));
free(argp->data);
break;
case GS_DOUBLE:
for (int i = 0; i < mat.columns(); i++) {
for (int j = 0; j < mat.rows(); j++) {
if (argp->inout == GS_VAROUT) {
mat(j, i) = (double) (*(double **) argp->data)[i * mat.rows() + j];
} else {
mat(j, i) = (double) ((double *) argp->data)[i * mat.rows() + j];
}
}
}
retval.append(octave_value(mat));
free(argp->data);
break;
case GS_SCOMPLEX:
for (int i = 0; i < cmat.columns(); i++) {
for (int j = 0; j < cmat.rows(); j++) {
int index = i * cmat.rows() + j;
if (argp->inout == GS_VAROUT) {
cmat(j, i) = Complex((*(gs_scomplex **) argp->data)[index].r,
(*(gs_scomplex **) argp->data)[index].i);
} else {
cmat(j, i) = Complex(((gs_scomplex *) argp->data)[index].r,
((gs_scomplex *) argp->data)[index].i);
}
}
}
retval.append(octave_value(cmat));
free(argp->data);
break;
case GS_DCOMPLEX:
for (int i = 0; i < cmat.columns(); i++) {
for (int j = 0; j < cmat.rows(); j++) {
int index = i * cmat.rows() + j;
if (argp->inout == GS_VAROUT) {
cmat(j, i) = Complex((*(gs_dcomplex **) argp->data)[index].r,
(*(gs_dcomplex **) argp->data)[index].i);
} else {
cmat(j, i) = Complex(((gs_dcomplex *) argp->data)[index].r,
((gs_dcomplex *) argp->data)[index].i);
}
}
}
retval.append(octave_value(cmat));
free(argp->data);
break;
case GS_CHAR:
for (int i = 0; i < mat.columns(); i++) {
for (int j = 0; j < mat.rows(); j++) {
if (argp->inout == GS_VAROUT) {
mat(j, i) = (char) (*(char **) argp->data)[i * mat.rows() + j];
} else {
mat(j, i) = (char) ((char *) argp->data)[i * mat.rows() + j];
}
}
}
retval.append(octave_value(mat));
free(argp->data);
break;
case GS_BAD_DTYPE:
break;
}
return 0;
}

| int fill_packed_file_argument | ( | gs_argument_t * | argp, | |
| octave_value_list & | retval | |||
| ) |
Definition at line 1019 of file oct_object_convert.cpp.
{
int ncolumns = 0;
for (int i = 0; i < argp->rows; i++) {
if (strlen(((char **) argp->data)[i]) > ncolumns);
ncolumns = strlen(((char **) argp->data)[i]);
}
charMatrix ret_packed_file_names = charMatrix(argp->rows, ncolumns);
for (int i = 0; i < argp->rows; i++) {
char *str = strdup(((char **) argp->data)[i]);
for (int j = 0; j < strlen(str); j++)
ret_packed_file_names.insert(str + j, i, j);
free(((char **) argp->data)[i]);
}
free(argp->data);
retval.append(ret_packed_file_names);
return 0;
}

| int fill_scalar | ( | gs_argument_t * | argp, | |
| octave_value_list & | retval | |||
| ) |
Definition at line 972 of file oct_object_convert.cpp.
{
if (argp->rows != 1 || argp->cols != 1) return -1;
Matrix mat = Matrix(1, 1);
ComplexMatrix cmat = ComplexMatrix(1, 1);
charMatrix chmat = charMatrix(1, 1);
switch (argp->datatype) {
case GS_DOUBLE:
mat(0, 0) = argp->scalar_val.double_val;
retval.append(octave_value(mat));
break;
case GS_INT:
mat(0, 0) = argp->scalar_val.int_val;
retval.append(octave_value(mat));
break;
case GS_FLOAT:
mat(0, 0) = argp->scalar_val.float_val;
retval.append(octave_value(mat));
break;
case GS_SCOMPLEX:
cmat(0, 0) = Complex(argp->scalar_val.scomplex_val.r,
argp->scalar_val.scomplex_val.i);
retval.append(octave_value(cmat));
break;
case GS_DCOMPLEX:
cmat(0, 0) = Complex(argp->scalar_val.dcomplex_val.r,
argp->scalar_val.dcomplex_val.i);
retval.append(octave_value(cmat));
break;
case GS_CHAR:
mat(0, 0) = (int) argp->scalar_val.char_val;
retval.append(octave_value(mat));
break;
}
return 0;
}

| int fill_sparse_matrix | ( | gs_problem_t * | pd, | |
| gs_argument_t * | argp, | |||
| octave_value_list & | retval | |||
| ) |
Definition at line 742 of file oct_object_convert.cpp.
{
gs_argument_t *arg_pointer;
gs_argument_t *arg_indices;
int nnz, nrows, ncolumns;
int *ir, *jc;
Matrix mat;
ComplexMatrix cmat;
charMatrix chmat;
nnz = argp->sparse_attr.nnz;
nrows = argp->sparse_attr.rows_val_saved;
ncolumns = argp->sparse_attr.cols_val_saved;;
arg_indices = gs_arg_lookup_by_name(argp->sparse_attr.indices, pd->arglist);
arg_pointer = gs_arg_lookup_by_name(argp->sparse_attr.pointer, pd->arglist);
if (arg_indices == NULL || arg_pointer == NULL) return -1;
ir = (int *) arg_indices->data;
jc = (int *) arg_pointer->data;
switch (argp->datatype) {
case GS_INT:
mat = Matrix(nrows, ncolumns);
for (int i = 0; i < nrows; i++)
for (int j = 0; j < ncolumns; j++)
mat(i, j) = 0;
for (int j; j < ncolumns; j++)
for( int k = *(jc + j); k < *(jc + j + 1); k++)
mat(*(ir + k), j) = (int) *((int *) argp->data + k);
retval.append(SparseMatrix(mat));
break;
case GS_FLOAT:
mat = Matrix(nrows, ncolumns);
for (int i = 0; i < nrows; i++)
for (int j = 0; j < ncolumns; j++)
mat(i, j) = 0.0;
for (int j; j < ncolumns; j++)
for( int k = *(jc + j); k < *(jc + j + 1); k++)
mat(*(ir + k), j) = (float) *((float *) argp->data + k);
retval.append(SparseMatrix(mat));
break;
case GS_DOUBLE:
mat = Matrix(nrows, ncolumns);
for (int i = 0; i < nrows; i++)
for (int j = 0; j < ncolumns; j++)
mat(i, j) = 0.00;
for (int j; j < ncolumns; j++)
for( int k = *(jc + j); k < *(jc + j + 1); k++)
mat(*(ir + k), j) = (double) *((double *) argp->data + k);
retval.append(SparseMatrix(mat));
break;
case GS_SCOMPLEX:
cmat = ComplexMatrix(nrows, ncolumns);
for (int i = 0; i < nrows; i++)
for (int j = 0; j < ncolumns; j++)
cmat(i, j) = 0;
for (int j; j < ncolumns; j++)
for( int k = *(jc + j); k < *(jc + j + 1); k++)
cmat(*(ir + k), j) = Complex(
((gs_scomplex) *((gs_scomplex *) argp->data + k)).r,
((gs_scomplex) *((gs_scomplex *) argp->data + k)).i);
retval.append(SparseComplexMatrix(cmat));
break;
case GS_DCOMPLEX:
cmat = ComplexMatrix(nrows, ncolumns);
for (int i = 0; i < nrows; i++)
for (int j = 0; j < ncolumns; j++)
cmat(i, j) = 0;
for (int j; j < ncolumns; j++)
for( int k = *(jc + j); k < *(jc + j + 1); k++)
cmat(*(ir + k), j) = Complex(
((gs_dcomplex) *((gs_dcomplex *) argp->data + k)).r,
((gs_dcomplex) *((gs_dcomplex *) argp->data + k)).i);
retval.append(SparseComplexMatrix(cmat));
break;
}
return 0;
}


| int fill_vector | ( | gs_argument_t * | argp, | |
| octave_value_list & | retval | |||
| ) |
Definition at line 832 of file oct_object_convert.cpp.
{
int nrows, ncolumns, nelems;
int major;
Matrix mat;
ComplexMatrix cmat;
charMatrix chmat;
nrows = argp->rows;
ncolumns = argp->cols;
if (nrows == 1) {
mat = Matrix(1, ncolumns);
cmat = ComplexMatrix(1, ncolumns);
chmat = charMatrix(1, ncolumns);
nelems = ncolumns;
major = 0;
}
else if (ncolumns == 1) {
mat = Matrix(nrows, 1);
cmat = ComplexMatrix(nrows, 1);
chmat = charMatrix(nrows, 1);
nelems = nrows;
major = 1;
}
switch (argp->datatype) {
case GS_INT:
for (int i = 0; i < nelems; i++) {
if (argp->inout == GS_VAROUT) {
if (major == 0)
mat(0, i) = (int) (*(int **) argp->data)[i];
else
mat(i, 0) = (int) (*(int **) argp->data)[i];
} else {
if (major == 0)
mat(0, i) = (int) ((int *) argp->data)[i];
else
mat(i, 0) = (int) ((int *) argp->data)[i];
}
}
free(argp->data);
retval.append(octave_value(mat));
break;
case GS_FLOAT:
for (int i = 0; i < nelems; i++) {
if (argp->inout == GS_VAROUT) {
if (major == 0)
mat(0, i) = (float) (*(float **) argp->data)[i];
else
mat(i, 0) = (float) (*(float **) argp->data)[i];
} else {
if (major == 0)
mat(0, i) = (float) ((float *) argp->data)[i];
else
mat(i, 0) = (float) ((float *) argp->data)[i];
}
}
free(argp->data);
retval.append(octave_value(mat));
break;
case GS_DOUBLE:
for (int i = 0; i < nelems; i++) {
if (argp->inout == GS_VAROUT) {
if (major == 0)
mat(0, i) = (double) (*(double **) argp->data)[i];
else
mat(i, 0) = (double) (*(double **) argp->data)[i];
} else {
if (major == 0)
mat(0, i) = (double) ((double *) argp->data)[i];
else
mat(i, 0) = (double) ((double *) argp->data)[i];
}
}
free(argp->data);
retval.append(octave_value(mat));
break;
case GS_SCOMPLEX:
for (int i = 0; i < nelems; i++) {
if (argp->inout == GS_VAROUT) {
if (major == 0)
cmat(0, i) = Complex((*(gs_scomplex **) argp->data)[i].r,
(*(gs_scomplex **) argp->data)[i].i);
else
cmat(i, 0) = Complex((*(gs_scomplex **) argp->data)[i].r,
(*(gs_scomplex **) argp->data)[i].i);
} else {
if (major == 0)
cmat(0, i) = Complex(((gs_scomplex *) argp->data)[i].r,
((gs_scomplex *) argp->data)[i].i);
else
cmat(i, 0) = Complex(((gs_scomplex *) argp->data)[i].r,
((gs_scomplex *) argp->data)[i].i);
}
}
free(argp->data);
retval.append(octave_value(cmat));
break;
case GS_DCOMPLEX:
for (int i = 0; i < nelems; i++) {
if (argp->inout == GS_VAROUT) {
if (major == 0)
cmat(0, i) = Complex((*(gs_dcomplex **) argp->data)[i].r,
(*(gs_dcomplex **) argp->data)[i].i);
else
cmat(i, 0) = Complex((*(gs_dcomplex **) argp->data)[i].r,
(*(gs_dcomplex **) argp->data)[i].i);
} else {
if (major == 0)
cmat(0, i) = Complex(((gs_dcomplex *) argp->data)[i].r,
((gs_dcomplex *) argp->data)[i].i);
else
cmat(i, 0) = Complex(((gs_dcomplex *) argp->data)[i].r,
((gs_dcomplex *) argp->data)[i].i);
}
}
free(argp->data);
retval.append(octave_value(cmat));
break;
case GS_CHAR:
if (argp->inout == GS_VAROUT) {
char *str = strdup(*((char **) argp->data));
retval.append(string_vector(str));
free(*((char **) argp->data));
free(argp->data);
} else {
char *str = strdup((char *) argp->data);
retval.append(string_vector(str));
free(argp->data);
}
break;
case GS_BAD_DTYPE:
break;
}
return 0;
}

| double* oct_GetPi | ( | octave_value | arg | ) |
Definition at line 23 of file oct_get_prpi.cpp.
{
double *pi;
int i, j;
if (arg.is_real_type()) {
pi = (double *) malloc(arg.rows() * arg.columns() * sizeof(double));
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
*(pi + i + (j * arg.rows())) = 0;
} else {
pi = (double *) malloc(arg.rows() * arg.columns() * sizeof(double));
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
*(pi + i + (j * arg.rows())) =
imag((arg.complex_matrix_value())(i, j));
}
return pi;
}

| double* oct_GetPr | ( | octave_value | arg | ) |
Definition at line 3 of file oct_get_prpi.cpp.
{
double *pr;
int i, j;
if (arg.is_real_type()) {
pr = (double *) malloc(arg.rows() * arg.columns() * sizeof(double));
for ( j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
*(pr + i + (j * arg.rows())) = (arg.matrix_value())(i, j);
} else {
pr = (double *) malloc(arg.rows() * arg.columns() * sizeof(double));
for (j = 0; j<arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
*(pr + i + (j * arg.rows())) =
real((arg.complex_matrix_value())(i, j));
}
return pr;
}

| int* oct_GetSparseIr | ( | octave_value | arg | ) |
Definition at line 129 of file oct_get_prpi.cpp.
{
int *Ir;
int i, j;
int count;
int index;
if (arg.is_real_type()) {
count = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((arg.matrix_value())(i, j) != 0) count++;
Ir = (int *) malloc(count * sizeof(int));
index = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((arg.matrix_value())(i, j) != 0) {
*(Ir + index) = i;
index++;
}
} else {
count = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i, j)) != 0) ||
(imag((arg.complex_matrix_value())(i, j)) != 0) )
count++;
Ir = (int *) malloc(count * sizeof(int));
index = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i, j)) != 0) ||
(imag((arg.complex_matrix_value())(i, j)) != 0)) {
*(Ir + index) = i;
index++;
}
}
return Ir;
}

| int* oct_GetSparseJc | ( | octave_value | arg | ) |
Definition at line 172 of file oct_get_prpi.cpp.
{
int *Jc;
int i, j;
int count;
Jc = (int *) malloc(arg.columns() * sizeof(int) + 1);
if (arg.is_real_type()) {
count = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((arg.matrix_value())(i, j) != 0 ) count++;
*(Jc + arg.columns()) = count;
count = 0;
for (j = 0; j < arg.columns(); j++) {
*(Jc + j) = count;
for (i = 0; i < arg.rows(); i++)
if ((arg.matrix_value())(i, j) != 0) count++;
}
} else {
count = 0;
for (j = 0;j<arg.columns();j++)
for (i = 0; i < arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i,j)) != 0) ||
(imag((arg.complex_matrix_value())(i,j)) != 0) )
count++;
*(Jc + arg.columns()) = count;
count = 0;
for (j = 0; j < arg.columns(); j++)
{
*(Jc + j) = count;
for (i = 0; i< arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i, j)) != 0) ||
(imag((arg.complex_matrix_value())(i, j)) != 0)) count++;
}
}
return Jc;
}

| double* oct_GetSparsePi | ( | octave_value | arg | ) |
Definition at line 86 of file oct_get_prpi.cpp.
{
double *pi;
int i, j;
int count;
int index;
if (arg.is_real_type()) {
count = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((arg.matrix_value())(i, j) != 0) count++;
pi = (double *) malloc(count * sizeof(double));
index = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i<arg.rows(); i++)
if ((arg.matrix_value())(i, j) != 0) {
*(pi + index) = 0;
index++;
}
} else {
count = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i, j)) != 0) ||
(imag((arg.complex_matrix_value())(i, j)) != 0))
count++;
pi = (double *) malloc(count*sizeof(double));
index = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i, j)) != 0) ||
(imag((arg.complex_matrix_value())(i, j)) != 0)) {
*(pi + index) = imag((arg.complex_matrix_value())(i, j));
index++;
}
}
return pi;
}

| double* oct_GetSparsePr | ( | octave_value | arg | ) |
Definition at line 43 of file oct_get_prpi.cpp.
{
double *pr;
int i, j;
int count;
int index;
if (arg.is_real_type()) {
count = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((arg.matrix_value())(i, j) != 0) count++;
pr = (double *) malloc(count * sizeof(double));
index = 0;
for (j = 0; j < arg.columns(); j++)
for(i = 0; i < arg.rows(); i++)
if( (arg.matrix_value())(i,j) != 0 ) {
*(pr + index) = (arg.matrix_value())(i, j);
index++;
}
} else {
count = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i, j)) != 0) ||
(imag((arg.complex_matrix_value())(i, j)) != 0) )
count++;
pr = (double *) malloc(count * sizeof(double));
index = 0;
for (j = 0; j < arg.columns(); j++)
for (i = 0; i < arg.rows(); i++)
if ((real((arg.complex_matrix_value())(i, j)) != 0) ||
(imag((arg.complex_matrix_value())(i, j)) != 0)) {
*(pr + index) = real((arg.complex_matrix_value())(i, j));
index++;
}
}
return pr;
}

| int process_gs_out_arguments | ( | gs_problem_t * | pd | ) |
Definition at line 48 of file oct_object_convert.cpp.
{
gs_argument_t *argp;
gs_argument_t *arg_indices;
gs_argument_t *arg_pointer;
void *v;
int nrows, ncolumns;
char buf[256];
int fd;
int nfiles;
char **fnames;
for (argp = pd->arglist; argp != NULL; argp = argp->next) {
if (argp->inout != GS_OUT && argp->inout != GS_VAROUT) continue;
if (is_sparse_index_or_pointer(argp, pd)) continue;
switch (argp->objecttype) {
case GS_MATRIX:
if (argp->inout == GS_OUT) {
nrows = argp->rows;
ncolumns = argp->cols;
argp->data = (void *) malloc(gs_datatype_sizeof(
argp->datatype) * nrows * ncolumns);
if (verify_allocation(argp->data) < 0) return -1;
}
else if (argp->inout == GS_VAROUT) {
argp->data = (char **) malloc(sizeof(char *));
}
break;
case GS_SPARSEMATRIX:
if (argp->inout == GS_VAROUT) {
fprintf(stderr, "VAROUT SPARSEMATRIX arguments are not supported\n");
return -1;
}
arg_indices = gs_arg_lookup_by_name(argp->sparse_attr.indices, pd->arglist);
arg_pointer = gs_arg_lookup_by_name(argp->sparse_attr.pointer, pd->arglist);
if (arg_indices == NULL || arg_pointer == NULL) return -1;
arg_indices->data = malloc(sizeof(int) * argp->sparse_attr.nnz);
if (verify_allocation(arg_indices->data) < 0) return -1;
arg_pointer->data = malloc(sizeof(int) *
(argp->sparse_attr.cols_val_saved + 1));
if (verify_allocation(arg_pointer->data) < 0) return -1;
argp->data = (void *) malloc(argp->sparse_attr.nnz *
gs_datatype_sizeof(argp->datatype));
if (verify_allocation(argp->data) < 0) return -1;
break;
case GS_VECTOR:
if (argp->inout == GS_OUT) {
nrows = argp->rows;
argp->data = (void *) malloc(gs_datatype_sizeof(argp->datatype) * nrows);
if (verify_allocation(argp->data) < 0) return -1;
}
else if (argp->inout == GS_VAROUT) {
argp->data = (char **) malloc(sizeof(char *));
}
break;
case GS_SCALAR:
if (argp->inout == GS_OUT) {
argp->data = &(argp->scalar_val);
}
else if (argp->inout == GS_VAROUT) {
fprintf(stderr, "VAROUT SCALAR arguments are not supported\n");
return -1;
}
break;
case GS_FILE:
sprintf(buf, "%s_%s_OUT", pd->name, argp->name);
fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if(fd < 0) {
fprintf(stderr, "Could not open file '%s'\n", buf);
return -1;
}
close(fd);
argp->data = strdup(buf);
if (argp->data == NULL) return -1;
break;
case GS_PACKEDFILE:
nfiles = argp->rows * argp->cols;
fnames = (char **) malloc(sizeof(char *) * nfiles);
for (int i = 0; i < nfiles; i++) {
sprintf(buf, "%s_%s_%d_OUT", pd->name, argp->name, i + 1);
fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if(fd < 0) {
fprintf(stderr, "Could not open file '%s'\n", buf);
return -1;
}
close(fd);
fnames[i] = strdup(buf);
if (fnames[i] == NULL) return -1;
}
argp->data = fnames;
break;
default:
break;
}
}
}


| int sparsematrix_octcsc_to_gscsr | ( | int | m, | |
| int | n, | |||
| int | nnz, | |||
| int | datatype, | |||
| double * | a, | |||
| double * | ai, | |||
| int * | colind, | |||
| int * | rowptr, | |||
| void * | at, | |||
| int * | rowind, | |||
| int * | colptr | |||
| ) |
Definition at line 5 of file oct_sparse.cpp.
{
int i, j, col, relpos;
int *marker;
marker = (int *) malloc(sizeof(int) * n);
if (marker == NULL) return -1;
/* Get counts of each column of A, and set up column pointers */
for (i = 0; i < m; ++i)
for (j = rowptr[i]; j < rowptr[i + 1]; ++j)
++marker[colind[j]];
colptr[0] = 0;
for (j = 0; j < n; ++j) {
colptr[j + 1] = colptr[j] + marker[j];
marker[j] = colptr[j];
}
/* Transfer the matrix into the compressed column storage. */
for (i = 0; i < m; ++i) {
for (j = rowptr[i]; j < rowptr[i + 1]; ++j) {
col = colind[j];
relpos = marker[col];
rowind[relpos] = i;
switch(datatype) {
case GS_INT:
((int *) at)[relpos] = (int) ((double *) a)[j];
break;
case GS_FLOAT:
((float *) at)[relpos] = (float) ((double *) a)[j];
break;
case GS_DOUBLE:
((double *) at)[relpos] = (double) ((double *) a)[j];
break;
case GS_SCOMPLEX:
((gs_scomplex *) at)[relpos].r = (float) ((double *) a)[j];
((gs_scomplex *) at)[relpos].i = (float) ((double *) ai)[j];
break;
case GS_DCOMPLEX:
/* ((dcomplex *)at)[relpos] = ((dcomplex *)a)[j]; */
((gs_dcomplex *) at)[relpos].r = (double) ((double *) a)[j];
((gs_dcomplex *) at)[relpos].i = (double) ((double *) ai)[j];
break;
default:
return -1;
break;
}
++marker[col];
}
}
return 0;
}
| int verify_allocation | ( | void * | ptr | ) |
Definition at line 22 of file oct_object_convert.cpp.
{
if (ptr == NULL) {
perror("malloc");
return -1;
}
return 0;
}

1.6.3-20100507