Macaulay2 Engine
Loading...
Searching...
No Matches

◆ rawMutableMatrixFillRandomDensity()

void rawMutableMatrixFillRandomDensity ( MutableMatrix * M,
double density,
int special_type )

Definition at line 134 of file mutable-matrix.cpp.

138{
139 bool doing_fraction = false;
140 int threshold = 0;
141
142 int nrows = static_cast<int>(M->n_rows());
143 int ncols = static_cast<int>(M->n_cols());
144 const Ring *R = M->get_ring();
145
146 if (density != 1.0)
147 {
148 doing_fraction = true;
149 threshold = static_cast<int>(density * 10000);
150 }
151
152 if (special_type == 0)
153 {
154 for (int i = 0; i < ncols; i++)
155 for (int j = 0; j < nrows; j++)
156 {
157 if (doing_fraction)
158 {
159 int32_t u = rawRandomInt((int32_t)10000);
160 if (u > threshold) continue;
161 }
162 ring_elem a = R->random();
163 if (!R->is_zero(a)) M->set_entry(j, i, a);
164 }
165 }
166 else if (special_type == 1)
167 {
168 for (int i = 0; i < ncols; i++)
169 {
170 int top = (i >= nrows ? nrows : i);
171 for (int j = 0; j < top; j++)
172 {
173 if (doing_fraction)
174 {
175 int32_t u = rawRandomInt((int32_t)10000);
176 if (u > threshold) continue;
177 }
178 ring_elem a = R->random();
179 if (!R->is_zero(a)) M->set_entry(j, i, a);
180 }
181 }
182 }
183}
virtual size_t n_rows() const =0
virtual size_t n_cols() const =0
virtual const Ring * get_ring() const =0
virtual bool set_entry(size_t r, size_t c, const ring_elem a)=0
virtual bool is_zero(const ring_elem f) const =0
virtual ring_elem random() const
Definition ring.cpp:284
xxx xxx xxx
Definition ring.hpp:102
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44

References MutableMatrix::get_ring(), Ring::is_zero(), MutableMatrix::n_cols(), MutableMatrix::n_rows(), Ring::random(), rawRandomInt(), and MutableMatrix::set_entry().