1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef bts_INT32MAT_EM_H
18#define bts_INT32MAT_EM_H
19
20/* ---- includes ----------------------------------------------------------- */
21
22#include "b_BasicEm/Int32Arr.h"
23
24/* ---- related objects  --------------------------------------------------- */
25
26/* ---- typedefs ----------------------------------------------------------- */
27
28/* ---- constants ---------------------------------------------------------- */
29
30/* data format version number */
31#define bts_INT32MAT_VERSION 100
32
33/* ---- object definition -------------------------------------------------- */
34
35/** square matrix */
36struct bts_Int32Mat
37{
38
39	/* ---- private data --------------------------------------------------- */
40
41	/* ---- public data ---------------------------------------------------- */
42
43	/* width = height of square matrix */
44	uint32 widthE;
45
46	/* array of matrix elements (data is arranged by rows) */
47	struct bbs_Int32Arr arrE;
48
49};
50
51/* ---- associated objects ------------------------------------------------- */
52
53/* ---- external functions ------------------------------------------------- */
54
55/* ---- \ghd{ constructor/destructor } ------------------------------------- */
56
57/** initializes matrix */
58void bts_Int32Mat_init( struct bbs_Context* cpA,
59					    struct bts_Int32Mat* ptrA );
60
61/** destroys matric */
62void bts_Int32Mat_exit( struct bbs_Context* cpA,
63					    struct bts_Int32Mat* ptrA );
64
65/* ---- \ghd{ operators } -------------------------------------------------- */
66
67/* copies matrices */
68void bts_Int32Mat_copy( struct bbs_Context* cpA,
69					    struct bts_Int32Mat* ptrA,
70						const struct bts_Int32Mat* srcPtrA );
71
72/* ---- \ghd{ query functions } -------------------------------------------- */
73
74/* ---- \ghd{ modify functions } ------------------------------------------- */
75
76/** allocates square matrix */
77void bts_Int32Mat_create( struct bbs_Context* cpA,
78						  struct bts_Int32Mat* ptrA,
79						  int32 widthA,
80				          struct bbs_MemSeg* mspA );
81
82/* ---- \ghd{ memory I/O } ------------------------------------------------- */
83
84/** size object needs when written to memory */
85uint32 bts_Int32Mat_memSize( struct bbs_Context* cpA,
86							 const struct bts_Int32Mat* ptrA );
87
88/** writes object to memory; returns number of bytes written */
89uint32 bts_Int32Mat_memWrite( struct bbs_Context* cpA,
90							  const struct bts_Int32Mat* ptrA,
91							  uint16* memPtrA );
92
93/** reads object from memory; returns number of bytes read */
94uint32 bts_Int32Mat_memRead( struct bbs_Context* cpA,
95							 struct bts_Int32Mat* ptrA,
96							 const uint16* memPtrA,
97				             struct bbs_MemSeg* mspA );
98
99/* ---- \ghd{ exec functions } --------------------------------------------- */
100
101/** computes the solution to  matrix * outVecA = inVecA,  returns false if the
102 *	function was not successful;
103 *	internally calls solve2() which is overflow safe;
104 *	use large bbpA if you need high accuracy;
105 *
106 *	matA: the square matrix, array of size ( matWidthA * matWidthA )
107 *	matWidthA: width of the matrix
108 *  inVecA:  array of size matWidthA
109 *  outVecA: array of size matWidthA
110 *	bbpA: bbp for all matrices and vectors
111 *	tmpMatA: matrix of same size as matA
112 *  tmpVecA: array of size matWidthA
113 */
114flag bts_Int32Mat_solve( struct bbs_Context* cpA,
115						 const int32* matA,
116						 int32 matWidthA,
117						 const int32* inVecA,
118						 int32* outVecA,
119						 int32 bbpA,
120						 int32* tmpMatA,
121						 int32* tmpVecA );
122
123/**	same as _solve(), but matA gets overwritten, and tmpMatA is not needed:
124 *	saves memory when matA is large;
125 *	overflow safe;
126 *	use large bbpA if you need high accuracy;
127 */
128flag bts_Int32Mat_solve2( struct bbs_Context* cpA,
129						  int32* matA,
130						  int32 matWidthA,
131						  const int32* inVecA,
132						  int32* outVecA,
133						  int32 bbpA,
134						  int32* tmpVecA );
135
136#endif /* bts_INT32MAT_EM_H */
137
138