changeset 209:4fc2631477a3 feature/grids

Removed old versions of blockmatrix implementations.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 16 Jun 2016 09:06:57 +0200
parents 40dda96c8c9c
children 39b7dcb2c724
files cell2sparse.m cell2vector.m sparse2cell.m sparse2cellTest.m vector2cell.m
diffstat 5 files changed, 0 insertions(+), 157 deletions(-) [+]
line wrap: on
line diff
--- a/cell2sparse.m	Wed Jun 15 17:25:40 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-function A = cell2sparse(C)
-
-    if isempty(C)
-        A = sparse([]);
-        return
-    end
-
-    n = row_height(C);
-    m = col_width(C);
-
-    N = sum(n);
-    M = sum(m);
-
-    A = sparse(N,M);
-
-    n_ind = [0 cumsum(n)];
-    m_ind = [0 cumsum(m)];
-
-    for i = 1:size(C,1)
-        for j = 1:size(C,2)
-            if ~has_matrix(C{i,j})
-                continue
-            end
-            A(n_ind(i)+1:n_ind(i+1),m_ind(j)+1:m_ind(j+1)) = C{i,j};
-        end
-    end
-
-end
-
-function m = col_width(C)
-    for j = 1:size(C,2)
-        for i = 1:size(C,1)
-            if ~has_matrix(C{i,j})
-                continue
-            end
-            m(j) = size(C{i,j},2);
-        end
-    end
-end
-
-function n = row_height(C)
-    for i = 1:size(C,1)
-        for j = 1:size(C,2)
-            if ~has_matrix(C{i,j})
-                continue
-            end
-            n(i) = size(C{i,j},1);
-        end
-    end
-end
-
-function b = has_matrix(c)
-    b = ~(isempty(c) || (numel(c)==1 && c == 0));
-end
\ No newline at end of file
--- a/cell2vector.m	Wed Jun 15 17:25:40 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-% cell2vector accepts a column cell array of column vectors and returns a columnvector
-% with the input concatenated. It also returns the number of elements in each vector.
-%   cv -- column cell array with column vectors
-%   v  -- vector of the concatenated vectors
-%   n  -- number of elements in each vector before concatenation. Can be used with vector2cell().
-function [v, n] = cell2vector(cv)
-    v = [];
-    n = zeros(length(cv),1);
-
-    for i = 1:length(cv)
-        n(i) = length(cv{i});
-        v = [v; cv{i}];
-    end
-end
-
-
-% IS THIS ONE REALLY NEEDED? JUST USE cell2sparse?
-
--- a/sparse2cell.m	Wed Jun 15 17:25:40 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-% sparse2cell breaks a sparse matrix up into a cell matrix of sparse matrices.
-% any zero submatrix creates a empty cell in the cell matrix.
-%  A -- NxM sparse matrix
-%  d1, d2 -- vectors of sub matrix sizes for each dimensions. Must have sum(di) == Ni.
-% Example:
-%   C = sparse2cell(A,[5 10], [10 5])
-function C = sparse2cell(A, d1, d2)
-    [n, m] = size(A);
-    if n ~= sum(d1) || m ~= sum(d2)
-        error('sparse2cell:NonMatchingDim','The elements of d1 and d2 must sum to N and M.');
-    end
-
-    C = cell(length(d1), length(d2));
-    I = 1;
-    for i = 1:length(d1)
-        J = 1;
-        for j = 1:length(d2)
-            Asub = A(I:(I + d1(i)-1), J:(J + d2(j)-1));
-            if nnz(Asub) == 0
-                C{i,j} = [];
-            else
-                C{i,j} = Asub;
-            end
-            J = J + d2(j);
-        end
-        I = I + d1(i);
-    end
-end
--- a/sparse2cellTest.m	Wed Jun 15 17:25:40 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-function tests = sparse2cellTest()
-    tests = functiontests(localfunctions);
-end
-
-function testErrorNonMatchingDim(testCase)
-    in  = {
-        {magic(5), [1 2 3], [4]},
-        {magic(5), [1 1 1 1 1 1], [5]},
-        {magic(5), [5], [1 1 1 1 1 1]},
-        {ones(4,2),[2 3],[2]},
-        {ones(4,2),[2 2],[3]},
-    };
-
-    for i = 1:length(in)
-        testCase.verifyError(@()sparse2cell(in{i}{:}),'sparse2cell:NonMatchingDim');
-    end
-end
-
-function testOutput(testCase)
-    in = {};
-    out = {};
-    in{1}{1} =[17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22; 10 12 19 21 3; 11 18 25 2 9];
-    in{1}{2} = [1 4];
-    in{1}{3} = [2 3];
-
-    out{1} = {
-        [17 24], [1 8 15];
-        [23 5; 4 6; 10 12; 11 18], [7 14 16; 13 20 22; 19 21 3; 25 2 9];
-    };
-
-    in{1}{1} = [17 24 1 8 15; 23 5 0 0 0; 4 6 0 0 0; 10 12 0 0 0; 11 18 0 0 0];
-    in{1}{2} = [1 4];
-    in{1}{3} = [2 3];
-
-    out{1} = {
-        [17 24], [1 8 15];
-        [23 5; 4 6; 10 12; 11 18], [];
-    };
-
-    for i = 1:length(in)
-        testCase.verifyEqual(sparse2cell(in{i}{:}), out{i});
-    end
-end
\ No newline at end of file
--- a/vector2cell.m	Wed Jun 15 17:25:40 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-% Splits column vector v into segments of length n and returns the result as a column cell array.
-%   v  -- column vector to be split
-%   n  -- number of elements in each part
-%
-%   cv -- cell array of vectors with lenght n(i)
-function cv = vector2cell(v,n)
-    cv = cell(length(n),1);
-
-    ind = [0; cumsum(n)];
-    for i = 1:length(n)
-        ind_i = (ind(i)+1):ind(i+1);
-        cv{i} = v(ind_i);
-    end
-end
\ No newline at end of file