File: features_int8.c

package info (click to toggle)
libocas 0.97%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,760 kB
  • sloc: ansic: 7,956; makefile: 103; sh: 7
file content (89 lines) | stat: -rw-r--r-- 2,336 bytes parent folder | download | duplicates (5)
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
/*-----------------------------------------------------------------------
 * features_int8.c: Helper functions for the OCAS solver working with 
 *                 INT8 features.
 *-------------------------------------------------------------------- */

#include <stdint.h>
#include <string.h>

#include "ocas_helper.h"
#include "features_int8.h"


/*----------------------------------------------------------------------------------
  full_add_new_cut( new_col_H, new_cut, cut_length, nSel ) does the following:

    new_a = sum(data_X(:,find(new_cut ~=0 )),2);
    new_col_H = [full_A(:,1:nSel)'*new_a ; new_a'*new_a];
    full_A(:,nSel+1) = new_a;

  ---------------------------------------------------------------------------------*/
int full_int8_add_new_cut( double *new_col_H, 
                           uint32_t *new_cut, 
                           uint32_t cut_length, 
                           uint32_t nSel,
                           void* user_data)
{
/*  double *new_a, */
  double sq_norm_a;
  uint32_t i, j;
  int8_t *ptr;

  ptr = (int8_t*)mxGetPr(data_X);

  memset(new_a, 0, sizeof(double)*nDim);


  for(i=0; i < cut_length; i++) {
    for(j=0; j < nDim; j++ ) {
      new_a[j] += (double)ptr[LIBOCAS_INDEX(j,new_cut[i],nDim)];
    }

    A0[nSel] += X0*data_y[new_cut[i]];    
  }

  /* compute new_a'*new_a and insert new_a to the last column of full_A */
  sq_norm_a = A0[nSel]*A0[nSel];
  for(j=0; j < nDim; j++ ) {
    sq_norm_a += new_a[j]*new_a[j];
    full_A[LIBOCAS_INDEX(j,nSel,nDim)] = new_a[j];
  }

  new_col_H[nSel] = sq_norm_a;
  for(i=0; i < nSel; i++) {
    double tmp = A0[nSel]*A0[i];

    for(j=0; j < nDim; j++ ) {
      tmp += new_a[j]*full_A[LIBOCAS_INDEX(j,i,nDim)];
    }
    new_col_H[i] = tmp;
  }

  return 0;
}

/*----------------------------------------------------------------------
  full_int8_compute_output( output ) does the follwing:

  output = data_X'*W;
  ----------------------------------------------------------------------*/
int full_int8_compute_output( double *output, void* user_data )
{
  uint32_t i, j;
  double tmp;
  int8_t* ptr;

  ptr = (int8_t*)mxGetPr( data_X );

  for(i=0; i < nData; i++) { 
    tmp = data_y[i]*X0*W0;

    for(j=0; j < nDim; j++ ) {
      tmp += W[j]*(double)ptr[LIBOCAS_INDEX(j,i,nDim)];
    }
    output[i] = tmp;
  }
  
  return 0;
}