File: Mat.h

package info (click to toggle)
torch 2-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,488 kB
  • ctags: 3,217
  • sloc: cpp: 14,272; makefile: 201
file content (107 lines) | stat: -rw-r--r-- 2,701 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (C) 2002 Ronan Collobert (collober@iro.umontreal.ca)
//                
//
// This file is part of Torch. Release II.
// [The Ultimate Machine Learning Library]
//
// Torch is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Torch is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Torch; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#ifndef MAT_INC
#define MAT_INC

#include "Object.h"
#include "Vec.h"

namespace Torch {

/** Matrix object.

    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
class Mat : public Object
{
  public:

    /** #false# if #ptr# is not allocated by Mat.
        (With the first constructor)
    */
    bool ptr_is_allocated;
    
    /// Size of the matrix
    int m, n;
    
    /// Data of the matrix
    real **ptr;
    
    /** NULL if not allocated by Mat.
        (when you're using the first constructor of Mat, or for
        the matrix returned by subMat)
    */
    real *base;
    
    /** Create a matrix from values in #ptr_#.
        (No memory copy).
    */
    Mat(real ** ptr_, int n_rows, int n_cols);
    
    /// Create a new matrix
    Mat(int n_rows, int n_cols);
    
    /// Copy the matrix #mat#
    void copy(Mat * mat);
    
    /// Zero the matrix
    void zero();
    
    /// Compute the norm1
    real norm1();
    
    /// Compute the Frobenius norm
    real normFrobenius();
    
    /// Compute the norm inf
    real normInf();
    
    /** Return the row #row# of the matrix.
        If #vec# is NULL, return a new vector.
        Else copy the row in #vec#.
    */
    Vec *getRow(int row, Vec * vec = NULL);
    
    /** Return the column #col# of the matrix.
        If #vec# is NULL, return a new vector.
        Else copy the column in #vec#.
    */
    Vec *getCol(int col, Vec * vec = NULL);
    
    /// Set the row #row# to values in #vec#
    void setRow(int row, Vec * vec);
    
    /// Set the column #col# to values in #vec#
    void setCol(int row, Vec * vec);
    
    /** Return a sub-matrix.
        Note that the memory is shared with the original
        matrix, so *be carefull*.
    */
    Mat *subMat(int row1, int col1, int row2, int col2);

   ~Mat();
};


}

#endif