In systemverilog how to provide commandline overrides for complex fields like associative array fields - command-line

Lets say i have added a associative array string,string field to the factory through the macro `ovm_field_aa_string_string macro. Is there a way to configure it from command line like we do with simple int fields like follows:
./simv ... +ovm_set_config_int=scope,name,value
is there something like
./simv ... +ovm_set_config_aa_string_string=scope,name,key=val,key2=val2

No, you can only set int's and strings from the command line. I strongly discourge the use of any `uvm_field macros because of their inability to deal with complex times, the the poor simulation performance they impose.

This seems to be already answered by someone else
Here is the link to the post
how to get array of values as plusargs in systemverilog?

Related

Where would custom subscripts be suited over methods/functions and why?

I've researched this in Swift and am confused on where custom subscripts are useful compared to methods and functions. What is the power in using them rather than using a method/func?
It's purely stylistic. Use a subscript whenever you'd prefer this syntax:
myObject[mySubscript] = newValue
over this one:
myObject.setValue(newValue, forSubscript: mySubscript)
Subscripts are more concise and, when used in appropriate situations, clearer in intent.
Which is an easier, clearer way to refer to an array element: myArray[1] or myArray.objectAtIndex(1)?
Would you like to saymyArray[1...3], or would it by just fine if you had to say something like myArray.sliceFromIndex(1).throughIndex(3) every time?
And hey, you know what? Arithmetic operators are also just functions. So don't we abandon them, so we'd have to say something like
let sum = a.addedTo(b.multipliedBy(c))
Wouldn't that be just the same really? What's the power in having arithmetic operators really?

Simple dictionary of heterogeneous settings, ported from Clojure

I am porting a Clojure program to Swift. Being a dynamically typed language, it is easy to throw different values together like this:
(def settings {:total-gens 5
:name "Incredible Program"
:options [:a :b :c :d :e]
:final-comment "Hope you had a good time."})
I pass settings maps like this around in the program, and I wanted to have a fairly similar process in Swift.
Right away, I feel like I am fighting the type system and I'm wondering what is the most elegant way to do this.
Here are two options that were recommended to me, both of which seem verbose or strange:
1) First, make an enum type of all possible settings value types. Then, create a dictionary of String: SettingsEnumType. Every time I need to add a new type of value to my dictionary, I first need to change the enum definition, and then change the actual dictionary.
2) Instead, create an empty protocol with no requirements. Then extend values like Int, String, etc to adopt this protocol, even though it is really a "dummy" protocol. Then make my settings dictionary String : SettingsProtocol so I can add whatever type I want in there (after first extending the type).
Both of these options feel weird to me, like I'm trying to circumvent the type system rather than have it work for me. The second option is frankly silly, but would no doubt work as needed.
Are there any other possibilities for doing something like this? Additionally, would the String type be the only obvious type for the keys in a settings dictionary? In this case, Clojure has again spoiled me with the useful keyword type that simultaneously acts as a look-up function in addition to a value type.
Any advice/pointers appreciated as I consider this new language.
After referring to Array with string and number answer, I believe you can create a Heterogeneous Dictionary with below Syntax:
let heteroDict = Dictionary<Any, Any>()
Can you try this one?

How can I make the value of an expression equal to a second return value of another expression

Is there an idiomatic way in Matlab to bind the value of an expression to the nth return value of another expression?
For example, say I want an array of indices corresponding to the maximum value of a number of vectors stored in a cell array. I can do that by
function I = max_index(varargin)
[~,I]=max(varargin{:});
cellfun(#max_index, my_data);
But this requires one to define a function (max_index) specific for each case one wants to select a particular return value in an expression. I can of course define a generic function that does what I want:
function y = nth_return(n,fun,varargin)
[vals{1:n}] = fun(varargin{:});
y = vals{n};
And call it like:
cellfun(#(x) nth_return(2,#max,x), my_data)
Adding such functions, however, makes code snippets less portable and harder to understand. Is there an idiomatic to achieve the same result without having to rely on the custom nth_return function?
This is as far as I know not possible in another way as with the solutions you mention. So just use the syntax:
[~,I]=max(var);
Or indeed create an extra function. But I would also suggest against this. Just write the extra line of code, in case you want to use the output in another function. I found two earlier questions on stackoverflow, which adress the same topic, and seem to confirm that this is not possible.
Skipping outputs with anonymous function in MATLAB
How to elegantly ignore some return values of a MATLAB function?
The reason why the ~ operator was added to MATLAB some versions ago was to prevent you from saving variables you do not need. If there would be a syntax like the one you are searching for, this would not have been necessary.

Variable in CDATA in Scala

Is there a way to put a variable to be expanded in a cdata section in scala
val reason = <reason><![CDATA[ {failedReason} ]]></reason>
It could be even simplier:
val reason = <reason>{scala.xml.PCData(failedReason)}</reason>
I am not sure if you can get that through native XML support, but you could do something like:
scala.xml.XML.loadString("<reason><![CDATA[%s]]></reason>".format(failedReason))
You lose some of the compile-time validations that way, but it should give you am xml element with the data which you are looking for. Since it returns a scala.xml.Elem, you can also embed the result in a larger XML structure.
EDIT
After thinking about this a bit more, the following may be a beter (and less fragile) way to do this. It restricts the free-text portion to only the CDATA, minimizing the potential for unbalanced expressions.
<reason>{ scala.xml.Unparsed("<![CDATA[%s]]>".format(failedReason)) }</reason>

What does the . operator do in matlab?

I came across some matlab code that did the following:
thing.x=linspace(...
I know that usually the . operator makes the next operation elementwise, but what does it do by itself? Is this just a sub-object operator, like in C++?
Yes its subobject.
You can have things like
Roger.lastname = "Poodle";
Roger.SSID = 111234997;
Roger.children.boys = {"Jim", "John"};
Roger.children.girls = {"Lucy"};
And the things to the right of the dots are called fields.
You can also define classes in Matlab, instatiate objects of those classes, and then if thing was one of those objects, thing.x would be an instance variable in that object.
The matlab documentation is excellent, look up "fields" and "classes" in it.
There are other uses for ., M*N means multiploy two things, if M, N are both matrices, this implements the rules for matrix multiplication to get a new matrix as its result. But M.*N means, if M, N are same shape, multiply each element. And so no like that with more subtleties, but out of scope of what you asked here.
As #marc points out, dot is also used to reference fields and subfields of something matlab calls a struct or structure. These are a lot like classes, subclasses and enums, seems to me. The idea is you can have a struct data say, and store all the info that goes with data like this:
olddata = data; % we assume we have an old struct like the one we are creating, we keep a reference to it
data.date_created=date();
data.x_axis = [1 5 2 9];
data.notes = "This is just a trivial example for stackoverflow. I didn't check to see if it runs in matlab or not, my bad."
data.versions.current = "this one";
data.versions.previous = olddata;
The point is ANY matlab object/datatype/whatever you want to call it, can be referenced by a field in the struct. The last entry shows that we can even reference another struct in the field of a struct. The implication of this last bit is we could look at the date of creation of the previous verions:
data.versions.previous.date_created
To me this looks just like objects in java EXCEPT I haven't put any methods in there. Matlab does support java objects which to me look a lot like these structs, except some of the fields can reference functions.
Technically, it's a form of indexing, as per mwengler's answer. However, it can also be used for method invocation on objects in recent versions of MATLAB, i.e.
obj.methodCall;
However note that there is some inefficiency in that style - basically, the system has to first work out if you meant indexing into a field, and if not, then call the method. It's more efficient to do
methodCall(obj);