Librairy calcul matriciel

cs_hitcher Messages postés 21 Date d'inscription jeudi 8 avril 2004 Statut Membre Dernière intervention 15 septembre 2009 - 6 avril 2009 à 23:14
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 7 avril 2009 à 12:12
Bonjour,

je doit travailler avec des matrices qui soit capable de faire des régressions linéaires (X/Y  ou (X'X)^-1 X'Y pour les puristes) mais pas seulement. Je suis en deuil de newmat qui ne migre pas très bien vers VC++ 2008 (je fait des dll pour excel) et l'interface GSL est naze (sorry pour ceux qui ne jurent que par GSL qui est tres bien sinon). Quelqu'un aurrait une Lib facile d'installe à sa connaissance?

merci

1 réponse

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
7 avril 2009 à 12:12
Exemple DLL avec seule fonction pour X /= Y.
règle du jeu: Si diviseur == 0.0 alors X inchangé.
A noter qu'il n'y a aucun saut de code dans boucle, perfs au RDV.
La DLL fait 2.5 Ko à ce point.


__declspec(align(16)) const double dPACK1PZ[2] = {1.0, 1.0};


#pragma comment(linker, "/entry:myDllMain")
__declspec(naked) int __stdcall myDllMain(HINSTANCE hdll, DWORD dwReason, LPVOID Reserved)
{
  __asm {
    mov     eax, 1
    ret     12
  }
}


__declspec(naked) void __stdcall MatrixDivMatrix(double *pX, double *pY, DWORD count)
{ // [esp+4] = pX, [esp+8] = pY, [esp+12] = count
  __asm {
    mov     ecx, [esp+12]         ; ECX = count
    mov     [esp-4], ebx
    mov     eax, [esp+4]          ; EAX = pX
    mov     edx, [esp+8]          ; EDX = pY
    movapd  xmm3, xmmword ptr dPACK1PZ
    xorpd   xmm4, xmm4            ; XMM4 = 0.0
    shr     ecx, 1
    setc    bl                    ; BL != 0 SI ENCORE 1 A TRAITER
    test    ecx, ecx
    je      short goULTIME
goPARDEUX:
    movdqu  xmm1, xmmword ptr[edx]
    movapd  xmm2, xmm3            ; XMM2 = 1.0
    movapd  xmm5, xmm1
    movdqu  xmm0, xmmword ptr[eax]
    cmppd   xmm5, xmm4, 0
    pand    xmm2, xmm5    addpd   xmm1, xmm2            ; SI XMM1 0.0 ALORS XMM1 1.0
    divpd   xmm0, xmm1
    movdqu  xmmword ptr[eax], xmm0
    add     edx, 16
    add     eax, 16
    sub     ecx, 1
    jne     short goPARDEUX
goULTIME:
    test    bl, bl
    je      short divEXIT
    movsd   xmm1, qword ptr[edx]
    movapd  xmm2, xmm3
    movapd  xmm5, xmm1
    movsd   xmm0, qword ptr[eax]
    cmpsd   xmm5, xmm4, 0
    pand    xmm2, xmm5
    addsd   xmm1, xmm2
    divsd   xmm0, xmm1
    movsd   qword ptr[eax], xmm0
divEXIT:
    mov     ebx, [esp-4]
    ret     12
  }
}


----------------------------------
FICHIER bnMatrix.def :


LIBRARY bnMatrix
EXPORTS
  MatrixDivMatrix  @1
--------------------------------


Prog de test en C (ira idem pour Excel):


#pragma comment(lib, "bnMatrix.lib")
void __stdcall MatrixDivMatrix(double *pX, double *pY, DWORD count);


char szappname[] = "Matrix";
double matY[9] = {1.0, 2.0, 0.0, 4.0, 6.0, 1.0, 2.0, 0.0, 4.0};


void tstDivMatrix(VOID)
{
  double matX[9];
  char buf[280], *c;
  int i;
  matX[0] = 4.0;
  matX[1] = 4.0;
  matX[2] = 4.0;
  matX[3] = 4.0;
  matX[4] = -18.0;
  matX[5] = -24.40;
  matX[6] = 128.2;
  matX[7] = 1.0;
  matX[8] = 64.5;
  MatrixDivMatrix(matX, matY, 9);
  c = buf;
  for(i = 0; i < 9; i++) {
    c = bnDoubleToA(&matX[i], c);
    *c++ = 10;
  }
  *(c-1) = 0;
  MessageBox(0, buf, szappname, 0);
}


#pragma comment(linker, "/entry:myWinMain")
__declspec(naked) void __stdcall myWinMain()
{
  __asm {
    call    tstDivMatrix
    push    0
    call    dword ptr ExitProcess
  }
}

ciao...
BruNews, MVP VC++
0
Rejoignez-nous