z3-z3-4.13.0.src.math.lp.indexed_vector_def.h Maven / Gradle / Ivy
The newest version!
/*++
Copyright (c) 2017 Microsoft Corporation
Module Name:
Abstract:
Author:
Lev Nachmanson (levnach)
Revision History:
--*/
#pragma once
#include "util/vector.h"
#include "math/lp/indexed_vector.h"
#include "math/lp/lp_settings.h"
namespace lp {
void print_vector_as_doubles(const vector & t, std::ostream & out) {
for (unsigned i = 0; i < t.size(); i++)
out << t[i].get_double() << std::setprecision(3) << " ";
out << std::endl;
}
template
void indexed_vector::resize(unsigned data_size) {
clear();
m_data.resize(data_size, numeric_traits::zero());
}
template
void indexed_vector::set_value(const T& value, unsigned index) {
m_data[index] = value;
lp_assert(std::find(m_index.begin(), m_index.end(), index) == m_index.end());
m_index.push_back(index);
}
template
void indexed_vector::clear() {
for (unsigned i : m_index)
m_data[i] = numeric_traits::zero();
m_index.resize(0);
}
template
void indexed_vector::clear_all() {
unsigned i = m_data.size();
while (i--) m_data[i] = numeric_traits::zero();
m_index.resize(0);
}
template
void indexed_vector::erase_from_index(unsigned j) {
auto it = std::find(m_index.begin(), m_index.end(), j);
if (it != m_index.end())
m_index.erase(it);
}
template
void indexed_vector::print(std::ostream & out) {
out << "m_index " << std::endl;
for (unsigned i = 0; i < m_index.size(); i++) {
out << m_index[i] << " ";
}
out << std::endl;
print_vector(m_data, out);
}
}