What is MATLAB equivalent of Java HashSet? - matlab

Java has HashSet class which I can use to create sets and add element in constant time making it efficient to compute unique values in a list.
How can I do the same in MATLAB? Is there an equivalent native class? This question proposes using Java's HashSet but does not provide native class.

Use struct in Matlab. Refer to http://www.mathworks.com/help/matlab/ref/struct.html

Related

Interface MiniZinc to other languages

I want to solve a problem for which a score function has been implemented in Prolog. Would it possible to call Prolog (or another language) from a MiniZinc script in the case an optimization function is defined in another language?
For instance, MiniZinc can easily be called from python through the package MiniZinc Python. Would there exist an interface to do the opposite (call Python from MiniZinc)?
There is currently no foreign function interface in MiniZinc. So it is currently not possible to use functionality from an other language, like Prolog, in MiniZinc.
Different from exposing MiniZinc to a programming language, integrating other languages into MiniZinc might not be as easy. The problem is that all parts of a MiniZinc instance needs to either be resolved by the compiler or be transformed to a solver-level construct. This means that a computation on parameter values is probably relatively easy to do in another language: MiniZinc could just call a compiled version of the computation. Transformations of variables, on the other hand, would require a strict MiniZinc API to perform them. You could compare such an interface to how you can use CPython in C: it would be more like writing a MiniZinc module in another language.

Convering values stored within another language to case classes

Rookie question here.
I have 2 apps that utilize Hazelcast, one is in Typescript and the other is in Scala.
The Typescript app stores all the data and the Scala one interacts with it.
I need an easy way to parse items inside of a map to a case class, this is easy if the HazelCast data is saved within Scala because it can be cast but when I attempt to do this with data stored from Typescript I get the following
java.lang.ClassCastException: com.hazelcast.core.HazelcastJsonValue cannot be cast to TheCaseClass
I'm using circe and finch in the rest of the application, not sure if circe can be used here to parse it.
tl;dr Is there an easy way to convert HazelCast data stored in Typescript to a Scala case class.
Thanks
You cannot just take one arbitrary class and cast it to another class. You have to parse them. If you use Hazelcast then probably Hanzelcast Scala is what you should use.
Wiki suggest that you would have to do at least:
import com.hazelcast.Scala._
serialization.Defaults.register(conf.getSerializationConfig)
though it might require you to write your own custom serialization.

Traversing a Z3Context using the z3.scala.dsl API

I'm using the scala^Z3 tool for a small library that (among other things) prints the constraints of a Z3Context in latex format. While it's possible to traverse the Z3AST and latex-ify the expressions by string comparison, it would be much nicer to use the object structure of the z3.scala.dsl package. Is there a way to obtain a z3.scala.dsl.Tree from a Z3AST?
It's true that the DSL is currently "write only", in that you can use it to create trees and ship them to Z3 but not to read them back.
The standard way to read Z3 trees is to use getASTKind and getDeclKind from Z3Context. The classes that represent the results are Z3ASTKind and Z3DeclKind respectively. (Since most trees are applications, the latter is where most of the information is).
It looks like the way to do this is create the original constraints using z3.scala.dsl, then add each constraint using Z3Context.assertCnstr (tree: Tree[BoolSort]). This way I have the whole DSL tree for easy transformation to latex. For some reason the examples on the scala^Z3 website assemble the AST without using the DSL at all, so this alternative wasn't obvious.

How to access an array of structs in simulink?

I have the problem, that I have to access a funktion form a dll in matlab/Simulink in the rtw.
This should work with a s function, but I have the needed parameters in a array of structures organized.
The question is now how I can reach them when I want to call my DLL function?
Or is there a better way (e.g. level 2 Matlab files or something similar)?
The pure simulation (without RTW) worked pretty well with level 2 m files but I am not able to write a tlc file for compiling them. I did not find much on the net and the documentation only about C sources.
Thanks
Christian
For signals in Simulink, what you are asking for is an array of buses. There is similar support for using arrays of structs for parameters. For calling an external function, you might want to look at the legacy code tool. You might also be able to use the MATLAB function block to call your external dll.
In addition to what #MikeT says:
Generating code from Level 2 M-S-Functions is problematic. Read this: http://www.mathworks.co.uk/help/toolbox/simulink/sfg/f7-67622.html#brgscav-1
Also, M-S-functions are generally slow, because they run in the MATLAB interpreter: http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/
In the end I coded the problem in C and used an array where I defined to order of the elements. Then I wrote some interface functions to access this "virtual" struct.
This is not very good coding but the easiest way I have found and it is portable.
Thanks

scala: analogy to metaclasses in python?

in scala i need to implement something similar to python metaclasses. in my case the goal of using the metaclasses is usually to create a registry of all the subclasses of a particular base class - that is, a mapping from say a string representation of the class to a reference to the class. in python it's very convenient to put a metaclass on the base class so that nothing special needs to be done on every subclass. i'm looking to do something similar in scala. is there any way to emulate metaclasses, or otherwise do this a different way? thanks!
If you know the fully qualified name of the class, you can load it using the usual Java reflection methods in java.lang.Class, namely Class.forName(String fqClassName). Given the resulting instance of Class, instantiation is easy only if there's a zero-argument constructor, otherwise you get entangled in the messy world of all the Java reflection types.
If you want a kind of "discovery" where classes unknown at compile time and whose names are not supplied as an input or parameter of the program in some way, then the classloader approach is probably the only answer.
There's nothing similar to python's metaclasses. The registry you speak of might be possible using custom class loaders or reflection.