Xcode 6, iOS 8, Cocoa Touch Framework Bi directional frameworks / cyclic dependency error - ios

My first time to post in here. Can't find any answer anywhere on my question. Please anyone:
I used earlier the iOS-Universal-Framework / fake framework to build two big frameworks, that depends of each other. So f.x. just to clarify:
Framework 1 (F1) has class A, B, C, ...
Framework 2 (F2) has class D, E, F, ...
So, what I normally did was to:
1) compile F1 with a global macro 'ENABLE_F2_METHODS_AND_TYPES' = 0
2) then moved to F2 and compiled F2 similarly with a macro 'ENABLE_F1_METHODS_AND_TYPES' = 0
Now both framework exists with class, types, etc.
3) compile F1 with macro = 1
4) compile F2 with macro = 1
That was all.
Now, the iOS-Universal-Framework is deprecated, and I have decided to move the frameworks into Cocoa Touch frameworks. So, at this moment, I have two Touch frameworks, but if I try to do similar approach, I successfully compile the two first steps, but not the third step.
I try to do some different attempts but didn't succeed.
I get the error:
Cannot find interface declaration for 'B' superclass of 'D';
so, what I tried is to add the #import "<F1/B.h>", but then get the error
Cyclic dependency in module 'F2': F2 -> F1 -> F2
How to solve this? Any other ideas?
IF succeeded, how to avoid that the frameworks is not going to be integrated into each other (Umbrella framework), but standalone frameworks. What I mean, in the
'Project' -> General -> 'Linked Frameworks and Libraries' -> I can choose "Required/Optional'.... Will that help or?
Thanks in advance.

Related

Creating a simple Rcpp package with dependency with other Rcpp package

I am trying to improve my loop computation speed by using foreach, but there is a simple Rcpp function I defined inside of this loop. I saved the Rcpp function as mproduct.cpp, and I call out the function simply using
sourceCpp("mproduct.cpp")
and the Rcpp function is a simple one, which is to perform matrix product in C++:
// [[Rcpp::depends(RcppArmadillo, RcppEigen)]]
#include <RcppArmadillo.h>
#include <RcppEigen.h>
// [[Rcpp::export]]
SEXP MP(const Eigen::Map<Eigen::MatrixXd> A, Eigen::Map<Eigen::MatrixXd> B){
Eigen::MatrixXd C = A * B;
return Rcpp::wrap(C);
}
So, the function in the Rcpp file is MP, referring to matrix product. I need to perform the following foreach loop (I have simplified the code for illustration):
foreach(j=1:n, .package='Rcpp',.noexport= c("mproduct.cpp"),.combine=rbind)%dopar%{
n=1000000
A<-matrix(rnorm(n,1000,1000))
B<-matrix(rnorm(n,1000,1000))
S<-MP(A,B)
return(S)
}
Since the size of matrix A and B are large, it is why I want to use foreach to alleviate the computational cost.
However, the above code does not work, since it provides me error message:
task 1 failed - "NULL value passed as symbol address"
The reason I added .noexport= c("mproduct.cpp") is to follow some suggestions from people who solved similar issues (Can't run Rcpp function in foreach - "NULL value passed as symbol address"). But somehow this does not solve my issue.
So I tried to install my Rcpp function as a library. I used the following code:
Rcpp.package.skeleton('mp',cpp_files = "<my working directory>")
but it returns me a warning message:
The following packages are referenced using Rcpp::depends attributes however are not listed in the Depends, Imports or LinkingTo fields of the package DESCRIPTION file: RcppArmadillo, RcppEigen
so when I tried to install my package using
install.packages("<my working directory>",repos = NULL,type='source')
I got the warning message:
Error in untar2(tarfile, files, list, exdir, restore_times) :
incomplete block on file
In R CMD INSTALL
Warning in install.packages :
installation of package ‘C:/Users/Lenovo/Documents/mproduct.cpp’ had non-zero exit status
So can someone help me out how to solve 1) using foreach with Rcpp function MP, or 2) install the Rcpp file as a package?
Thank you all very much.
The first step would be making sure that you are optimizing the right thing. For me, this would not be the case as this simple benchmark shows:
set.seed(42)
n <- 1000
A<-matrix(rnorm(n*n), n, n)
B<-matrix(rnorm(n*n), n, n)
MP <- Rcpp::cppFunction("SEXP MP(const Eigen::Map<Eigen::MatrixXd> A, Eigen::Map<Eigen::MatrixXd> B){
Eigen::MatrixXd C = A * B;
return Rcpp::wrap(C);
}", depends = "RcppEigen")
bench::mark(MP(A, B), A %*% B)[1:5]
#> # A tibble: 2 x 5
#> expression min median `itr/sec` mem_alloc
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt>
#> 1 MP(A, B) 277.8ms 278ms 3.60 7.63MB
#> 2 A %*% B 37.4ms 39ms 22.8 7.63MB
So for me the matrix product via %*% is several times faster than the one via RcppEigen. However, I am using Linux with OpenBLAS for matrix operations while you are on Windows, which often means reference BLAS for matrix operations. It might be that RcppEigen is faster on your system. I am not sure how difficult it is for Windows user to get a faster BLAS implementation (https://csgillespie.github.io/efficientR/set-up.html#blas-and-alternative-r-interpreters might contain some pointers), but I would suggest spending some time on investigating this.
Now if you come to the conclusion that you do need RcppEigen or RcppArmadillo in your code and want to put that code into a package, you can do the following. Instead of Rcpp::Rcpp.package.skeleton() use RcppEigen::RcppEigen.package.skeleton() or RcppArmadillo::RcppArmadillo.package.skeleton() to create a starting point for a package based on RcppEigen or RcppArmadillo, respectively.

Is there an equivalant for Griddata or ScatteredInterpolant in Obj-c or Swift?

I have a set of data for example:
X Y Z
1 3 7
2 5 8
1 4 9
3 6 10
I would like to interpolate Z for X=2.5 and Y=3.5.
I can use interp2.griddata from Scipy in Python or ScatteredInterpolant in Matlab like this:
z = griddata( [1 2 1 3], [3 5 4 6], [7 8 9 10], 2.5, 3.5, 'nearest' )
or
S = scatteredInterpolant(x,y,z,d);
Is there a way i could use something similar in Swift/Objective-c or any other compatible language to develop a small app for iOS (as well as for Android if possible) where i insert scattered data and when the user enter a value for a given X and Y he gets an interpolated value for Z (i intend to use this with 4D dimension).
Maybe my answer is late, but I hope it will be useful in the future.
The easiest way to combine two ios languages in one project is to create a bridge header file. If your project does not have a bridge header file yet, Xcode will ask you if the bridge header file should be created. You can also create it manually: just create an Objective-C header file, for example “Bridging-Header.h”. Then go to the “Swift Compiler - Code Generation” section in the build settings and set the bridge header file name in the “Objective-C Bridging Header” field.
Good luck

Unit Test a submodule static function in iOS? (Swift 4 - Xcode)

I have 4 submodules in my iOS project (Project A).
In one submodule (X Submodule) I have a class with a static function that get as input an Object defined in another submodule (Y submodule) and return a String.
How and where do I write a unit test for this static function logic? Do I write the logic in one of the App projects (A, B, C iOS Projects) that re-use those submodules (X, Y submodules)?
If you have any suggestion it will be highly appreaciated!
Just as you've created multiple frameworks for your app, you can create multiple test targets. It probably makes sense to create a test target in your X subproject that validates the X submodule.

Binding redirect at compile time for strong named assembly

We have a question about assembly binding redirection at compile time:
Team V (the Veterans) is developing Product P1
P1 is continuously developed by Team V in two branches (branch 1.6.x and 1.7.x), so the version from Product P1 is incrementing over time in both branches
Team NG (New Generation) has built a Product P2 based on Product P1 (using certain assemblies from P1 branch 1.7)
Product P2 contains an Assembly A2 (strongly named) that helps implementing any Product (P2, P3...) that is based on P1
Team NG created a Nuget Package for Assembly A2 (which is referring certain assemblies from P1 branch 1.7)
Now, Team NG has started Product P3 and has to use Assembly A2 from P2 and an Assembly A1 from P1
Assembly A1 from P1 is also available as Nuget Package, but in version 1.6 (because 1.7 is not approved yet for Product P3)
So Team NG has now Product P3 with two references: A2 and A1
The problem now is, that A2 refers A1 in version 1.7 but we only have A1 in version 1.6
Team NG is not allowed to use A1 in version 1.7
This is why we are looking for a binding redirect at compile time for strongly named assemblies. As far as I know (by investigations), the 'Specific Version' property has no effect when setting this for a strongly named assembly.
Is such a redirection possible or are there any other suggestions?
Many thanks in advance
Regards, Michael
The bindingRedirect element of app.config/web.config files applies to runtime only (not compile-time).
At compile-time, the compiler does not insist on references having like version numbers, unless a reference has the SpecificVersion element set to True in a project file.
Strong-naming vs. non-strong-naming shouldn't be a factor with this.
See also How exactly does the "Specific Version" property of an assembly reference work in Visual Studio?

How does the Erlang compiler handle pattern matching? What does it output?

I just asked a question about how the Erlang compiler implements pattern matching, and I got some great responses, one of which is the compiled bytecode (obtained with a parameter passed to the c() directive):
{function, match, 1, 2}.
{label,1}.
{func_info,{atom,match},{atom,match},1}.
{label,2}.
{test,is_tuple,{f,3},[{x,0}]}.
{test,test_arity,{f,3},[{x,0},2]}.
{get_tuple_element,{x,0},0,{x,1}}.
{test,is_eq_exact,{f,3},[{x,1},{atom,a}]}.
return.
{label,3}.
{badmatch,{x,0}}
Its all just plain Erlang tuples. I was expecting some cryptic binary thingy, guess not. I am asking this on impulse here (I could look at the compiler source but asking questions always ends up better with extra insight), how is this output translated in the binary level?
Say {test,is_tuple,{f,3},[{x,0}]} for example. I am assuming this is one instruction, called 'test'... anyway, so this output would essentially be the AST of the bytecode level language, from which the binary encoding is just a 1-1 translation?
This is all so exciting, I had no idea that I can this easily see what the Erlang compiler break things into.
ok so I dug into the compiler source code to find the answer, and to my surprise the asm file produced with the 'S' parameter to the compile:file() function is actually consulted in as is (file:consult()) and then the tuples are checked one by one for further action(line 661 - beam_consult_asm(St) -> - compile.erl). further on then there's a generated mapping table in there (compile folder of the erlang source) that shows what the serial number of each bytecode label is, and Im guessing this is used to generate the actual binary signature of the bytecode.
great stuff. but you just gotta love the consult() function, you can almost have a lispy type syntax for a random language and avoid the need for a parser/lexer fully and just consult source code into the compiler and do stuff with it... code as data data as code...
The compiler has a so-called pattern match compiler which will take a pattern and compile it down to what is essentially a series of branches, switches and such. The code for Erlang is in v3_kernel.erl in the compiler. It uses Simon Peyton Jones, "The Implementation of Functional
Programming Languages", available online at
http://research.microsoft.com/en-us/um/people/simonpj/papers/slpj-book-1987/
Another worthy paper is the one by Peter Sestoft,
http://www.itu.dk/~sestoft/papers/match.ps.gz
which derives a pattern match compiler by inspecting partial evaluation of a simpler system. It may be an easier read, especially if you know ML.
The basic idea is that if you have, say:
% 1
f(a, b) ->
% 2
f(a, c) ->
% 3
f(b, b) ->
% 4
f(b, c) ->
Suppose now we have a call f(X, Y). Say X = a. Then only 1 and 2 are applicable. So we check Y = b and then Y = c. If on the other hand X /= a then we know that we can skip 1 and 2 and begin testing 3 and 4. The key is that if something does not match it tells us something about where the match can continue as well as when we do match. It is a set of constraints which we can solve by testing.
Pattern match compilers seek to optimize the number of tests so there are as few as possible before we have conclusion. Statically typed language have some advantages here since they may know that:
-type foo() :: a | b | c.
and then if we have
-spec f(foo() -> any().
f(a) ->
f(b) ->
f(c) ->
and we did not match f(a), f(b) then f(c) must match. Erlang has to check and then fail if it doesn't match.

Resources