void append_const(double const_to_add) { int r_num = m_feat.rowNum()+1, c_num = m_feat.colNum(); m_feat.resize(r_num, c_num); int col; for (col = 0; col < c_num; ++col) { AzIFarr ifa; m_feat.col(col)->nonZero(&ifa); ifa.put(r_num-1, const_to_add); m_feat.col_u(col)->load(&ifa); } }
/*-------------------------------------------------------------------------*/ void AzPrepText2::gen_X_seq(const AzIntArr &ia_tokno, int dic_sz, int pch_sz, int pch_step, int padding, bool do_allow_zero, bool do_skip_stopunk, /*--- output ---*/ AzSmat *m_feat, AzIntArr *ia_pos) const /* patch position: may be NULL */ { const char *eyec = "AzPrepText2::gen_X_seq"; AzX::throw_if_null(m_feat, eyec, "m_feat"); AzX::no_support(do_skip_stopunk, eyec, "variable strides with Seq"); int t_num; const int *tokno = ia_tokno.point(&t_num); int pch_num = DIVUP(t_num+padding*2-pch_sz, pch_step) + 1; m_feat->reform(dic_sz*pch_sz, pch_num); if (ia_pos != NULL) ia_pos->reset(); int col = 0; int tx0 = -padding; for (int pch_no = 0; pch_no < pch_num; ++pch_no) { int tx1 = tx0 + pch_sz; AzSmat m; for (int tx = tx0; tx < tx1; ++tx) { AzSmat m0(dic_sz, 1); if (tx >= 0 && tx < t_num && tokno[tx] >= 0) { AzIntArr ia_row; ia_row.put(tokno[tx]); m0.col_u(0)->load(&ia_row, 1); } if (tx == tx0) m.set(&m0); else m.rbind(&m0); } if (do_allow_zero || !m.isZero()) { m_feat->col_u(col)->set(m.col(0)); if (ia_pos != NULL) ia_pos->put(tx0); ++col; } if (tx1 >= t_num+padding) break; tx0 += pch_step; } m_feat->resize(col); }
inline void add_to(AzDvect *v_dst, int col, double coeff) const { if (md != NULL) v_dst->add(md->col(col), coeff); /* dst += md[,col]*coeff */ else if (ms != NULL) v_dst->add(ms->col(col), coeff); else throw new AzException("AzDSmat::add", "No data"); }