MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / setAttr

Function setAttr

tensorflow/go/graph.go:336–466  ·  view source on GitHub ↗
(cdesc *C.TF_OperationDescription, status *status, name string, value interface{})

Source from the content-addressed store, hash-verified

334}
335
336func setAttr(cdesc *C.TF_OperationDescription, status *status, name string, value interface{}) error {
337 cAttrName := C.CString(name)
338 defer C.free(unsafe.Pointer(cAttrName))
339 switch value := value.(type) {
340 case string:
341 cstr := C.CString(value)
342 C.TF_SetAttrString(cdesc, cAttrName, unsafe.Pointer(cstr), C.size_t(len(value)))
343 C.free(unsafe.Pointer(cstr))
344 case []string:
345 size := len(value)
346 list := make([]unsafe.Pointer, size)
347 lens := make([]C.size_t, size)
348 for i, s := range value {
349 list[i] = unsafe.Pointer(C.CString(s))
350 lens[i] = C.size_t(len(s))
351 }
352 if size > 0 {
353 C.TF_SetAttrStringList(cdesc, cAttrName, &list[0], &lens[0], C.int(size))
354 } else {
355 C.TF_SetAttrStringList(cdesc, cAttrName, nil, nil, 0)
356 }
357 for _, s := range list {
358 C.free(s)
359 }
360 case int64:
361 C.TF_SetAttrInt(cdesc, cAttrName, C.int64_t(value))
362 case []int64:
363 size := len(value)
364 list := make([]C.int64_t, size)
365 for i, v := range value {
366 list[i] = C.int64_t(v)
367 }
368 if size > 0 {
369 C.TF_SetAttrIntList(cdesc, cAttrName, &list[0], C.int(size))
370 } else {
371 C.TF_SetAttrIntList(cdesc, cAttrName, nil, 0)
372 }
373 case float32:
374 C.TF_SetAttrFloat(cdesc, cAttrName, C.float(value))
375 case []float32:
376 size := len(value)
377 list := make([]C.float, size)
378 for i, v := range value {
379 list[i] = C.float(v)
380 }
381 if size > 0 {
382 C.TF_SetAttrFloatList(cdesc, cAttrName, &list[0], C.int(size))
383 } else {
384 C.TF_SetAttrFloatList(cdesc, cAttrName, nil, 0)
385 }
386 case bool:
387 v := C.uchar(0)
388 if value {
389 v = 1
390 }
391 C.TF_SetAttrBool(cdesc, cAttrName, v)
392 case []bool:
393 size := len(value)

Callers 2

UpdateDataFormatMethod · 0.85
AddOperationMethod · 0.85

Calls 5

makeFunction · 0.85
appendFunction · 0.85
freeMethod · 0.80
NumDimensionsMethod · 0.80
ErrMethod · 0.45

Tested by

no test coverage detected