void CMatlabInterface::set_real(float64_t scalar) { mxArray* o=mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL); if (!o) SG_ERROR("Couldn't create Double.\n"); double* data=(double*) mxGetData(o); data[0]=scalar; set_arg_increment(o); }
void CMatlabInterface::set_bool(bool scalar) { mxArray* o=mxCreateLogicalMatrix(1, 1); if (!o) SG_ERROR("Couldn't create Logical.\n"); bool* data=(bool*) mxGetData(o); data[0]=scalar; set_arg_increment(o); }
void CMatlabInterface::set_int(int32_t scalar) { mxArray* o=mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL); if (!o) SG_ERROR("Couldn't create Integer.\n"); int* data=(int*) mxGetData(o); data[0]=scalar; set_arg_increment(o); }
//this function will fail for strings containing 0, unclear how to do 'raw' //strings in R void CRInterface::set_char_string_list(const TString<char>* strings, int32_t num_str) { if (!strings) SG_ERROR("Given strings are invalid.\n"); SEXP feat=NULL; PROTECT( feat = allocVector(STRSXP, num_str) ); for (int32_t i=0; i<num_str; i++) { int32_t len=strings[i].length; if (len>0) SET_STRING_ELT(feat, i, mkChar(strings[i].string)); } UNPROTECT(1); set_arg_increment(feat); }
void COctaveInterface::set_real_sparsematrix(const SGSparseVector<float64_t>* matrix, int32_t num_feat, int32_t num_vec, int64_t nnz) { SparseMatrix sm((octave_idx_type) num_feat, (octave_idx_type) num_vec, (octave_idx_type) nnz); int64_t offset=0; for (int32_t i=0; i<num_vec; i++) { int32_t len=matrix[i].num_feat_entries; sm.cidx(i)=offset; for (int32_t j=0; j<len; j++) { sm.data(offset) = matrix[i].features[j].entry; sm.ridx(offset) = matrix[i].features[j].feat_index; offset++; } } sm.cidx(num_vec) = offset; set_arg_increment(sm); }
void COctaveInterface::set_bool(bool scalar) { octave_value o(scalar); set_arg_increment(o); }
void COctaveInterface::set_real(float64_t scalar) { octave_value o(scalar); set_arg_increment(o); }
void COctaveInterface::set_int(int32_t scalar) { octave_value o(scalar); set_arg_increment(o); }
void CRInterface::set_bool(bool scalar) { set_arg_increment(ScalarLogical(scalar)); }
void CRInterface::set_real(float64_t scalar) { set_arg_increment(ScalarReal(scalar)); }
void CRInterface::set_int(int32_t scalar) { set_arg_increment(ScalarInteger(scalar)); }