SEXP initialize_hbhmat(SEXP F, SEXP window, SEXP wmask, SEXP fmask, SEXP weights, SEXP circular) { hbhankel_matrix *h; ext_matrix *e; SEXP hbhmat, N = NILSXP; PROTECT(N = getAttrib(F, R_DimSymbol)); /* Allocate memory */ e = Calloc(1, ext_matrix); e->type = "hbhankel matrix"; e->mulfn = hbhankel_matmul; e->tmulfn = hbhankel_tmatmul; e->ncol = hbhankel_ncol; e->nrow = hbhankel_nrow; /* Build toeplitz circulants for hankel matrix */ h = Calloc(1, hbhankel_matrix); initialize_circulant(h, REAL(F), length(N), INTEGER(N), INTEGER(window), LOGICAL(circular)); /* TODO: add a check for correct window sizes */ h->col_ind = alloc_area2d(wmask, N); h->row_ind = alloc_area2d(fmask, N); h->weights = alloc_weights(weights); e->matrix = h; /* We do not need to protect N anymore */ UNPROTECT(1); /* Make an external pointer envelope */ hbhmat = R_MakeExternalPtr(e, install("external matrix"), R_NilValue); R_RegisterCFinalizer(hbhmat, hbhmat_finalizer); return hbhmat; }
SEXP initialize_hbhmat(SEXP F, SEXP windowx, SEXP windowy) { R_len_t Nx, Ny, Lx, Ly; hbhankel_matrix *h; ext_matrix *e; SEXP hbhmat; int *dimF = INTEGER(getAttrib(F, R_DimSymbol)); Nx = dimF[0]; Ny = dimF[1]; Lx = INTEGER(windowx)[0]; Ly = INTEGER(windowy)[0]; /* Allocate memory */ e = Calloc(1, ext_matrix); e->type = "hbhankel matrix"; e->mulfn = hbhankel_matmul; e->tmulfn = hbhankel_tmatmul; e->ncol = hbhankel_ncol; e->nrow = hbhankel_nrow; /* Build toeplitz circulants for hankel matrix */ h = Calloc(1, hbhankel_matrix); initialize_circulant(h, REAL(F), Nx, Ny, Lx, Ly); e->matrix = h; /* Make an external pointer envelope */ hbhmat = R_MakeExternalPtr(e, install("external matrix"), R_NilValue); R_RegisterCFinalizer(hbhmat, hbhmat_finalizer); return hbhmat; }
SEXP initialize_hmat(SEXP F, SEXP window) { R_len_t N, L; hankel_matrix *h; ext_matrix *e; SEXP hmat; N = length(F); L = INTEGER(window)[0]; /* Allocate memory */ e = Calloc(1, ext_matrix); e->type = "hankel matrix"; e->mulfn = hankel_matmul; e->tmulfn = hankel_tmatmul; e->ncol = hankel_ncol; e->nrow = hankel_nrow; /* Build toeplitz circulants for hankel matrix */ h = Calloc(1, hankel_matrix); initialize_circulant(h, REAL(F), N, L); e->matrix = h; /* Make an external pointer envelope */ hmat = R_MakeExternalPtr(e, install("external matrix"), R_NilValue); R_RegisterCFinalizer(hmat, hmat_finalizer); return hmat; }