forked from translunar/nmatrix
/
dense.h
117 lines (90 loc) · 2.57 KB
/
dense.h
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
108
109
110
111
112
113
114
115
116
117
/////////////////////////////////////////////////////////////////////
// = NMatrix
//
// A linear algebra library for scientific computation in Ruby.
// NMatrix is part of SciRuby.
//
// NMatrix was originally inspired by and derived from NArray, by
// Masahiro Tanaka: http://narray.rubyforge.org
//
// == Copyright Information
//
// SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
// NMatrix is Copyright (c) 2012, Ruby Science Foundation
//
// Please see LICENSE.txt for additional copyright notices.
//
// == Contributing
//
// By contributing source code to SciRuby, you agree to be bound by
// our Contributor Agreement:
//
// * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
//
// == dense.h
//
// Dense n-dimensional matrix storage.
#ifndef DENSE_H
#define DENSE_H
/*
* Standard Includes
*/
#include <stdlib.h>
/*
* Project Includes
*/
#include "types.h"
//#include "util/math.h"
#include "data/data.h"
#include "common.h"
#include "nmatrix.h"
/*
* Macros
*/
/*
* Types
*/
/*
* Data
*/
extern "C" {
/*
* Functions
*/
///////////////
// Lifecycle //
///////////////
DENSE_STORAGE* nm_dense_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, void* elements, size_t elements_length);
void nm_dense_storage_delete(STORAGE* s);
void nm_dense_storage_delete_ref(STORAGE* s);
void nm_dense_storage_mark(void*);
///////////////
// Accessors //
///////////////
VALUE nm_dense_each(VALUE nmatrix);
void* nm_dense_storage_get(STORAGE* s, SLICE* slice);
void* nm_dense_storage_ref(STORAGE* s, SLICE* slice);
void nm_dense_storage_set(STORAGE* s, SLICE* slice, void* val);
///////////
// Tests //
///////////
bool nm_dense_storage_eqeq(const STORAGE* left, const STORAGE* right);
bool nm_dense_storage_is_symmetric(const DENSE_STORAGE* mat, int lda);
bool nm_dense_storage_is_hermitian(const DENSE_STORAGE* mat, int lda);
//////////
// Math //
//////////
STORAGE* nm_dense_storage_ew_op(nm::ewop_t op, const STORAGE* left, const STORAGE* right, VALUE scalar);
STORAGE* nm_dense_storage_matrix_multiply(const STORAGE_PAIR& casted_storage, size_t* resulting_shape, bool vector);
/////////////
// Utility //
/////////////
size_t nm_dense_storage_pos(const DENSE_STORAGE* s, const size_t* coords);
/////////////////////////
// Copying and Casting //
/////////////////////////
DENSE_STORAGE* nm_dense_storage_copy(const DENSE_STORAGE* rhs);
STORAGE* nm_dense_storage_copy_transposed(const STORAGE* rhs_base);
STORAGE* nm_dense_storage_cast_copy(const STORAGE* rhs, nm::dtype_t new_dtype);
} // end of extern "C" block
#endif // DENSE_H