struct

TensorFlow Custom Allocator and Accessing Data from Tensor

南楼画角 提交于 2020-01-23 12:10:08
问题 In TensorFlow, you can create custom allocators for various reasons (I am doing it for new hardware). Due to the structure of the device, I need to use a struct of a few elements as my data pointer which the allocator returns as a void* . In the kernels that I am writing, I am given access to Tensors but I need t get the pointer struct that I wrote. Examining the classes, it seemed that I could get this struct by doing tensor_t.buf_->data() Tensor::buf_ TensorBuffer::data() The problem is

TensorFlow Custom Allocator and Accessing Data from Tensor

不打扰是莪最后的温柔 提交于 2020-01-23 12:10:06
问题 In TensorFlow, you can create custom allocators for various reasons (I am doing it for new hardware). Due to the structure of the device, I need to use a struct of a few elements as my data pointer which the allocator returns as a void* . In the kernels that I am writing, I am given access to Tensors but I need t get the pointer struct that I wrote. Examining the classes, it seemed that I could get this struct by doing tensor_t.buf_->data() Tensor::buf_ TensorBuffer::data() The problem is

Golang struct literal syntax with unexported fields

我只是一个虾纸丫 提交于 2020-01-23 07:08:06
问题 I've got a largish struct which until just now I was instantiating with the struct literal syntax, e.g.: Thing{ "the name", ... } I've just added an unexported field the Thing struct and now Go is complaining: implicit assignment of unexported field 'config' in Thing literal . Is there any way I can continue using the literal syntax even though there's now an unexported field on the struct? 回答1: You can only use composite literals to create values of struct types defined in another package if

Enumerations within a struct - C vs C++

有些话、适合烂在心里 提交于 2020-01-23 05:54:57
问题 I'm trying to use Enums within a struct, this compiles and works fine with gcc . But the same code when compiled with g++ throws an error. #include<stdio.h> #include<stdlib.h> struct foo { enum {MODE1, MODE2, MODE3} mode; enum {TYPE1, TYPE2} type; }; void bar(struct foo* bar) { bar->mode = MODE1; } int main() { struct foo* foo = (struct foo*) malloc(sizeof(struct foo)); bar(foo); printf("mode=%d\n",foo->mode); } Output obtained with gcc : $ gcc foo.c $ ./a.out mode=0 Output obtained with g++

C dictionary/map

蹲街弑〆低调 提交于 2020-01-23 03:57:12
问题 I want to map struct members so I can eliminate if branches in a loop. What is the best way or convention to implement this in C? I suppose it could be a 2 dimensional array instead...then I could map integers to the char keys? char chunk[32]; int n; int i; char *ptr = config; while (*ptr != '\0') { int items_read = sscanf(ptr, "%31[^;]%n", chunk, &n); if(chunk[0] == 'S' && chunk[1] == 'P') { for(i=0;i<GLOBAL_MEAS_CUTOFF; i++) { theMeas[i].signal_path = atoi(&chunk[2]); } } if(chunk[0] == 'T'

Foreach struct weird compile error in C#

限于喜欢 提交于 2020-01-23 01:49:51
问题 namespace MyNamespace { public struct MyStruct { public string MyString; public int MyInt; public bool MyBool; } public class MyClass { private List<MyStruct> MyPrivateVariable; public List<MyStruct> MyVariable { get { if (MyPrivateVariable == null) { MyPrivateVariable = new List<MyStruct>(); MyPrivateVariable.Add(new MyStruct()); MyPrivateVariable.Add(new MyStruct()); } return MyPrivateVariable; } } public void MyLoop() { foreach (MyStruct ms in MyVariable) { // Doesn't compile, but it works

Casting explicitly-laid out structures

梦想与她 提交于 2020-01-23 01:19:31
问题 Let's say I have this structure, [StructLayout(LayoutKind.Explicit)] public struct Chapter4Time { [FieldOffset(0)] public UInt16 Unused; [FieldOffset(2)] public UInt16 TimeHigh; [FieldOffset(4)] public UInt16 TimeLow; [FieldOffset(6)] public UInt16 MicroSeconds; } and this structure. [StructLayout(LayoutKind.Explicit)] public struct IEEE_1588Time { [FieldOffset(0)] public UInt32 NanoSeconds; [FieldOffset(4)] public UInt32 Seconds; } How would I convert from one structure to the other? 回答1:

How to cast interface{} back into its original struct?

删除回忆录丶 提交于 2020-01-22 16:29:06
问题 I need a way to dynamically cast a struct/interface back to its original object. I can add methods / functions inside. basically I need something like this: MyStruct => Interface{} => MyStruct When on the final conversion I don't know anything about the original struct besides what come inside the struct, so I can't just so: a.(MyStruct) 回答1: No: as mentioned in this thread Go is neither covariant nor contravariant. Types are either equal or they aren't. You have to either take the structs

Explicit initialization of struct/class members

谁说胖子不能爱 提交于 2020-01-22 13:35:22
问题 struct some_struct{ int a; }; some_struct n = {}; n.a will be 0 after this; I know this braces form of initialization is inherited from C and is supported for compatibility with C programs, but this only compiles with C++, not with the C compiler. I'm using Visual C++ 2005. In C this type of initialization struct some_struct n = {0}; is correct and will zero-initialize all members of a structure. Is the empty pair of braces form of initialization standard? I first saw this form of

Explicit initialization of struct/class members

匆匆过客 提交于 2020-01-22 13:35:11
问题 struct some_struct{ int a; }; some_struct n = {}; n.a will be 0 after this; I know this braces form of initialization is inherited from C and is supported for compatibility with C programs, but this only compiles with C++, not with the C compiler. I'm using Visual C++ 2005. In C this type of initialization struct some_struct n = {0}; is correct and will zero-initialize all members of a structure. Is the empty pair of braces form of initialization standard? I first saw this form of