Minor changes, mostly signed comparisons and adding includes for

dependency documentation.
This commit is contained in:
couriersud 2016-04-08 17:02:33 +02:00
parent 50d78ba017
commit 07645b6670
9 changed files with 42 additions and 38 deletions

View File

@ -18,10 +18,10 @@ SRC = ..
CDEFS = -DPSTANDALONE=1 -DPTR64=1
#-Werror
CFLAGS = $(LTO) -g -O3 -std=c++98 -Doverride="" -march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra -Wno-long-long -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -I..
LDFLAGS = $(LTO) -g -O3 -std=c++98
#CFLAGS = $(LTO) -g -O3 -std=c++11 -Wall -Wpedantic -Wsign-compare -Wextra -Isrc
#LDFLAGS = $(LTO) -g -O3 -std=c++11
#CFLAGS = $(LTO) -g -O3 -std=c++98 -Doverride="" -march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra -Wno-long-long -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -I..
#LDFLAGS = $(LTO) -g -O3 -std=c++98
CFLAGS = $(LTO) -g -O3 -std=c++11 -I.. -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter
LDFLAGS = $(LTO) -g -O3 -std=c++11
CC = @g++-5
LD = @g++-5
@ -66,7 +66,6 @@ NLOBJS := \
$(NLOBJ)/analog/nld_opamps.o \
$(NLOBJ)/devices/nld_4020.o \
$(NLOBJ)/devices/nld_4066.o \
$(NLOBJ)/devices/nld_7400.o \
$(NLOBJ)/devices/nld_7402.o \
$(NLOBJ)/devices/nld_7404.o \
$(NLOBJ)/devices/nld_7408.o \

View File

@ -30,7 +30,7 @@ NETLIST_START(TTL_7416_DIP)
s3.A, /* A3 |5 10| Y5 */ s5.Q,
s3.Q, /* Y3 |6 9| A4 */ s4.A,
GND.I, /* GND |7 8| Y4 */ s4.Q
/* +--------------+ */
/* +--------------+ */
)
NETLIST_END()
@ -69,7 +69,7 @@ NETLIST_START(TTL_7400_DIP)
s2.B, /* B2 |5 10| B3 */ s3.B,
s2.Q, /* Y2 |6 9| A3 */ s3.A,
GND.I, /* GND |7 8| Y3 */ s3.Q
/* +--------------+ */
/* +--------------+ */
)
NETLIST_END()

View File

@ -14,8 +14,8 @@
#define TTL_7400_GATE(_name) \
NET_REGISTER_DEV(TTL_7400_GATE, _name)
#define TTL_7400_NAND(_name, _A, _B) \
NET_REGISTER_DEV(TTL_7400_NAND, _name) \
NET_CONNECT(_name, A, _A) \
NET_REGISTER_DEV(TTL_7400_NAND, _name) \
NET_CONNECT(_name, A, _A) \
NET_CONNECT(_name, B, _B)
#define TTL_7400_DIP(_name) \

View File

@ -126,7 +126,7 @@ public:
int indexof(const _ListClass &elem) const
{
for (int i = 0; i < this->size(); i++)
for (unsigned i = 0; i < this->size(); i++)
{
if (this->at(i) == elem)
return i;

View File

@ -34,7 +34,7 @@ struct mat_cr_t
while (k < oe)
{
double tmp = 0.0;
T tmp = 0.0;
const unsigned e = ia[i+1];
for (; k < e; k++)
tmp += A[k] * x[ja[k]];
@ -42,7 +42,8 @@ struct mat_cr_t
}
}
void incomplete_LU_factorization(const nl_double * RESTRICT A, nl_double * RESTRICT LU)
template<typename T>
void incomplete_LU_factorization(const T * RESTRICT A, T * RESTRICT LU)
{
/*
* incomplete LU Factorization according to http://de.wikipedia.org/wiki/ILU-Zerlegung
@ -64,7 +65,7 @@ struct mat_cr_t
// pk == (i, k)
const unsigned k = ja[pk];
const unsigned iak1 = ia[k + 1];
const double LUpk = LU[pk] = LU[pk] / LU[diag[k]];
const T LUpk = LU[pk] = LU[pk] / LU[diag[k]];
unsigned pt = ia[k];
@ -81,7 +82,8 @@ struct mat_cr_t
}
}
void solveLUx (const nl_double * RESTRICT LU, nl_double * RESTRICT r)
template<typename T>
void solveLUx (const T * RESTRICT LU, T * RESTRICT r)
{
/*
* Solve a linear equation Ax = r
@ -109,7 +111,7 @@ struct mat_cr_t
for (i = 1; ia[i] < nz_num; i++ )
{
double tmp = 0.0;
T tmp = 0.0;
const unsigned j1 = ia[i];
const unsigned j2 = diag[i];
@ -122,7 +124,7 @@ struct mat_cr_t
for (; 0 < i; i-- )
{
const unsigned im1 = i - 1;
double tmp = 0.0;
T tmp = 0.0;
const unsigned j1 = diag[im1] + 1;
const unsigned j2 = ia[im1+1];
for (unsigned j = j1; j < j2; j++ )

View File

@ -11,6 +11,7 @@
#include <algorithm>
#include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
#include "solver/vector_base.h"
/* Disabling dynamic allocation gives a ~10% boost in performance
@ -133,7 +134,7 @@ protected:
virtual int vsolve_non_dynamic(const bool newton_raphson) override;
int solve_non_dynamic(const bool newton_raphson);
inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
void build_LE_A();
void build_LE_RHS();
@ -574,7 +575,7 @@ void matrix_solver_direct_t<m_N, _storage_N>::LE_solve()
#else
vec_add_mult_scalar(kN-i-1,pj,f1,pi);
//for (unsigned k = i+1; k < kN; k++)
// pj[k] = pj[k] + pi[k] * f1;
// pj[k] = pj[k] + pi[k] * f1;
//for (unsigned k = i+1; k < kN; k++)
//A(j,k) += A(i,k) * f1;
RHS(j) += RHS(i) * f1;

View File

@ -11,6 +11,7 @@
#include <algorithm>
#include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
//#define A(_r, _c) m_A[_r][_c]

View File

@ -13,9 +13,9 @@
* In this specific implementation, u is a unit vector specifying the row which
* changed. Thus v contains the changed column.
*
* Than z = A????? u , w = transpose(A?????) v , lambda = v z
* Than z = A¹ u , w = transpose(A¹) v , lambda = v z
*
* A????? <- 1.0 / (1.0 + lambda) * (z x w)
* A¹ <- 1.0 / (1.0 + lambda) * (z x w)
*
* The approach is iterative and applied for each row changed.
*
@ -36,6 +36,7 @@
#include <algorithm>
#include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
#include "solver/vector_base.h"
NETLIB_NAMESPACE_DEVICES_START()
@ -62,7 +63,7 @@ protected:
virtual int vsolve_non_dynamic(const bool newton_raphson) override;
int solve_non_dynamic(const bool newton_raphson);
inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
void build_LE_A();
void build_LE_RHS();
@ -454,14 +455,14 @@ void matrix_solver_sm_t<m_N, _storage_N>::LE_compute_x(
{
const unsigned kN = N();
for (int i=0; i<kN; i++)
for (unsigned i=0; i<kN; i++)
x[i] = 0.0;
for (int k=0; k<kN; k++)
for (unsigned k=0; k<kN; k++)
{
const nl_double f = RHS(k);
for (int i=0; i<kN; i++)
for (unsigned i=0; i<kN; i++)
x[i] += Ainv(i,k) * f;
}
}
@ -512,13 +513,13 @@ int matrix_solver_sm_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const boo
}
else
{
if (!incremental)
if (not incremental)
{
for (int row = 0; row < iN; row ++)
for (int k = 0; k < iN; k++)
for (unsigned row = 0; row < iN; row ++)
for (unsigned k = 0; k < iN; k++)
Ainv(row,k) = lAinv(row, k);
}
for (int row = 0; row < iN; row ++)
for (unsigned row = 0; row < iN; row ++)
{
nl_double v[m_pitch] = {0};
unsigned cols[m_pitch];
@ -555,11 +556,11 @@ int matrix_solver_sm_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const boo
}
lamba = -1.0 / (1.0 + lamba);
for (int i=0; i<iN; i++)
for (unsigned i=0; i<iN; i++)
{
const nl_double f = lamba * z[i];
if (f != 0.0)
for (int k = 0; k < iN; k++)
for (unsigned k = 0; k < iN; k++)
Ainv(i,k) += f * w[k];
}
}

View File

@ -15,7 +15,7 @@
* Whilst the book proposes to invert the matrix R=(I+transpose(V)*Z) we define
*
* w = transpose(V)*y
* a = R????? * w
* a = R¹ * w
*
* and consequently
*
@ -43,6 +43,7 @@
#include <algorithm>
#include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
#include "solver/vector_base.h"
NETLIB_NAMESPACE_DEVICES_START()
@ -69,7 +70,7 @@ protected:
virtual int vsolve_non_dynamic(const bool newton_raphson) override;
int solve_non_dynamic(const bool newton_raphson);
inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
void build_LE_A();
void build_LE_RHS();
@ -467,14 +468,14 @@ void matrix_solver_w_t<m_N, _storage_N>::LE_compute_x(
{
const unsigned kN = N();
for (int i=0; i<kN; i++)
for (unsigned i=0; i<kN; i++)
x[i] = 0.0;
for (int k=0; k<kN; k++)
for (unsigned k=0; k<kN; k++)
{
const nl_double f = RHS(k);
for (int i=0; i<kN; i++)
for (unsigned i=0; i<kN; i++)
x[i] += Ainv(i,k) * f;
}
}
@ -531,7 +532,7 @@ int matrix_solver_w_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const bool
unsigned rowcount=0;
#define VT(r,c) (A(r,c) - lA(r,c))
for (int row = 0; row < iN; row ++)
for (unsigned row = 0; row < iN; row ++)
{
unsigned cc=0;
auto &nz = m_terms[row]->m_nz;
@ -596,7 +597,7 @@ int matrix_solver_w_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const bool
}
/* Back substitution */
//inv(H) w = t w = H t
nl_double *t = new nl_double[rowcount];
nl_double t[_storage_N]; // FIXME: convert to member
for (int j = rowcount - 1; j >= 0; j--)
{
nl_double tmp = 0;
@ -619,7 +620,6 @@ int matrix_solver_w_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const bool
}
new_V[i] -= tmp;
}
delete[] t;
}
}
m_cnt++;