File: assembler.mw

package info (click to toggle)
mwrap 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 980 kB
  • sloc: cpp: 3,271; ansic: 856; makefile: 252; lex: 233; sh: 2
file content (81 lines) | stat: -rw-r--r-- 2,154 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
% assembler.mw
%   MWrap bindings for MatrixAssembler (CSC matrix assembly).
%
% Copyright (c) 2007  David Bindel
% See the file COPYING for copying permissions

$[
#include "assembler.h"
#include <mex.h>
#include <algorithm>

mxArray* export_matrix(MatrixAssembler* matrix)
{
    matrix->compress();
    int m = matrix->get_m();
    int n = matrix->get_n();
    int nnz = matrix->csc_nnz();
    mxArray* result = mxCreateSparse(m, n, nnz, mxREAL);
    std::copy(matrix->get_jc(), matrix->get_jc()+n+1, mxGetJc(result));
    std::copy(matrix->get_ir(), matrix->get_ir()+nnz, mxGetIr(result));
    std::copy(matrix->get_pr(), matrix->get_pr()+nnz, mxGetPr(result));
    return result;
}
$]


@function aobj = Assembler_create(m, n, nnz)
% aobj = Assembler_create(m, n)
%
% Create an assembly object for m-by-n matrices.
if nargin < 2, m = n; end
if nargin < 3
  # MatrixAssembler* aobj = new MatrixAssembler(int m, int n);
else
  # MatrixAssembler* aobj = new MatrixAssembler(int m, int n, int nnz);
end 


@function Assembler_delete(aobj)
% Assembler_delete(aobj)
%
% Delete a matrix assembler object
# delete(MatrixAssembler* aobj);


@function Assembler_add(aobj, ii, jj, Aelt)
% Assembler_create(aobj, ii, jj, Aelt)
%
% Perform A(ii,jj) += Aelt.
[m,n] = size(Aelt);
ii = ii-1;
jj = jj-1;
# aobj->MatrixAssembler.add_entry(int[m] ii, int[n] jj, double[m,n] Aelt, 
#                                 int m, int n);


@function K = Assembler_get(aobj)
% K = Assembler_get(aobj)
%
% Retrieve a sparse matrix from a matrix assembler.
# mxArray K = export_matrix(MatrixAssembler* aobj);


@function Assembler_clear(aobj)
% Assembler_clear(aobj)
%
% Clear the matrix assembler in preparation for building a new matrix.
# aobj->MatrixAssembler.wipe();


@function [structure_nnz, cached_nnz] = Assembler_stats(aobj)
% [structure_nnz, cached_nnz] = Assembler_stats(aobj)
%
% Get statistics about the nonzeros in the assembler.
# int structure_nnz = aobj->MatrixAssembler.csc_nnz();
# int cached_nnz    = aobj->MatrixAssembler.cache_nnz();
if nargout == 0
  fprintf('NNZ in structure: %d\n', structure_nnz);
  fprintf('NNZ in cache:     %d\n', cached_nnz);
end