Zum Inhalt springen

dizem

Mitglieder
  • Gesamte Inhalte

    10
  • Benutzer seit

  • Letzter Besuch

Alle Inhalte von dizem

  1. Ich bin in forum neu (auch in c++ )daher weiß ich einfach nicht wie ich den Code mit Zeilennummern und bunt posten soll , ich habe es versucht hat aber nicht geklappt..Da ich es eillig habe versuche ich irgendwie mein Problem bzw. meine Fragen zu darstellen.. Ich bedanke mich für deine Rückmeldung .
  2. danke sehr jetzt sind diese Fehler nicht mehr da...ich möchte gerne mein Code bunt posten damit man es besser erkennt aber kann ich leider nicht, es geht irgendwie nicht so ganz.. folgender code ist meine Struktur. #include "csparse.h" typedef struct problem_struct { cs *A ; cs *C ; int sym ; double *x ; double *b ; double *resid ; } problem ; problem *get_problem (FILE *f, double tol) ; int demo2 (problem *Prob) ; int demo3 (problem *Prob) ; problem *free_problem (problem *Prob) ; und mein Quellencode mit der Funktion cs_free sieht folgendermaßen aus /* free a problem bzw a sparse Matríx */ problem *free_problem (problem *Prob) { if (!Prob) return (NULL) ; cs_spfree (Prob->A) ; if (Prob->sym) cs_spfree (Prob->C) ; cs_free (Prob-> ; cs_free (Prob->x) ; cs_free (Prob->resid) ; return (cs_free (Prob)) ; } Genau bei der Zeile return (cs_free (Prob)) ; ein letzter ähnlicher Fehler und zwar folgendes "error C2440: 'return': 'void *' kann nicht in 'problem *' konvertiert werden. Meinst du dass es sein könnte dass die Fehler in der Struktur liegen? Übrigens ich bedanke mich sehr
  3. hallo leute ich habe wieder ein Konvertierungsfehler.mein code lautet #include "csprobe2.h" #include <time.h> /* 1 if A is square & upper tri., -1 if square & lower tri., 0 otherwise */ static int is_sym (cs *A) { int is_upper, is_lower, j, p, n = A->n, m = A->m, *Ap = A->p, *Ai = A->i ; if (m != n) return (0) ; is_upper = 1 ; is_lower = 1 ; for (j = 0 ; j < n ; j++) { for (p = Ap [j] ; p < Ap [j+1] ; p++) { if (Ai [p] > j) is_upper = 0 ; if (Ai [p] < j) is_lower = 0 ; } } return (is_upper ? 1 : (is_lower ? -1 : 0)) ; } /* true for off-diagonal entries */ static int dropdiag (int i, int j, double aij, void *other) { return (i != j) ;} /* C = A + triu(A,1)' */ static cs *make_sym (cs *A) { cs *AT, *C ; AT = cs_transpose (A, 1) ; /* AT = A' */ cs_fkeep (AT, &dropdiag, NULL) ; /* drop diagonal entries from AT */ C = cs_add (A, AT, 1, 1) ; /* C = A+AT */ cs_spfree (AT) ; return © ; } /* create a right-hand side */ static void rhs (double *x, double *b, int m) { int i ; for (i = 0 ; i < m ; i++) b = 1 + ((double) i) / m ; for (i = 0 ; i < m ; i++) x = b ; } /* infinity-norm of x */ static double norm (double *x, int n) { int i ; double normx = 0 ; for (i = 0 ; i < n ; i++) normx = CS_MAX (normx, fabs (x )) ; return (normx) ; } /* compute residual, norm(A*x-b,inf) / (norm(A,1)*norm(x,inf) + norm(b,inf)) */ static void print_resid (int ok, cs *A, double *x, double *b, double *resid) { int i, m, n ; if (!ok) { printf (" (failed)\n") ; return ; } m = A->m ; n = A->n ; for (i = 0 ; i < m ; i++) resid = -b ; /* resid = -b */ cs_gaxpy (A, x, resid) ; /* resid = resid + A*x */ printf ("resid: %8.2e\n", norm (resid,m) / ((n == 0) ? 1 : (cs_norm (A) * norm (x,n) + norm (b,m)))) ; } static double tic (void) { return (clock () / (double) CLOCKS_PER_SEC) ; } static double toc (double t) { double s = tic () ; return (CS_MAX (0, s-t)) ; } static void print_order (int order) { switch (order) { case 0: printf ("natural ") ; break ; case 1: printf ("amd(A+A') ") ; break ; case 2: printf ("amd(S'*S) ") ; break ; case 3: printf ("amd(A'*A) ") ; break ; } } /* read a problem from a file */ problem *get_problem (FILE *f, double tol) { cs *T, *A, *C ; int sym, m, n, mn, nz1, nz2 ; problem *Prob ; Prob = cs_calloc (1, sizeof (problem)) ; if (!Prob) return (NULL) ; T = cs_load (f) ; /* load triplet matrix T from a file */ Prob->A = A = cs_compress (T) ; /* A = compressed-column form of T */ cs_spfree (T) ; /* clear T */ if (!cs_dupl (A)) return (free_problem (Prob)) ; /* sum up duplicates */ Prob->sym = sym = is_sym (A) ; /* determine if A is symmetric */ m = A->m ; n = A->n ; mn = CS_MAX (m,n) ; nz1 = A->p [n] ; cs_dropzeros (A) ; /* drop zero entries */ nz2 = A->p [n] ; if (tol > 0) cs_droptol (A, tol) ; /* drop tiny entries (just to test) */ Prob->C = C = sym ? make_sym (A) : A ; /* C = A + triu(A,1)', or C=A */ if (!C) return (free_problem (Prob)) ; printf ("\n--- Matrix: %d-by-%d, nnz: %d (sym: %d: nnz %d), norm: %8.2e\n", m, n, A->p [n], sym, sym ? C->p [n] : 0, cs_norm ©) ; if (nz1 != nz2) printf ("zero entries dropped: %d\n", nz1 - nz2) ; if (nz2 != A->p [n]) printf ("tiny entries dropped: %d\n", nz2 - A->p [n]) ; Prob->b = cs_malloc (mn, sizeof (double)) ; Prob->x = cs_malloc (mn, sizeof (double)) ; Prob->resid = cs_malloc (mn, sizeof (double)) ; return ((!Prob->b || !Prob->x || !Prob->resid) ? free_problem (Prob) : Prob) ; } /* free a problem */ problem *free_problem (problem *Prob) { if (!Prob) return (NULL) ; cs_spfree (Prob->A) ; if (Prob->sym) cs_spfree (Prob->C) ; cs_free (Prob-> ; cs_free (Prob->x) ; cs_free (Prob->resid) ; return (cs_free (Prob)) ; } /* solve a linear system using Cholesky, LU, and QR, with various orderings */ int demo2 (problem *Prob) { cs *A, *C ; double *b, *x, *resid, t, tol ; int k, m, n, ok, order, nb, ns, *r, *s, *rr, sprank ; csd *D ; if (!Prob) return (0) ; A = Prob->A ; C = Prob->C ; b = Prob->b ; x = Prob->x ; resid = Prob->resid; m = A->m ; n = A->n ; tol = Prob->sym ? 0.001 : 1 ; /* partial pivoting tolerance */ D = cs_dmperm (C, 1) ; /* randomized dmperm analysis */ if (!D) return (0) ; nb = D->nb ; r = D->r ; s = D->s ; rr = D->rr ; sprank = rr [3] ; for (ns = 0, k = 0 ; k < nb ; k++) { ns += ((r [k+1] == r [k]+1) && (s [k+1] == s [k]+1)) ; } printf ("blocks: %d singletons: %d structural rank: %d\n", nb, ns, sprank) ; cs_dfree (D) ; for (order = 0 ; order <= 3 ; order += 3) /* natural and amd(A'*A) */ { if (!order && m > 1000) continue ; printf ("QR ") ; print_order (order) ; rhs (x, b, m) ; /* compute right-hand side */ t = tic () ; ok = cs_qrsol (order, C, x) ; /* min norm(Ax- with QR */ printf ("time: %8.2f ", toc (t)) ; print_resid (ok, C, x, b, resid) ; /* print residual */ } if (m != n || sprank < n) return (1) ; /* return if rect. or singular*/ for (order = 0 ; order <= 3 ; order++) /* try all orderings */ { if (!order && m > 1000) continue ; printf ("LU ") ; print_order (order) ; rhs (x, b, m) ; /* compute right-hand side */ t = tic () ; ok = cs_lusol (order, C, x, tol) ; /* solve Ax=b with LU */ printf ("time: %8.2f ", toc (t)) ; print_resid (ok, C, x, b, resid) ; /* print residual */ } if (!Prob->sym) return (1) ; for (order = 0 ; order <= 1 ; order++) /* natural and amd(A+A') */ { if (!order && m > 1000) continue ; printf ("Chol ") ; print_order (order) ; rhs (x, b, m) ; /* compute right-hand side */ t = tic () ; ok = cs_cholsol (order, C, x) ; /* solve Ax=b with Cholesky */ printf ("time: %8.2f ", toc (t)) ; print_resid (ok, C, x, b, resid) ; /* print residual */ } return (1) ; } /* free workspace for demo3 */ static int done3 (int ok, css *S, csn *N, double *y, cs *W, cs *E, int *p) { cs_sfree (S) ; cs_nfree (N) ; cs_free (y) ; cs_spfree (W) ; cs_spfree (E) ; cs_free (p) ; return (ok) ; } /* Cholesky update/downdate */ int demo3 (problem *Prob) { cs *A, *C, *W = NULL, *WW, *WT, *E = NULL, *W2 ; int n, k, *Li, *Lp, *Wi, *Wp, p1, p2, *p = NULL, ok ; double *b, *x, *resid, *y = NULL, *Lx, *Wx, s, t, t1 ; css *S = NULL ; csn *N = NULL ; if (!Prob || !Prob->sym || Prob->A->n == 0) return (0) ; A = Prob->A ; C = Prob->C ; b = Prob->b ; x = Prob->x ; resid = Prob->resid; n = A->n ; if (!Prob->sym || n == 0) return (1) ; rhs (x, b, n) ; /* compute right-hand side */ printf ("\nchol then update/downdate ") ; print_order (1) ; y = cs_malloc (n, sizeof (double)) ; t = tic () ; S = cs_schol (1, C) ; /* symbolic Chol, amd(A+A') */ printf ("\nsymbolic chol time %8.2f\n", toc (t)) ; t = tic () ; N = cs_chol (C, S) ; /* numeric Cholesky */ printf ("numeric chol time %8.2f\n", toc (t)) ; if (!S || !N || !y) return (done3 (0, S, N, y, W, E, p)) ; t = tic () ; cs_ipvec (S->pinv, b, y, n) ; /* y = P*b */ cs_lsolve (N->L, y) ; /* y = L\y */ cs_ltsolve (N->L, y) ; /* y = L'\y */ cs_pvec (S->pinv, y, x, n) ; /* x = P'*y */ printf ("solve chol time %8.2f\n", toc (t)) ; printf ("original: ") ; print_resid (1, C, x, b, resid) ; /* print residual */ k = n/2 ; /* construct W */ W = cs_spalloc (n, 1, n, 1, 0) ; if (!W) return (done3 (0, S, N, y, W, E, p)) ; Lp = N->L->p ; Li = N->L->i ; Lx = N->L->x ; Wp = W->p ; Wi = W->i ; Wx = W->x ; Wp [0] = 0 ; p1 = Lp [k] ; Wp [1] = Lp [k+1] - p1 ; s = Lx [p1] ; srand (1) ; for ( ; p1 < Lp [k+1] ; p1++) { p2 = p1 - Lp [k] ; Wi [p2] = Li [p1] ; Wx [p2] = s * rand () / ((double) RAND_MAX) ; } t = tic () ; ok = cs_updown (N->L, +1, W, S->parent) ; /* update: L*L'+W*W' */ t1 = toc (t) ; printf ("update: time: %8.2f\n", t1) ; if (!ok) return (done3 (0, S, N, y, W, E, p)) ; t = tic () ; cs_ipvec (S->pinv, b, y, n) ; /* y = P*b */ cs_lsolve (N->L, y) ; /* y = L\y */ cs_ltsolve (N->L, y) ; /* y = L'\y */ cs_pvec (S->pinv, y, x, n) ; /* x = P'*y */ t = toc (t) ; p = cs_pinv (S->pinv, n) ; W2 = cs_permute (W, p, NULL, 1) ; /* E = C + (P'W)*(P'W)' */ WT = cs_transpose (W2,1) ; WW = cs_multiply (W2, WT) ; cs_spfree (WT) ; cs_spfree (W2) ; E = cs_add (C, WW, 1, 1) ; cs_spfree (WW) ; if (!E || !p) return (done3 (0, S, N, y, W, E, p)) ; printf ("update: time: %8.2f (incl solve) ", t1+t) ; print_resid (1, E, x, b, resid) ; /* print residual */ cs_nfree (N) ; /* clear N */ t = tic () ; N = cs_chol (E, S) ; /* numeric Cholesky */ if (!N) return (done3 (0, S, N, y, W, E, p)) ; cs_ipvec (S->pinv, b, y, n) ; /* y = P*b */ cs_lsolve (N->L, y) ; /* y = L\y */ cs_ltsolve (N->L, y) ; /* y = L'\y */ cs_pvec (S->pinv, y, x, n) ; /* x = P'*y */ t = toc (t) ; printf ("rechol: time: %8.2f (incl solve) ", t) ; print_resid (1, E, x, b, resid) ; /* print residual */ t = tic () ; ok = cs_updown (N->L, -1, W, S->parent) ; /* downdate: L*L'-W*W' */ t1 = toc (t) ; if (!ok) return (done3 (0, S, N, y, W, E, p)) ; printf ("downdate: time: %8.2f\n", t1) ; t = tic () ; cs_ipvec (S->pinv, b, y, n) ; /* y = P*b */ cs_lsolve (N->L, y) ; /* y = L\y */ cs_ltsolve (N->L, y) ; /* y = L'\y */ cs_pvec (S->pinv, y, x, n) ; /* x = P'*y */ t = toc (t) ; printf ("downdate: time: %8.2f (incl solve) ", t1+t) ; print_resid (1, C, x, b, resid) ; /* print residual */ return (done3 (1, S, N, y, W, E, p)) ; } die fehlermeldung dazu sihet folgendermaßen aus: error C2440: '=': 'void *' kann nicht in 'problem *' konvertiert werden und error C2440: 'return': 'void *' kann nicht in 'problem *' konvertiert werden ich kommen garnicht weiter , hat jemand eine Idee wie ich die Fehlerbehen kann?
  4. dizem

    error 2440

    danke sehr an euch alle...werde daran erstmal arbeiten..
  5. dizem

    error 2440

    int p, f, j, *Lp, *Li, *Cp, *Ci ; double *Lx, *Cx, alpha, beta = 1, delta, gamma, w1, w2, *w, n, beta2 = 1 ; if (!L || !C || !parent) return (0) ; Lp = L->p ; Li = L->i ; Lx = L->x ; n = L->n ; Cp = C->p ; Ci = C->i ; Cx = C->x ; if ((p = Cp [0]) >= Cp [1]) return (1) ; /* return if C empty */ w = (double*)cs_malloc(n, sizeof (double)) ; if (!w) return (0) ; f = Ci [p] ; for ( ; p < Cp [1] ; p++) f = CS_MIN (f, Ci [p]) ; /* f = min (find ©) */ for (j = f ; j != -1 ; j = parent [j]) w [j] = 0 ; /* clear workspace w */ for (p = Cp [0] ; p < Cp [1] ; p++) w [Ci [p]] = Cx [p] ; /* w = C */ for (j = f ; j != -1 ; j = parent [j]) /* walk path f up to root */ { p = Lp [j] ; alpha = w [j] / Lx [p] ; /* alpha = w(j) / L(j,j) */ beta2 = beta*beta + sigma*alpha*alpha ; if (beta2 <= 0) break ; /* not positive definite */ beta2 = sqrt (beta2) ; delta = (sigma > 0) ? (beta / beta2) : (beta2 / beta) ; gamma = sigma * alpha / (beta2 * beta) ; Lx [p] = delta * Lx [p] + ((sigma > 0) ? (gamma * w [j]) : 0) ; beta = beta2 ; for (p++ ; p < Lp [j+1] ; p++) { w1 = w [Li [p]] ; w [Li [p]] = w2 = w1 - alpha * Lx [p] ; Lx [p] = delta * Lx [p] + gamma * ((sigma > 0) ? w1 : w2) ; } } cs_free (w) ; return (beta2 > 0) ; } JETZT habe ich nun einen Fehler mit dem Linker und zwar.. error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_main" in Funktion "___tmainCRTStartup" wieß nicht wie ich den beheben soll?Ich bin ziemlich die Anfängerin
  6. dizem

    error 2440

    mit dem code w = (double*)cs_malloc(n, sizeof (double)) ; if (!w) return (0) ; Zeigt er folgende Fehler. :\dokumente und einstellungen\admin\eigene dateien\visual studio 2008\projects\permute\permute\csparse.cpp(1922) : warning C4244: 'Argument': Konvertierung von 'double' in 'int', möglicher Datenverlust Manifest in Ressourcen wird kompiliert... Microsoft ® Windows ® Resource Compiler Version 6.1.6723.1 Copyright © Microsoft Corporation. All rights reserved. Verknüpfen... MSVCRTD.lib(crtexe.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_main" in Funktion "___tmainCRTStartup". C:\Dokumente und Einstellungen\Admin\Eigene Dateien\Visual Studio 2008\Projects\permute\Debug\permute.exe : fatal error LNK1120: 1 nicht aufgelöste externe Verweise. Das Buildprotokoll wurde unter "file://c:\Dokumente und Einstellungen\Admin\Eigene Dateien\Visual Studio 2008\Projects\permute\permute\Debug\BuildLog.htm" gespeichert. permute - 2 Fehler, 1 Warnung(en) ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
  7. dizem

    error 2440

    die fehlermeldung sagt dass error C2440: '=': 'int *' kann nicht in 'double *' konvertiert werden kann..Ich komme nicht weiter...das ist der einzige Fehler ...wenn ich in int* schreibe dann meckert der zicht mal....
  8. dizem

    error 2440

    du hast Recht der Code ist nicht von mir, mir gehts nur darum dass der fehlerfrei funktioniert , ich muss nur die Ausgabe davon haben , das eigentliche Problem ist: ich müsste nun ein Programm in C++ schreiben der einen Matrix permutiert wie in matlab der dmperm macht..Deswegen habe ich die csparse.cpp und csparse.h mit dem code cs_permute Dateien versucht zusammen zu verknüpfen... Es entstehen natürlich Fehler die ich nicht beheben könnte.Hast du vielleicht eine bessere Idee wie ich weiterkommen kann?
  9. dizem

    error 2440

    da ich neu in Forum bin weiß nicht ganz genau wo ich Beiträge posten soll..Du meinst dass ich w = (double*)cs_malloc (n, sizeof (double)) schreiben soll? Dies habe ich schon ausprobiert , der zeigt dann mehrere Fehlern Wie könnte es sonst lösen?Hat jemand sonst eine Idee?
  10. dizem

    error 2440

    Hallo Ich bin ziemlich die Abfängerin bei C++ und habe folgenden Code aufgeschrieben : /* sparse Cholesky update/downdate, L*L' + sigma*w*w' (sigma = +1 or -1) */ int cs_updown (cs *L, int sigma, const cs *C, const int *parent) { int p, f, j, *Lp, *Li, *Cp, *Ci ; double *Lx, *Cx, alpha, beta = 1, delta, gamma, w1, w2, *w, n, beta2 = 1 ; if (!L || !C || !parent) return (0) ; Lp = L->p ; Li = L->i ; Lx = L->x ; n = L->n ; Cp = C->p ; Ci = C->i ; Cx = C->x ; if ((p = Cp [0]) >= Cp [1]) return (1) ; /* return if C empty */ w = (int*)cs_malloc (n, sizeof (int)) ; if (!w) return (0) ; f = Ci [p] ; for ( ; p < Cp [1] ; p++) f = CS_MIN (f, Ci [p]) ; /* f = min (find ©) */ for (j = f ; j != -1 ; j = parent [j]) w [j] = 0 ; /* clear workspace w */ for (p = Cp [0] ; p < Cp [1] ; p++) w [Ci [p]] = Cx [p] ; /* w = C */ for (j = f ; j != -1 ; j = parent [j]) /* walk path f up to root */ { p = Lp [j] ; alpha = w [j] / Lx [p] ; /* alpha = w(j) / L(j,j) */ beta2 = beta*beta + sigma*alpha*alpha ; if (beta2 <= 0) break ; /* not positive definite */ beta2 = sqrt (beta2) ; delta = (sigma > 0) ? (beta / beta2) : (beta2 / beta) ; gamma = sigma * alpha / (beta2 * beta) ; Lx [p] = delta * Lx [p] + ((sigma > 0) ? (gamma * w [j]) : 0) ; beta = beta2 ; for (p++ ; p < Lp [j+1] ; p++) { w1 = w [Li [p]] ; w [Li [p]] = w2 = w1 - alpha * Lx [p] ; Lx [p] = delta * Lx [p] + gamma * ((sigma > 0) ? w1 : w2) ; } } cs_free (w) ; return (beta2 > 0) ; } wobei die Zeile mit w = (int*)cs_malloc (n, sizeof (int)) , den Fehler C2440 verursacht Kann mir jemand dabei einen Tipp geben? LG

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...