Please keep responses on the list as the list is an invaluable source of
information for people that have similar problems, and going offline
deprives them of this information.
w4nderlust wrote:
> First thing: Thanks really much :)
> then some questions:
> 1) what's the difference between .cdx and .xcdx ? This is just to know.
>
The "x" before data in Sparse and Full matrices and ridx and cidx in
Sparse matrices prevents some bounds checking. If you "know" that your
indexing is correct, using xridx rather than ridx then your code will be
faster, but will it will crash octave if your indexing is incorrect.
> 2) how can owrking on the transpose of a help performances?
>
The compressed column format of Octave means that working with a Sparse
matrix column by column is many times faster than working with a matrix
row by row. The reason is that working by columns we can access the data
sequentially in "data" and "ridx" whereas as not only can't we do that
when working by rows, we have to traverse all of the elements of a
column of the sparse matrix to find the offset into "data" and "ridx"
for a particular row.
> 3) if i run this code octave crashes... why? (using octave 3.2.4)
>
>
>>>> SA = sprand(100, 100, 0.2);
>>>> SB = sprand(100, 100, 0.2);
>>>> tic; spmaxmin_ST_new(SA, SB); toc;
>>>>
> octave: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char
> *)
> &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk,
> fd)))
> ) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned
> long)((((__buil
> tin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1))
> & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned
> long
> )old_end & pagemask) == 0)' failed.
> panic: Aborted -- stopping myself...
> attempting to save variables to `octave-core'...
>
> some other times it gives me just:
>
> panic: Segmentation fault -- stopping myself...
>
> some ideas?
> Thanks
>
Because my assumption that the maximum number of non zeros elements in
the return matrix is nnzA+nnzB is incorrect. I suggest counting the
number of elements in the returned matrix first as this can be done at
significantly lower cost than the full calculation, sizing the return
matrix correctly and then removing the call to maybe_compress as its no
longer needed. Try the attached
David
#include <octave/oct.h>
#define NUM_ARG 2
#define HELP " Help della funzione"
double calc_tnorm(double first, double second);
DEFUN_DLD (spmaxmin_ST_new, args, nargout, HELP)
{
if (args.length() != NUM_ARG)
print_usage();
else
{
const SparseMatrix a = args(0).sparse_matrix_value();
const SparseMatrix b = args(1).sparse_matrix_value();
dim_vector dimsA = a.dims();
octave_idx_type rowsA = dimsA(0);
octave_idx_type colsA = dimsA(1);
octave_idx_type nnzA = a.nnz();
dim_vector dimsB = b.dims();
octave_idx_type rowsB = dimsB(0);
octave_idx_type colsB = dimsB(1);
octave_idx_type nnzB = b.nnz();
if (colsA != rowsB)
print_usage();
else
{
// Count the number of non-zero elements first. This should be
// relatively low cost
octave_idx_type nel = 0;
for (octave_idx_type i = 0; i < rowsA; i++)
{
for(octave_idx_type j = 0; j < colsB; j++)
{
if (b.cidx(j) != b.cidx(j+1))
nel++;
else
{
for (octave_idx_type k = b.cidx(j);
k <= (b.cidx(j+1) - 1); k++)
{
if (a(i, b.ridx(k)) != 0)
{
nel++;
break;
}
}
}
}
}
SparseMatrix c = SparseMatrix(colsB, rowsA, nel);
octave_idx_type rowsC = colsB;
octave_idx_type colsC = rowsA;
double mx;
nel = 0;
c.xcidx(0) = 0;
for (octave_idx_type i = 0; i < rowsA; i++)
{
for(octave_idx_type j = 0; j < colsB; j++)
{
mx = 0;
for (octave_idx_type k = b.cidx(j);
k <= (b.cidx(j+1) - 1); k++)
{
double mn = calc_tnorm(a(i, b.ridx(k)), b.data(k));
if (mn > mx)
mx = mn;
}
if (mx != 0)
{
c.xridx(nel) = j;
c.xdata(nel++) = mx;
}
}
c.xcidx(i+1) = nel;
}
return octave_value(c.transpose());
}
}
}
double calc_tnorm(double first, double second)
{
if(first < second)
return first;
else
return second;
}
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev