19#ifndef FPLLL_HOUSEHOLDER_H
20#define FPLLL_HOUSEHOLDER_H
72 enable_transform(arg_u.get_rows() > 0), u(arg_u),
73 enable_inverse_transform(arg_uinv_t.get_rows() > 0), u_inv_t(arg_uinv_t),
95 fill(row_expo.begin(), row_expo.end(), 0);
97 init_row_size.resize(d);
98 for (
int i = 0; i < d; i++)
100 init_row_size[i] = max(b[i].size_nz(), 1);
104 for (
int i = 0; i < d; i++)
106 R_history[i].resize(n);
107 for (
int j = 0; j < n; j++)
108 R_history[i][j].resize(n);
113 norm_square_b.resize(d);
114 expo_norm_square_b.resize(d);
117 fill(expo_norm_square_b.begin(), expo_norm_square_b.end(), 0);
119#ifdef HOUSEHOLDER_PRECOMPUTE_INVERSE
121 R_inverse_diag.resize(d);
126 tmp_col_expo.resize(n);
130 fill(col_kept.begin(), col_kept.end(),
false);
135 n_known_rows_naively = 0;
136 sigma_naively.resize(d);
139 row_expo_naively.resize(d);
140 fill(row_expo_naively.begin(), row_expo_naively.end(), 0);
143 for (
int i = 0; i < d; i++)
145 for (
int j = 0; j < n; j++)
148 V_naively(i, j).set_nan();
161 inline void get_R(FT &f,
int i,
int j,
long &expo);
168 inline void get_R(FT &f,
int i,
int j);
235 inline void norm_R_row(FT &f,
int k,
int beg,
int end,
long &expo);
240 bool size_reduce(
int k,
int size_reduction_end,
int size_reduction_start = 0);
247 void swap(
int i,
int j);
355 const bool enable_row_expo;
361 vector<long> row_expo;
364 vector<long> tmp_col_expo;
367 FT ftmp0, ftmp1, ftmp2, ftmp3;
371 vector<int> init_row_size;
384 void row_addmul_we(
int i,
int j,
const FT &x,
long expo_add);
388 void row_add(
int i,
int j);
389 void row_sub(
int i,
int j);
390 void row_addmul_si(
int i,
int j,
long x);
391 void row_addmul_si_2exp(
int i,
int j,
long x,
long expo);
392 void row_addmul_2exp(
int i,
int j,
const ZT &x,
long expo);
403 vector<vector<vector<FT>>> R_history;
409 vector<FT> R_inverse_diag;
412 const bool enable_transform;
421 const bool enable_inverse_transform;
429 const bool row_op_force_long;
432 vector<FT> norm_square_b;
434 vector<long> expo_norm_square_b;
438 vector<bool> col_kept;
485 vector<FT> sigma_naively;
491 vector<long> row_expo_naively;
496 int n_known_rows_naively;
499template <
class ZT,
class FT>
534 for (
int i = 0; i < d; i++)
538template <
class ZT,
class FT>
545 bf[k].dot_product(f, bf[k], 0, n_known_cols);
548 expo = 2 * row_expo[k];
553template <
class ZT,
class FT>
562 R[k].dot_product(f, R[k], beg, end);
565 expo = 2 * row_expo[k];
571template <
class ZT,
class FT>
580 R[k].dot_product(f, R[k], beg, end);
593 if (k < n_known_rows)
602 for (
int k = 0; k < i - 1; k++)
603 R(i, k) = R_history[i][k][k];
604 for (
int k = i - 1; k < n; k++)
605 R(i, k) = R_history[i][i - 1][k];
612 for (
int i = 0; i < d; i++)
618 for (
int i = 0; i < d; i++)
622template <
class ZT,
class FT>
626 expo = expo_norm_square_b[i];
627 f = norm_square_b[i];
634 for (
int i = 0; i < d; i++)
638template <
class ZT,
class FT>
643 expo = row_expo_naively[i];
646template <
class ZT,
class FT>
656 R_naively[k].dot_product(f, R_naively[k], 0, end);
659 expo = 2 * row_expo_naively[k];
664template <
class ZT,
class FT>
673 b[k].dot_product(ztmp0, b[k], 0, n);
674 ztmp0.get_f_exp(f, expo);
682 b[k].dot_product(ztmp0, b[k], 0, n);
Definition: householder.h:39
bool get_updated_R()
Definition: householder.h:262
void update_R()
Definition: householder.h:532
bool size_reduce(int k, int size_reduction_end, int size_reduction_start=0)
Definition: householder.cpp:403
FT get_R_inverse_diag(int i)
Definition: householder.h:272
const Matrix< FT > & get_R(vector< long > &expo)
Definition: householder.h:179
void get_R(FT &f, int i, int j, long &expo)
Definition: householder.h:500
void norm_R_row(FT &f, int k, int beg, int end, long &expo)
Definition: householder.h:572
void norm_square_R_row_naively(FT &f, int k, int end, long &expo)
Definition: householder.h:647
void norm_square_R_row(FT &f, int k, int beg, int end, long &expo)
Definition: householder.h:554
void set_updated_R_false()
Definition: householder.h:267
int get_n()
Definition: householder.h:220
void get_norm_square_b(FT &f, int i, long &expo)
Definition: householder.h:623
void invalidate_row(int k)
Definition: householder.h:591
void swap(int i, int j)
Definition: householder.cpp:372
void recover_R(int i)
Definition: householder.h:597
bool is_row_op_force_long()
Definition: householder.h:289
~MatHouseholder()
Definition: householder.h:154
MatHouseholder(Matrix< ZT > &arg_b, Matrix< ZT > &arg_u, Matrix< ZT > &arg_uinv_t, int flags)
Definition: householder.h:70
int get_d()
Definition: householder.h:219
void norm_square_b_row(FT &f, int k, long &expo)
Definition: householder.h:539
void refresh_R()
Definition: householder.h:616
void refresh_R_bf()
Definition: householder.h:610
const Matrix< ZT > & get_b()
Definition: householder.h:193
void update_R_last(int i)
Definition: householder.cpp:27
long get_row_expo(int i)
Definition: householder.h:284
bool is_enable_row_expo()
Definition: householder.h:257
void get_R_naively(FT &f, int i, int j, long &expo)
Definition: householder.h:639
void update_R_naively()
Definition: householder.h:632
void norm_square_b_row_naively(FT &f, int k, long &expo)
Definition: householder.h:665
int get_cols() const
Definition: matrix.h:156
int get_rows() const
Definition: matrix.h:154
void resize(int rows, int cols)
Definition: matrix.cpp:26
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
#define FPLLL_DEBUG_CHECK(x)
Definition: defs.h:109
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
MatHouseholderFlags
Definition: householder.h:27
@ HOUSEHOLDER_OP_FORCE_LONG
Definition: householder.h:31
@ HOUSEHOLDER_DEFAULT
Definition: householder.h:28
@ HOUSEHOLDER_ROW_EXPO
Definition: householder.h:30