|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using static Tensorflow.Binding; |
| 6 | + |
| 7 | +namespace Tensorflow.Queues |
| 8 | +{ |
| 9 | + public class PriorityQueue : QueueBase |
| 10 | + { |
| 11 | + public PriorityQueue(int capacity, |
| 12 | + TF_DataType[] dtypes, |
| 13 | + TensorShape[] shapes, |
| 14 | + string[] names = null, |
| 15 | + string shared_name = null, |
| 16 | + string name = "priority_queue") |
| 17 | + : base(dtypes: dtypes, shapes: shapes, names: names) |
| 18 | + { |
| 19 | + _queue_ref = gen_data_flow_ops.priority_queue_v2( |
| 20 | + component_types: dtypes, |
| 21 | + shapes: shapes, |
| 22 | + capacity: capacity, |
| 23 | + shared_name: shared_name, |
| 24 | + name: name); |
| 25 | + |
| 26 | + _name = _queue_ref.op.name.Split('/').Last(); |
| 27 | + |
| 28 | + var dtypes1 = dtypes.ToList(); |
| 29 | + dtypes1.Insert(0, TF_DataType.TF_INT64); |
| 30 | + _dtypes = dtypes1.ToArray(); |
| 31 | + |
| 32 | + var shapes1 = shapes.ToList(); |
| 33 | + shapes1.Insert(0, new TensorShape()); |
| 34 | + _shapes = shapes1.ToArray(); |
| 35 | + } |
| 36 | + |
| 37 | + public Operation enqueue_many<T>(long[] indexes, T[] vals, string name = null) |
| 38 | + { |
| 39 | + return tf_with(ops.name_scope(name, $"{_name}_EnqueueMany", vals), scope => |
| 40 | + { |
| 41 | + var vals_tensor1 = _check_enqueue_dtypes(indexes); |
| 42 | + var vals_tensor2 = _check_enqueue_dtypes(vals); |
| 43 | + |
| 44 | + var tensors = new List<Tensor>(); |
| 45 | + tensors.AddRange(vals_tensor1); |
| 46 | + tensors.AddRange(vals_tensor2); |
| 47 | + |
| 48 | + return gen_data_flow_ops.queue_enqueue_many_v2(_queue_ref, tensors.ToArray(), name: scope); |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + public Tensor[] dequeue(string name = null) |
| 53 | + { |
| 54 | + Tensor[] ret; |
| 55 | + if (name == null) |
| 56 | + name = $"{_name}_Dequeue"; |
| 57 | + |
| 58 | + if (_queue_ref.dtype == TF_DataType.TF_RESOURCE) |
| 59 | + ret = gen_data_flow_ops.queue_dequeue_v2(_queue_ref, _dtypes, name: name); |
| 60 | + else |
| 61 | + ret = gen_data_flow_ops.queue_dequeue(_queue_ref, _dtypes, name: name); |
| 62 | + |
| 63 | + return ret; |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments