This file is indexed.

/usr/include/vmmlib/tucker3_importer.hpp is in libvmmlib-dev 1.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* 
 * VMMLib - Tensor Classes
 *  
 * @author Susanne Suter
 *
 * Import tool for Tucker3 tensor and quantized Tucker3 tensor
 * 
 */


#ifndef __VMML__TUCK3_IMPORTER__HPP__
#define __VMML__TUCK3_IMPORTER__HPP__

#include <vmmlib/qtucker3_tensor.hpp>

/* FIXME:
 *
 * - T_internal
 */


namespace vmml
{
	
	template< size_t R1, size_t R2, size_t R3, size_t I1, size_t I2, size_t I3, typename T_value = float, typename T_coeff = float >
	class tucker3_importer
	{
	public:    
		
		typedef float T_internal; //FIXME! should match with tucker3 tensor

		typedef tucker3_tensor< R1, R2, R3, I1, I2, I3, T_value, T_coeff > tucker3_type;
		typedef qtucker3_tensor< R1, R2, R3, I1, I2, I3, T_value, T_coeff > qtucker3_type;
		
		typedef tensor3< R1, R2, R3, T_coeff > t3_core_type;
		typedef typename t3_core_type::iterator t3_core_iterator;
		typedef typename t3_core_type::const_iterator t3_core_const_iterator;
		
		typedef matrix< I1, R1, T_coeff > u1_type;
		typedef typename u1_type::iterator u1_iterator;
		typedef typename u1_type::const_iterator u1_const_iterator;
		
		typedef matrix< I2, R2, T_coeff > u2_type;
		typedef typename u2_type::iterator u2_iterator;
		typedef typename u2_type::const_iterator u2_const_iterator;
		
		typedef matrix< I3, R3, T_coeff > u3_type;
		typedef typename u3_type::iterator u3_iterator;
		typedef typename u3_type::const_iterator u3_const_iterator;
		
		typedef matrix< R1, R2, T_coeff > front_core_slice_type; //fwd: forward cylcling (after kiers et al., 2000)

		typedef tensor3< R1, R2, R3, char > t3_core_signs_type;
		
		template< typename T >
		static void import_from( const std::vector< T >& data_, tucker3_type& tuck3_data_ );
		
		//previous version, but works only with 16bit quantization
		static void import_quantized_from( const std::vector<unsigned char>& data_in_, qtucker3_type& tuck3_data_  );
		
		//use this version, works with a better quantization for the core tensor:
		//logarithmic quantization and separate high energy core vale
		//suitable for voxelwise reconstruction
		static void import_hot_quantized_from( const std::vector<unsigned char>& data_in_, qtucker3_type& tuck3_data_  );
		
		//use this version for the ttm export/import (core: backward cyclic), without plain hot value 
		static void import_ttm_quantized_from( const std::vector<unsigned char>& data_in_, qtucker3_type& tuck3_data_  );
		
		
	}; //end tucker3 importer class
	
#define VMML_TEMPLATE_STRING        template< size_t R1, size_t R2, size_t R3, size_t I1, size_t I2, size_t I3, typename T_value, typename T_coeff >
#define VMML_TEMPLATE_CLASSNAME     tucker3_importer< R1, R2, R3, I1, I2, I3, T_value, T_coeff >
	
	
VMML_TEMPLATE_STRING
template< typename T >
void
VMML_TEMPLATE_CLASSNAME::import_from( const std::vector< T >& data_, tucker3_type& tuck3_data_  )
{
	size_t i = 0; //iterator over data_
	size_t data_size = (size_t) data_.size();
	
	if ( data_size != tuck3_data_.SIZE  )
		VMMLIB_ERROR( "import_from: the input data must have the size R1xR2xR3 + R1xI1 + R2xI2 + R3xI3 ", VMMLIB_HERE );
	
	u1_type* u1 = new u1_type;
	u2_type* u2 = new u2_type;
	u3_type* u3 = new u3_type;
	t3_core_type core;
	
	tuck3_data_.get_u1( *u1 );
	tuck3_data_.get_u2( *u2 );
	tuck3_data_.get_u3( *u3 );
	tuck3_data_.get_core( core );
	
	u1_iterator  it = u1->begin(),
	it_end = u1->end();
	for( ; it != it_end; ++it, ++i )
	{
		*it = static_cast< T >( data_.at(i));
	}
	
	
	u2_iterator  u2_it = u2->begin(),
	u2_it_end = u2->end();
	for( ; u2_it != u2_it_end; ++u2_it, ++i )
	{
		*u2_it = static_cast< T >( data_.at(i));
	}
	
	u3_iterator  u3_it = u3->begin(),
	u3_it_end = u3->end();
	for( ; u3_it != u3_it_end; ++u3_it, ++i )
	{
		*u3_it = static_cast< T >( data_.at(i));
	}
	
	t3_core_iterator  it_core = core.begin(),
	it_core_end = core.end();
	for( ; it_core != it_core_end; ++it_core, ++i )
	{
		*it_core = static_cast< T >( data_.at(i));
	}
	
	tuck3_data_.set_u1( *u1 );
	tuck3_data_.set_u2( *u2 );
	tuck3_data_.set_u3( *u3 );
	tuck3_data_.set_core( core );
	
	tuck3_data_.cast_comp_members();
	
	delete u1;
	delete u2;
	delete u3;
}
	

VMML_TEMPLATE_STRING
void
VMML_TEMPLATE_CLASSNAME::import_quantized_from( const std::vector<unsigned char>& data_in_, qtucker3_type& tuck3_data_   )
{
	size_t end_data = 0;
	size_t len_t_comp = sizeof( T_internal );
	size_t len_export_data = tuck3_data_.SIZE * sizeof(T_coeff) + 8 * len_t_comp;
	unsigned char * data = new unsigned char[ len_export_data ]; 
	for( size_t byte = 0; byte < len_export_data; ++byte )
	{
		data[byte] = data_in_.at(byte);
	}
	
	//copy min and max values: u1_min, u1_max, u2_min, u2_max, u3_min, u3_max, core_min, core_max
	T_internal u_min = 0; T_internal u_max = 0;
	memcpy( &u_min, data, len_t_comp ); end_data = len_t_comp;
	memcpy( &u_max, data + end_data, len_t_comp ); end_data += len_t_comp;
	
	T_internal core_min = 0; T_internal core_max = 0;
	memcpy( &core_min, data + end_data, len_t_comp ); end_data += len_t_comp;
	memcpy( &core_max, data + end_data, len_t_comp ); end_data += len_t_comp;
	
	u1_type* u1 = new u1_type;
	u2_type* u2 = new u2_type;
	u3_type* u3 = new u3_type;
	t3_core_type core;
	
	tuck3_data_.get_u1( *u1 );
	tuck3_data_.get_u2( *u2 );
	tuck3_data_.get_u3( *u3 );
	tuck3_data_.get_core( core );

	//copy data to u1
	size_t len_u1 = I1 * R1 * sizeof( T_coeff );
	memcpy( *u1, data + end_data, len_u1 ); end_data += len_u1;
	
	//copy data to u2
	size_t len_u2 = I2 * R2 * sizeof( T_coeff );
	memcpy( *u2, data + end_data, len_u2 ); end_data += len_u2;
	
	//copy data to u3
	size_t len_u3 = I3 * R3 * sizeof( T_coeff );
	memcpy( *u3, data + end_data, len_u3 ); end_data += len_u3;
	
	//copy data to core
	size_t len_core_slice = R1 * R2 * sizeof( T_coeff );
	front_core_slice_type* slice = new front_core_slice_type();
	for (size_t r3 = 0; r3 < R3; ++r3 ) {
		memcpy( slice, data + end_data, len_core_slice );
		core.set_frontal_slice_fwd( r3, *slice );
		end_data += len_core_slice;
	}
	
	tuck3_data_.set_u1( *u1 );
	tuck3_data_.set_u2( *u2 );
	tuck3_data_.set_u3( *u3 );
	tuck3_data_.set_core( core );
	
	//dequantize tucker3 components (u1-u3 and core)
	tuck3_data_.dequantize_basis_matrices( u_min, u_max, u_min, u_max, u_min, u_max  );
	tuck3_data_.dequantize_core( core_min, core_max );	
	
	delete slice;
	delete[] data;
	delete u1;
	delete u2;
	delete u3;
}
	
	

VMML_TEMPLATE_STRING
void
VMML_TEMPLATE_CLASSNAME::import_hot_quantized_from( const std::vector<unsigned char>& data_in_, qtucker3_type& tuck3_data_   )
{
	tuck3_data_.enable_quantify_hot();
	size_t end_data = 0;
	size_t len_t_comp = sizeof( T_internal );
	size_t len_export_data = R1*R2*R3 + (R1*I1 + R2*I2 + R3*I3) * sizeof(T_coeff) + 4 * len_t_comp;
	unsigned char * data = new unsigned char[ len_export_data ];
	for( size_t byte = 0; byte < len_export_data; ++byte )
	{
		data[byte] = data_in_.at(byte);
	}
	
	//copy min and max values: u1_min, u1_max, u2_min, u2_max, u3_min, u3_max, core_min, core_max
	T_internal u_min = 0; T_internal u_max = 0;
	memcpy( &u_min, data, len_t_comp ); end_data = len_t_comp;
	memcpy( &u_max, data + end_data, len_t_comp ); end_data += len_t_comp;
	
	T_internal core_min = 0; T_internal core_max = 0; //core_min is 0
	//memcpy( &core_min, data + end_data, len_t_comp ); end_data += len_t_comp;
	memcpy( &core_max, data + end_data, len_t_comp ); end_data += len_t_comp;
	//copy first value of core tensor separately as a float
	T_internal hottest_value = 0;
	memcpy( &hottest_value, data + end_data, len_t_comp ); end_data += len_t_comp;
	tuck3_data_.set_hottest_value( hottest_value );
	
	u1_type* u1 = new u1_type;
	u2_type* u2 = new u2_type;
	u3_type* u3 = new u3_type;
	t3_core_type core;
	t3_core_signs_type signs;
	
	tuck3_data_.get_u1( *u1 );
	tuck3_data_.get_u2( *u2 );
	tuck3_data_.get_u3( *u3 );
	tuck3_data_.get_core( core );
	tuck3_data_.get_core_signs( signs );
	
	//copy data to u1
	size_t len_u1 = I1 * R1 * sizeof( T_coeff );
	memcpy( *u1, data + end_data, len_u1 ); end_data += len_u1;
	
	//copy data to u2
	size_t len_u2 = I2 * R2 * sizeof( T_coeff );
	memcpy( *u2, data + end_data, len_u2 ); end_data += len_u2;
	
	//copy data to u3
	size_t len_u3 = I3 * R3 * sizeof( T_coeff );
	memcpy( *u3, data + end_data, len_u3 ); end_data += len_u3;
	
	//copy data to core
	size_t len_core_el = 1; //currently 1 bit for sign and 7 bit for values
	
	unsigned char core_el;
	for (size_t r3 = 0; r3 < R3; ++r3 ) {
		for (size_t r2 = 0; r2 < R2; ++r2 ) {
			for (size_t r1 = 0; r1 < R1; ++r1 ) {
				memcpy( &core_el, data + end_data, len_core_el );
				signs.at( r1, r2, r3 ) = (core_el & 0x80)/128;
				core.at( r1, r2, r3 ) = core_el & 0x7f ;
				++end_data;
			}
		}
	} 
	
	tuck3_data_.set_u1( *u1 );
	tuck3_data_.set_u2( *u2 );
	tuck3_data_.set_u3( *u3 );
	tuck3_data_.set_core( core );
	tuck3_data_.set_core_signs( signs );

	//dequantize tucker3 components (u1-u3 and core)
	tuck3_data_.dequantize_basis_matrices( u_min, u_max, u_min, u_max, u_min, u_max  );
	tuck3_data_.dequantize_core( core_min, core_max );	

	delete[] data;
	delete u1;
	delete u2;
	delete u3;
}
	
	
VMML_TEMPLATE_STRING
void
VMML_TEMPLATE_CLASSNAME::import_ttm_quantized_from( const std::vector<unsigned char>& data_in_, qtucker3_type& tuck3_data_   )
{
	tuck3_data_.enable_quantify_log();
	size_t end_data = 0;
	size_t len_t_comp = sizeof( T_internal );
	size_t len_export_data = R1*R2*R3 + (R1*I1 + R2*I2 + R3*I3) * sizeof(T_coeff) + 3 * len_t_comp;
	unsigned char * data = new unsigned char[ len_export_data ];
	for( size_t byte = 0; byte < len_export_data; ++byte )
	{
		data[byte] = data_in_.at(byte);
	}
	
	//copy min and max values: u1_min, u1_max, u2_min, u2_max, u3_min, u3_max, core_min, core_max
	T_internal u_min = 0; T_internal u_max = 0;
	memcpy( &u_min, data, len_t_comp ); end_data = len_t_comp;
	memcpy( &u_max, data + end_data, len_t_comp ); end_data += len_t_comp;
	
	T_internal core_min = 0; T_internal core_max = 0; //core_min is 0
	//memcpy( &core_min, data + end_data, len_t_comp ); end_data += len_t_comp;
	memcpy( &core_max, data + end_data, len_t_comp ); end_data += len_t_comp;
	
	u1_type* u1 = new u1_type;
	u2_type* u2 = new u2_type;
	u3_type* u3 = new u3_type;
	t3_core_type core;
	t3_core_signs_type signs;
	
	tuck3_data_.get_u1( *u1 );
	tuck3_data_.get_u2( *u2 );
	tuck3_data_.get_u3( *u3 );
	tuck3_data_.get_core( core );
	tuck3_data_.get_core_signs( signs );
	
	//copy data to u1
	size_t len_u1 = I1 * R1 * sizeof( T_coeff );
	memcpy( *u1, data + end_data, len_u1 ); end_data += len_u1;
	
	//copy data to u2
	size_t len_u2 = I2 * R2 * sizeof( T_coeff );
	memcpy( *u2, data + end_data, len_u2 ); end_data += len_u2;
	
	//copy data to u3
	size_t len_u3 = I3 * R3 * sizeof( T_coeff );
	memcpy( *u3, data + end_data, len_u3 ); end_data += len_u3;
	
	//copy data to core
	size_t len_core_el = 1; //currently 1 bit for sign and 7 bit for values
	
	//backward cyclic after lathauwer et al. 
	unsigned char core_el;
	for (size_t r2 = 0; r2 < R2; ++r2 ) {
		for (size_t r3 = 0; r3 < R3; ++r3 ) {
			for (size_t r1 = 0; r1 < R1; ++r1 ) {
				memcpy( &core_el, data + end_data, len_core_el );
				signs.at( r1, r2, r3 ) = (core_el & 0x80)/128;
				core.at( r1, r2, r3 ) = core_el & 0x7f ;
				++end_data;
			}
		}
	} 
	//std::cout << "signs: " << _signs << std::endl;
	//std::cout << "_core: " << _core << std::endl;
	
	delete[] data;
	
	tuck3_data_.set_u1( *u1 );
	tuck3_data_.set_u2( *u2 );
	tuck3_data_.set_u3( *u3 );
	tuck3_data_.set_core( core );
	tuck3_data_.set_core_signs( signs );

	//dequantize tucker3 components (u1-u3 and core)
	tuck3_data_.dequantize_basis_matrices( u_min, u_max, u_min, u_max, u_min, u_max  );
	tuck3_data_.dequantize_core( core_min, core_max );	

	delete u1;
	delete u2;
	delete u3;	
}
	
#undef VMML_TEMPLATE_STRING
#undef VMML_TEMPLATE_CLASSNAME

	
} // namespace vmml

	
	
#endif