In tensorflow, can you define your own collection name? - collections

I searched all resources in tensorflow's API documents and can't find any indication.
It seems when using get_variable(), I can put a specific name for collections term like:
x=tf.get_variable('x',[2,2],collections='my_scope')
but get only empty list when doing:
tf.get_collection('my_scope')

collectionS needs a list of collection name.
>>x = tf.get_variable('x',[2,2], collections=['my_scope'])
>>tf.get_collection('my_scope')
[<tensorflow.python.ops.variables.Variable at 0x10d8e1590>]
watch out that if you use it some other operations can have side effects.
like tf.all_variables() will not work and thus tf.initialize_all_variables() also will not see your variable. One way to fix it is to specify the default collection too.
>>x = tf.get_variable('x',[2,2], collections=['my_scope', tf.GraphKeys.VARIABLES])
but things starts to get tedious.

Actually, you can use tf.get_collection to create a new collection:
tf.get_collection('my_collection')
var = tf.get_variable('var', [2, 2], initializer=tf.constant_initializer())
tf.add_to_collection('my_collection', var)

Related

How to filter additionaasset lookup/dialog to only list assets at work order location

I have a need to filter the list of available assets from which to choose to those assets that reside at the location of the current work order. I do not want to see assets in the list that are not at the current location.
I have located a place in the javascript
var filter = [];
filter.push({siteid: siteid});
additionalasset.lookupFilter = filter;
... which appears to let me push filters into a filter array. Would this be the ideal method to use? 1) Determine the location on the work order and 2) push an additional filter e.g.
filter.push({location: location});
I'm looking for a solution that is dynamic, such that if the user changes the location and then wants to select an asset, the available list of assets will update, based on this filter, to those assets at that location. I hope this is understandable.
This bit of code did what I needed. For some reason I can push multiple filter critera on one call to .push() but I can't .push() multiple filters separately as I was trying before.
var currLocation = workOrderSet.getCurrentRecord().get("location");
filter.push({siteid: siteid, location: currLocation});
Yes this is exactly how you should do this code wise. We had a bug (fixed in 7.5.2.1 I believe) where the very first location you picked would be reused the second time you tried to select the asset. If you're still seeing the same behavior at 7.5.2.1, open a PMR and we can get you an iFix to support this.

premake5 adding new complex fields

I am trying to add a new premake5 field in my premake5 script but am having trouble understanding how to specify the field.kind .
I want to add a field that contains a list of (path, string ) pairs but can't work out how to specify the kind spec .
The documentation and examples are not particularly clear.
This is how I have registered my new field
premake.api.register( {
name = "mypathmappings",
scope = "config",
kind = "list:path:string", or "list:keyed:path:string"
}
)
and inside of a config scope I declare the field item like so
project myproject
mypathmappings { ["path/to/file1"] = "stringvalue1", ["path/to/file2"] = "stringvalue2"}
However when it comes to processing time I don't get what I'm expecting in the field:
function processpathmappings(cfg)
local pathmappings = cfg.mypathmappings
for path, value in pairs(pathmappings) do
--do something with the path and value but
--value is not a string as expected
end
end
Can someone explain how the complex kinds can be built up correctly from the field kinds registered in api.lua?
I get that "list:integer" specifies a list of integers but don't know how the "keyed" element works for example.
Right now, it is not possible to control the "kind" of the keys in a keyed value. The best you will be able to get with the current system is kind="keyed:string", which should give you the values (the strings) that you want, but the paths will not be processed by Premake (made absolute, etc.)
If it is feasible, you might want to flip it around to kind="keyed:path" and set the values like this:
mypathmappings { ["stringvalue1"] = "path/to/file1" }
But that relies on your string values being unique within a map.
In theory, Premake's field API could be extended to support kinds of keys; feel free to open a ticket or submit a pull request.

Extracting Requirements folder Tree structure from QC using API

I am trying to extract requirements from QC Requirement module. i could extract all requirements of a QC project but i would like to extract selected requirements only. So i need to give folder path and extract requirements accordingly.
Currently i use ReqFactory to extract Reqs from QC. Could you please help me or give me idea to extract requirmeents from selected folder path.
I tried Req Path and father id, but still it does not fulfill my need as some may have multiple sub folders under parent folders.
I assume you like to get all the child requirements of a requirement using the OTA API? The only solution I can offer is a bit clumsy. First you have to get the requirement where you want to start, e.g. "Requirements\Projects\ProjectX". How to achieve that is described in the OTA API Reference as an example of the ReqFactory object ("Find a specified requirement in a specified folder"). Or it is posted in this forum. If you know the ID of the start-requirement you can simply get the requirement with req_factory.Item(id).
When you have your requirement where you want to start, you can use the Find-method of the ReqFactory to get all its children, resp. all Requirement objects starting with the same path as the start-requirement. Here is an example-method in Ruby:
def list_all_child_requirements(start_req)
req_factory = #tdc.ReqFactory
req_path_strange_format = start_req.Field("RQ_REQ_PATH")
child_req_list = req_factory.Find(start_req.ID, "RQ_REQ_PATH", req_path_strange_format, 8)
child_req_list.each do |list_req|
puts list_req
end
end
The req_path_strange_format contains a String in the strange Quality Center notation like "AAAAAB". The Find-method starts from the start-requirement and searches all requirements which path starts with the same path as the path of the start-requirement. The parameter 8 means "starts with pattern" (described in the API Reference, Enum tagTDAPI_REQMODE). I just don't know how to access the Enum using Ruby, thats why the magic 8 is used... The Find-method returns a list with format "ID,NAME". From there it should be no problem to extract the requirements.
Doing the same directly in QC with a VAPI-XP-TEST and VB looks like that:
TDOutput.Clear
Dim reqPathStrangeFormat
Set reqF = tdConnection.ReqFactory
Set startReq = reqF.Item(14) ' ID of parent requirement
reqPathStrangeFormat = startReq.Field("RQ_REQ_PATH")
TDOutput.Print reqPathStrangeFormat
Set childReqList = reqF.Find(startReq.ID, "RQ_REQ_PATH", reqPathStrangeFormat, TDREQMODE_FIND_START_WITH)
For Each childReq in childReqList
TDOutput.Print childReq
Next
This code first prints some strange string "AAAAAB" or something similiar, then a list with "ID,NAME" of the requirements.

Using XQuery with multiple collection functions

I am using the following XQuery to query a collection of files:
for $files in collection("/data?select=*data*.xml")
Each file in the directory has a specific name, which enables me to recognize it. I use this as the identifier, which I retrieve as follows:
let $file-id := tokenize(base-uri($files), "/")[last()]
The $file-id variable follows a certain pattern: abc-1234. The first eight characters are relevant, so I fetch them using the variable below:
let $file-link-id := substring($file-id, 1, 8)
Now, I have another collection of files, which I want to query. These files follow the same pattern in the name, because they contain connected information.
How can I use the $file-link-id to select the correct file in the second collection?
I assume I would have to include it in the second collection clause, something along the lines of ?select=$file-link-id.xml, but I am unsure of how to do this.
Maybe you could clearify your problem statement if I assume wrong here, because your problem seems to be very easy solveable (so maybe I misunderstood your problem).
So you have your correct $file-link-id and want to use it as string. If your xquery processor supports XQuery 3.0 you can use two pipes, i.e.
for $files in collection("/data?select=" || $file-link-id || ".xml")
If not, use string-join():
for $files in collection(string-join(("/data?select=", $file-link-id, ".xml"), ''))

filter functions problem

I'm working on a search component for an app I'm working on and I needed to add some filters to it. I've found an example and got the first filter working fine.
Now I'm trying to add a second filter I'm running into problems... In the example I found they use filterFunctions, but I only get an option for filterFunction, why is that?
Here's the example code
productsCollection.filterFunctions =
[
filterByPrice, filterByType,
filterByCondition, filterByVendor
]
And this is what I'm trying
acData.filterFunction = [filterByStatus, filterByDate]
but with this code I get the following error message - 1067: Implicit coercion of a value of type Array to an unrelated type Function.
Why am I getting this error and how would I go about add multiple filters to my Array Collection?
Thanks!
filterFunction must be set to a single function, not an Array or any other datatype. To combine multiple functions create one that combines them, like this:
acData.filterFunction = function(item:Object)
{
return
filterByPrice(item) &&
filterByType(item) &&
filterByCondition(item) &&
filterByVendor(item);
};
If you saw a sample that used filterFunctions plural that accepted an array, post a link. That's not anywhere in the standard Flex framework or in the new 4.0 beta afaik.
It looks like you are going to have to extend an arraycollection to make it work. this link should spell it out for you: http://blog.rotundu.eu/flex/arraycollection-with-multiple-filter-functions/

Resources