architcture 86_64 error - objective-c

Getting this error:
which seems to be connected to this, but have no idea why:
// Inline
inline float onsetsds_phase_rewrap(float phase);
inline float onsetsds_phase_rewrap(float phase){
return (phase>MINUSPI && phase<PI) ? phase : phase + TWOPI * (1.f + floorf((MINUSPI - phase) * INV_TWOPI));
}
Any ideas?

Related

Mean or Sum of objective function matters in optimization?

I'm using RcppEnsmallen to estimate quantile regression models. I think I have set up everything right, but problems have been constantly emerging. I've tried two strategies:
Strategy 1: in the objective function, return sum of all errors. The corresponding gradient setup is similar. I tried 0.1 quantile in my example. However, occasionally I can get correct answers. Most of the time, it returns NaN.
Strategy 2: The objective function changed to mean of the sum of all errors. The gradient setup is also use the mean version. However, in this scenario, it returns quite different values each time, far from the correct answers.
I was wondering where the problem might be? Thanks.
#include <RcppEnsmallen.h>
// [[Rcpp::depends(RcppEnsmallen)]]
class QuantileRegressionFunction
{
public:
// Construct the QuantileRegressFunction with the given data.
QuantileRegressionFunction(const arma::mat& X,
const arma::colvec& y
) : X(X),y(y){}
// Define the objective function.
double Evaluate(const arma::mat& beta){
// arma::vec residual1 = y - X * beta;
return arma::sum( (y - X * beta) % ( 0.1 - arma::ones(y.n_rows) % ( (y - X * beta) <0 )) );
}
void Gradient(const arma::mat& beta, arma::mat& gradient)
{
gradient = -X.t() * ( 0.1 - arma::ones(y.n_rows) % ( (y - X * beta) <0 ) ) ;
}
private:
const arma::mat& X;
const arma::vec& y;
};
// [[Rcpp::export]]
arma::mat qr_reg(const arma::mat&X, const arma::vec&y){
QuantileRegressionFunction qrf(X,y);
ens::L_BFGS lbfgs;
lbfgs.MaxIterations()= 100000 ;
lbfgs.MaxLineSearchTrials() = 10000;
//lbfgs.ArmijoConstant() = 1e-10;
arma::mat beta(X.n_cols, 1 , arma::fill::randn);
lbfgs.Optimize(qrf,beta);
return beta;
}

Swift let computed property to Objective C syntax

I have this code in a Swift application and was curious of what its equivalent syntax would be in Objective C
typealias Signal = (Float) -> (Float)
static let sine: Signal = { (time: Float) -> Float in
return amplitude * sin(2.0 * Float.pi * frequency * time)
}
I believe I would declare Signal as follows:
typedef float (^Signal)(float);
but I am not sure how I would setup a similar way of setting up the syntax to retrieve the value. I thought about a class method but the didn't quite work out.
Thank you
This is not a computed property. This is a “closure”.
So this defines a type alias for a closure that takes a Float as a parameter and returns a Float:
typealias Signal = (Float) -> (Float)
You can create an instance of this Signal closure like so:
let doubler: Signal = { $0 * 2 }
And you can call that closure like so:
print(doubler(21)) // 42
The equivalent Objective-C syntax to define the type for a “block”:
typedef float (^Signal)(float);
To create an instance of a Signal block:
Signal doubler = ^(float input) {
return input * 2;
};
And to call it:
NSLog(#"%f", doubler(21)); // 42

SKTUtils Errors Galore

Added SKTUtils to my project and it just does not want to cooperate. I am afraid to change too much as I assumed it is coded a very specific way. Here is a few errors that I am getting and cannot figure out. Returning 20 errors then says too many errors, stopping now.
These return: "incompatible block pointer types initializing'_strong SKTTiming Function' AKA 'float(^_strong)(float) with an expression of type 'void'(^)(float)
Use of undeclared identifier 'M_PI_2',M_Pi
Implicitly declaring library function 'sqrtf' with type float(float)
SKTTimingFunction SKTTimingFunctionSineEaseIn = ^(float t) {
return sinf((t - 1.0f) * M_PI_2) + 1.0f;
};
SKTTimingFunction SKTTimingFunctionSineEaseOut = ^(float t) {
return sinf(t * M_PI_2);
};
SKTTimingFunction SKTTimingFunctionSineEaseInOut = ^(float t) {
return 0.5f * (1.0f - cosf(t * M_PI));
};
SKTTimingFunction SKTTimingFunctionCircularEaseIn = ^(float t) {
return 1.0f - sqrtf(1.0f - t * t);
};
Sounds like an old version of SKTUtils? M_Pi is no longer used.
I just created an Xcode 7.3.1 SpriteKit project and dropped in a clean SKTUtils, no issues.
SKUtils was updated not so long ago for 7.3
https://github.com/raywenderlich/SKTUtils

unexpected VARSYM in zimpl

I am getting an unexpected VARSYM in my Zimpl code. Here is a portion of my code:
param T := 0.8;
var S[Sensors] binary;
minimize nb_sensors : sum < i > in Sensors : S[ i ];
subto fd:
1- prod <k,l> in Sensors*Pipe : (1-ord(Proba[k,l],1,1) * S[k]) >= T;
It seems that the error is because I have a variable (S[]) which is inside the function (prod), do you have any idea about this issue?
What is T, a variable or a constant? Have you tried to write the product in brackets:
1- (prod <k,l> in Sensors*Pipe : (1-ord(Proba[k,l],1,1) * S[k])) >= T;
or to rewrite is as:
prod <k,l> in Sensors*Pipe : (1-ord(Proba[k,l],1,1) * S[k]) + T <= 1;

How to include freetype library to Keil uVision 4?

I have to add freetype library to keil uvision 4 for dealing ttf font files.
I followed the steps in Simple Glyph Loading Tutorial.
I am trying to compile the code below called example1.c. I tried the tutorial in Ubuntu terminal with the help of Undefined reference to 'FT_Init_FreeType'. It compiled without error.
But unfortunately I don't know how to link the library to keil.
It shows "Error: L6218E: Undefined symbol FT_Init_FreeType (referred from example1.o)."
Can anyone help me?
example1.c:
/* example1.c */
/* */
/* This small program shows how to print a rotated string with the */
/* FreeType 2 library. */
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#define WIDTH 640
#define HEIGHT 480
/* origin is the upper left corner */
unsigned char image[HEIGHT][WIDTH];
/* Replace this function with something useful. */
void
draw_bitmap( FT_Bitmap* bitmap,
FT_Int x,
FT_Int y)
{
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
for ( i = x, p = 0; i < x_max; i++, p++ )
{
for ( j = y, q = 0; j < y_max; j++, q++ )
{
if ( i < 0 || j < 0 ||
i >= WIDTH || j >= HEIGHT )
continue;
image[j][i] |= bitmap->buffer[q * bitmap->width + p];
}
}
}
void
show_image( void )
{
int i, j;
for ( i = 0; i < HEIGHT; i++ )
{
for ( j = 0; j < WIDTH; j++ )
putchar( image[i][j] == 0 ? ' '
: image[i][j] < 128 ? '+'
: '*' );
putchar( '\n' );
}
}
int
main( int argc,
char** argv )
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
char* filename;
char* text;
double angle;
int target_height;
int n, num_chars;
if ( argc != 3 )
{
fprintf ( stderr, "usage: %s font sample-text\n", argv[0] );
exit( 1 );
}
filename = argv[1]; /* first argument */
text = argv[2]; /* second argument */
num_chars = strlen( text );
angle = ( 25.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */
target_height = HEIGHT;
error = FT_Init_FreeType( &library ); /* initialize library */
/* error handling omitted */
error = FT_New_Face( library, filename, 0, &face );/* create face object */
/* error handling omitted */
/* use 50pt at 100dpi */
error = FT_Set_Char_Size( face, 50 * 64, 0,
100, 0 ); /* set character size */
/* error handling omitted */
slot = face->glyph;
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
/* the pen position in 26.6 cartesian space coordinates; */
/* start at (300,200) relative to the upper left corner */
pen.x = 300 * 64;
pen.y = ( target_height - 200 ) * 64;
for ( n = 0; n < num_chars; n++ )
{
/* set transformation */
FT_Set_Transform( face, &matrix, &pen );
/* load glyph image into the slot (erase previous one) */
error = FT_Load_Char( face, text[n], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */
/* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
target_height - slot->bitmap_top );
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
show_image();
FT_Done_Face ( face );
FT_Done_FreeType( library );
return 0;
}
Create a new project "freetype". In the project settings change the "Output" to a static library:
Add the freetype sources to the project, and build. Do not use your "amalgamated" source file - that will destroy the library granularity and lead to excessively large code.
Add the resulting freetype.lib file to your application project. The linker will select only those modules from the library that are necessary to resolve references in your application thus keeping size to a minimum.
You may get smaller code size from including the freetype source directly in your application and using cross-module optimisation (this will work regardless of the use of separate compilation or the amalgamated file); however the build time may be excessive as it requires repeated full-builds to fully optimise. Note that unlike compiler-optimisation, cross-module optimisation does not affect the debugging experience - you can use the debugger normally even with it enabled.
EDIT :
The cross-module optimisation feature may not apply when using the GNU toolchain; it refers to the use of Keil MDK-ARM which uses ARM's RealView toolchain. Other aspects of this answer may also be applicable only to MDK-ARM.
After a long research I could find an alternate solution for the problem. I could reach at freetype amalgamate project, which one is the exact solution for this .
Here all the source files are amalgamated into two files. One ".c" file and one ".h" file. So it can be easily integrate into any other project.
Here is the link for freetype amalgamate.
Thank you.