Below is the Input_dict for data analysis:
input_dict =
{
"C:\\arm64\\lib_apple.so": { "func-abc": [5,6,7,8], "func-123":[1,1,1,1] },
"C:\\arm64\\lib_banana.so": { "func-123": [2,3,4], "func-rt": [0,0] },
"C:\\armeabi\\lib_banana.so": { "func-123": [1,0,0], "func-rt": [1,5] },
"C:\\armeabi\\lib2.so": { "func-0": [1]},
"C:\\x86\\lib_apple.so": { "func-so": [5,6,7,8], "func-123": [2,2,1,1] },
"C:\\x86\\lib_banana.so": { "func-rt": [2,0] },
"C:\\x86\\lib2.so": { "func-0": [1,2,3]}
}
The aim is to compare the 'values' of functions with same name of different architectures(arm64,armeabi,x86).
In other words, I want to compare the "lists" of functions(with same name) in different libraries(.so) files.
For example: Comparing func-123: [2,3,4] with func-123: [1,0,0] from arm64\lib_banana.so and armeabi\lib_banana.so respectively.
One of the desired output could be:
{ lib_apple.so: { func-123: [arm64,[1,1,1,1]],[x86,[2,2,1,1]]}}
You can restructure your function data to order by their name first, then supported architectures. Afterwards, print out those functions that appear in multiple architectures:
from collections import defaultdict
from pathlib import PureWindowsPath
lib2func = {
r'C:\arm64\lib_apple.so': { 'func-abc': [5,6,7,8], 'func-123': [1,1,1,1] },
r'C:\arm64\lib_banana.so': { 'func-123': [2,3,4], 'func-rt': [0,0] },
r'C:\armeabi\lib_banana.so': { 'func-123': [1,0,0], 'func-rt': [1,5] },
r'C:\armeabi\lib.so': {},
r'C:\armeabi\lib2.so': { 'func-0': [1]},
r'C:\x86\lib_apple.so': { 'func-so': [5,6,7,8], 'func-123': [2,2,1,1] },
r'C:\x86\lib_banana.so': { 'func-rt': [2,0] },
r'C:\x86\lib2.so': { 'func-0': [1,2,3] },
}
# restructure
func2arch = defaultdict(dict)
for lib_path, functions in lib2func.items():
path = PureWindowsPath(lib_path)
lib = path.name
arch = path.parent.name
for func_name, func_val in functions.items():
func2arch[(lib, func_name)][arch] = func_val
# find functions defined for multiple architectures
for (lib, func_name), arch_data in func2arch.items():
if len(arch_data) < 2:
continue # skip functions that only appear once
print(lib, func_name, arch_data)
gives
lib_apple.so func-123 {'arm64': [1, 1, 1, 1], 'x86': [2, 2, 1, 1]}
lib_banana.so func-123 {'arm64': [2, 3, 4], 'armeabi': [1, 0, 0]}
lib_banana.so func-rt {'arm64': [0, 0], 'armeabi': [1, 5], 'x86': [2, 0]}
lib2.so func-0 {'armeabi': [1], 'x86': [1, 2, 3]}
The above code assumes that library/function name pairs are unique.
Related
I have this TXT file:
{ input: [0,0], output: [0], id: 232362 }
{ input:[0,1], output: [1], id: 232363 }
I would like to convert it into array of objects in Typescript this way:
[
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] }
];
Could you help me, please?
I am a beginner, sorry.
I'm trying to draw a polygon from a list of points with labels on each of the sides (borders) with the length of the sides?
Is there a simple way to get this happening?
Here's a snippet with what I've got at present. Note that I want to be able to use an arbitrary number of points, not just three if at all possible.
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5],
axis: true
});
var points = [
[0, 0],
[0, 1],
[1, 0]
];
var pg = board.create('polygon', points, {
fixed: true,
hasInnerPoints: true,
vertices: {
visible: false
},
borders: {
names: ['a', 'b', 'c'],
withLabel: true
}
});
It is possible to set the label text of each border to be a function. This has to be done after the construction of the polygon. A possible solution would look like this:
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5], axis:true
});
var points = [
[0, 0],
[0, 2],
[2, 0]
];
var pg = board.create('polygon', points, {
fixed: true,
hasInnerPoints: true,
vertices: {
visible: false
},
borders: {
names: ['a', 'b', 'c'],
label: { offset: [-10, 10] },
withLabel: true
}
});
// Overwrite the labels of the borders:
for (let i = 0; i < pg.borders.length; i++) {
pg.borders[i].label.setText( () => pg.borders[i].L().toFixed(2) );
}
See https://jsfiddle.net/h6knmgjc/ for a working example.
My issue is the following. I have a collection (territories) that have a geometry of type Polygon inside. The thing is that the polygons in my applications must be validated against this collection. Meaning that for a polygon to be valid, it must be COMPLETELY contained in at least one territory.
As $geoWithin is intented to work only in one direction. I try to do the following.
db.territories.insertMany([
{
_id: 1,
geometry: {
type: "Polygon",
coordinates: [
[
[0, 0],
[5, 0],
[5, 5],
[0, 5],
[0, 0]
]
]
}
}
])
const aggregation = [
{
$addFields: {
polygonToValidate: {
type: "Polygon",
coordinates: [[[2, 2], [4, 2], [4, 4], [2, 4], [2, 2]]]
},
territoryPolygon: "$geometry",
},
},
{
$match: {
polygonToValidate: {
$geoWithin: {
$geometry: "$territoryPolygon"
}
}
}
}
]
db.territories.aggregate(aggregation);
The polygon is valid as it is completely contained inside the territory polygon. But is not posible to reference the document field, neither the field added in the $addFields (territoryPolygon).
Having collection Measurement such as shown below:
{
"Data" : [ [-5, [[1, 1023.0], [2, 694.0]]], [-1, [[1, 0.0], [2, 20.0]]], [-3, [[1, 30.75], [2, 30.75]]] ]
}
it reflects c# structure of Dictionary<int, Dictionary<int, double>> - what I'd need to do is to write an update script which will add 5 to all the parental dictionary keys. How could this be done via mongo update script? So it would turn the object to look as follows:
{
"Data" : [ [0, [[1, 1023.0], [2, 694.0]]], [4, [[1, 0.0], [2, 20.0]]], [2, [[1, 30.75], [2, 30.75]]] ]
}
The only way to do this is programatically, i.e., looping over the Data array and updating each individually.
This is probably not the structure that you really want if you need to update things in this way. The problem lies with the ability to match elements in a nested array in that the current limitation is that you can only match the first position and reference that index only when doing an update.
We can't tell much about your purpose based on what you have presented, but what you probably need is something like this:
{
"Data" : [
{
"pos": 0,
"ref": -5,
"A": { "x": 1, "y": 1023.0 },
"B": { "x": 2, "y": 694.0 }
},
{
"pos": 1,
"ref": -1,
"A": { "x": 1, "y": 0.0},
"B": { "x": 2, "y": 20.0 }
},
{
"pos": 2,
"ref": -3,
"A": { "x": 1, "y": 30.75 },
"B": { "x": 2, "y": 30.75 }
}
]
}
Yet even that does not allow you to update in a single query. You can do it with one for each element though:
db.collection.update({"_id": id, "Data.pos": 0}, {"$inc":{"Data.$.ref": 5}});
db.collection.update({"_id": id, "Data.pos": 1}, {"$inc":{"Data.$.ref": 5}});
db.collection.update({"_id": id, "Data.pos": 3}, {"$inc":{"Data.$.ref": 5}});
And your current schema would not allow you to do even that. And at least all of the elements could be accessed in this way, which again they could not before.
In any case, updating all of the array elements at once is not possible other than in a loop:
db.collection.find({ "_id": id }).forEach(function(doc) {
doc.Data.forEach(function(data) {
data.ref += 5;
});
db.collection.update(
{ "_id": doc._id },
{ "$set": { "Data": doc.Data } }
);
})
Or some variant that might even do something like the first example rather that just replacing the whole array as this does. Your current structure would rely on looping through several nested arrays to do the same thing.
Of course if you regularly have to update all elements in this way, then consider something other than an array. Or live with how you have to update, according to what your data access needs are.
Read the documentation on how things can be handled and make you decisions from there.
I have an Object MyObject which has a List of ThatObjects where each ThatObject is a list of ThoseObjects.
MyObject {
List<ThatObject> thatObjects;
}
ThatObject {
List<ThoseObject> thoseObjects
}
If I have a handle to MyObject, is it possible to get a handle to all thoseObjects in one list joined to together? Without have to iterate and make the joined list myself?
Thanks
Given:
class MyObject {
List thatObjects
}
class ThatObject {
List thoseObjects
}
We can make a test object of:
def o = new MyObject( thatObjects:[ new ThatObject( thoseObjects:[ 1, 2 ] ),
new ThatObject( thoseObjects:[ 3, 4 ] ) ] )
Then a simple walk through the properties gives us:
assert o.thatObjects.thoseObjects == [ [1, 2], [3, 4] ]
And call flatten to get a single list:
assert o.thatObjects.thoseObjects.flatten() == [ 1, 2, 3, 4 ]
Or, you could use collectMany
assert o.thatObjects.collectMany { it.thoseObjects } == [ 1, 2, 3, 4 ]