I a very interested about the source, because I have tried on my own (see the attached file) by I have discovered that getSparseMatrix only gives a copy of the non zeros values but not just the pointer to the array.

S.

Le 12/05/2015 12:01, Samuel Gougeon a écrit :
Le 12/05/2015 11:56, Samuel Gougeon a écrit :
Le 12/05/2015 11:09, Stéphane Mottelet a écrit :
Le 12/05/2015 10:30, Samuel Gougeon a écrit :

OK. So, unless i misunderstand you, this syntax is used only to update values at their current positions, not to set new positions or modify ones.
exactly !

Stephane,
Could you report your wish on bugzilla? The patch to do S.nzval=v is ready. I will post it on your report, with updated help pages.
Here is a sample:

-->sp0 = sprand(5,4,0.4); v = grand(1,nnz(sp0),"uin",0,10); sp = sp0;

-->sp.nzval = v;

-->full(sp0), v, full(sp),sp
 ans  =

    0.3439298    0.           0.0811258    0.9293860
    0.           0.7802274    0.3794188    0.
    0.6256186    0.           0.           0.4584969
    0.           0.6692851    0.           0.
    0.8157691    0.           0.           0.7757127
 v  =

    5.    9.    6.    0.    10.    5.    4.    0.    9.    3.
 ans  =

    5.    0.     5.    0.
    0.    0.     4.    0.
    9.    0.     0.    9.
    0.    10.    0.    0.
    6.    0.     0.    3.
 sp  =

(    5,    4) sparse matrix

(    1,    1)        5.
(    1,    3)        5.
(    2,    3)        4.
(    3,    1)        9.
(    3,    4)        9.
(    4,    2)        10.
(    5,    1)        6.
(    5,    4)        3.



_______________________________________________
dev mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/dev


--
Département de Génie Informatique
EA 4297 Transformations Intégrées de la Matière Renouvelable
Université de Technologie de Compiègne -  CS 60319
60203 Compiègne cedex

/* ==================================================================== */
/* Template toolbox_skeleton */
/* This file is released under the 3-clause BSD license. See COPYING-BSD. */
/* ==================================================================== */
#include "api_scilab.h"
#include "Scierror.h"
#include "MALLOC.h"
#include <localization.h>
#include "api_scilab.h"

#define MIN(x, y) (((x) < (y)) ? (x) : (y))

int sparse_set(char *fname,unsigned long fname_len)
{
        SciErr sciErr;
        int i,j,k;
        int* piAddr                     = NULL;
    int* vAddr          = NULL;
        int iRows                       = 0;
        int iCols                       = 0;
        int viRows                      = 0;
        int viCols                      = 0;
        int iNbItem                     = 0;
        int* piNbItemRow        = NULL;
        int* piColPos           = NULL;
        double* pdblReal        = NULL; 
    double* vpdblReal   = NULL;
        double* pdblImg         = NULL;

    CheckInputArgument(pvApiCtx, 2, 2);

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
        if(sciErr.iErr)
        {
                printError(&sciErr, 0);
                return 0;
        }
        sciErr = getSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, 
&piNbItemRow, &piColPos, &pdblReal);
        if(sciErr.iErr)
        {
                printError(&sciErr, 0);
                return 0;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &vAddr);
        if(sciErr.iErr)
        {
                printError(&sciErr, 0);
                return 0;
        }

        sciErr = getMatrixOfDouble(pvApiCtx, vAddr, &viRows, &viCols, 
&vpdblReal);
        if(sciErr.iErr)
        {
                printError(&sciErr, 0);
                return 0;
        }

        
    for(i = 0 ; i < MIN(viRows*viCols,iNbItem) ; i++)
        {
                pdblReal[i]=vpdblReal[i];
        }

        //assign allocated variables to Lhs position
        // AssignOutputVariable(pvApiCtx, 1) = 0;
        return 0;
}
_______________________________________________
dev mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/dev

Reply via email to