Skip to content

Commit 829fda7

Browse files
committed
run mvn spotless:apply
1 parent a4d12ce commit 829fda7

File tree

1 file changed

+88
-79
lines changed

1 file changed

+88
-79
lines changed
Lines changed: 88 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
2-
Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2+
Copyright 2019 The TensorFlow Authors. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
=======================================================================
16-
*/
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
=======================================================================
16+
*/
1717

1818
package org.tensorflow.internal.c_api;
1919

@@ -33,84 +33,93 @@
3333

3434
@Properties(inherit = org.tensorflow.internal.c_api.presets.tensorflow.class)
3535
public abstract class AbstractTF_Tensor extends Pointer {
36-
protected static class DeleteDeallocator extends TF_Tensor implements Pointer.Deallocator {
37-
DeleteDeallocator(TF_Tensor s) { super(s); }
38-
@Override public void deallocate() {
39-
if (!isNull()) {
40-
if (TF_TensorType(this) == TF_STRING) {
41-
TF_Tensor moved = TF_TensorMaybeMove(this);
42-
if (moved != null) {
43-
// we need to deallocate the strings themselves before deallocating the tensor memory
44-
long n = TF_TensorElementCount(moved);
45-
TF_TString data = new TF_TString(TF_TensorData(moved));
46-
for (int i = 0; i < n; i++) {
47-
TF_TString_Dealloc(data.position(i));
48-
}
49-
TF_DeleteTensor(moved);
50-
} else {
51-
// TensorBuffer is shared, leave contained strings alone.
52-
TF_DeleteTensor(this);
53-
}
54-
} else {
55-
TF_DeleteTensor(this);
56-
}
36+
protected static class DeleteDeallocator extends TF_Tensor implements Pointer.Deallocator {
37+
DeleteDeallocator(TF_Tensor s) {
38+
super(s);
39+
}
40+
41+
@Override
42+
public void deallocate() {
43+
if (!isNull()) {
44+
if (TF_TensorType(this) == TF_STRING) {
45+
TF_Tensor moved = TF_TensorMaybeMove(this);
46+
if (moved != null) {
47+
// we need to deallocate the strings themselves before deallocating the tensor memory
48+
long n = TF_TensorElementCount(moved);
49+
TF_TString data = new TF_TString(TF_TensorData(moved));
50+
for (int i = 0; i < n; i++) {
51+
TF_TString_Dealloc(data.position(i));
5752
}
58-
setNull();
53+
TF_DeleteTensor(moved);
54+
} else {
55+
// TensorBuffer is shared, leave contained strings alone.
56+
TF_DeleteTensor(this);
57+
}
58+
} else {
59+
TF_DeleteTensor(this);
5960
}
61+
}
62+
setNull();
6063
}
64+
}
6165

62-
/** TensorFlow crashes if we don't pass it a deallocator, so... */
63-
protected static Deallocator_Pointer_long_Pointer dummyDeallocator = new Deallocator_Pointer_long_Pointer() {
64-
@Override public void call(Pointer data, long len, Pointer arg) { }
65-
}.retainReference();
66+
/** TensorFlow crashes if we don't pass it a deallocator, so... */
67+
protected static Deallocator_Pointer_long_Pointer dummyDeallocator =
68+
new Deallocator_Pointer_long_Pointer() {
69+
@Override
70+
public void call(Pointer data, long len, Pointer arg) {}
71+
}.retainReference();
6672

67-
/** A reference to prevent deallocation. */
68-
protected Pointer pointer;
73+
/** A reference to prevent deallocation. */
74+
protected Pointer pointer;
6975

70-
public AbstractTF_Tensor(Pointer p) { super(p); }
76+
public AbstractTF_Tensor(Pointer p) {
77+
super(p);
78+
}
7179

72-
/**
73-
* Calls TF_NewTensor(), and registers a deallocator.
74-
* @return TF_Tensor created. Do not call TF_DeleteTensor() on it.
75-
*/
76-
public static TF_Tensor newTensor(int dtype, long[] dims, Pointer data) {
77-
TF_Tensor t = TF_NewTensor(dtype, dims, dims.length, data, data.limit(), dummyDeallocator, null);
78-
if (t != null) {
79-
t.pointer = data;
80-
t.deallocator(new DeleteDeallocator(t));
81-
}
82-
return t;
80+
/**
81+
* Calls TF_NewTensor(), and registers a deallocator.
82+
*
83+
* @return TF_Tensor created. Do not call TF_DeleteTensor() on it.
84+
*/
85+
public static TF_Tensor newTensor(int dtype, long[] dims, Pointer data) {
86+
TF_Tensor t =
87+
TF_NewTensor(dtype, dims, dims.length, data, data.limit(), dummyDeallocator, null);
88+
if (t != null) {
89+
t.pointer = data;
90+
t.deallocator(new DeleteDeallocator(t));
8391
}
92+
return t;
93+
}
8494

85-
/**
86-
* Calls TF_AllocateTensor(), and registers a deallocator.
87-
* @return TF_Tensor created. Do not call TF_DeleteTensor() on it.
88-
*/
89-
public static TF_Tensor allocateTensor(int dtype, long[] dims, long length) {
90-
TF_Tensor t = TF_AllocateTensor(dtype, dims, dims.length, length);
91-
if (t != null) {
92-
if (TF_TensorType(t) == TF_STRING) {
93-
// we need to initialize the strings themselves after allocating the tensor memory
94-
long n = TF_TensorElementCount(t);
95-
TF_TString data = new TF_TString(TF_TensorData(t));
96-
for (int i = 0; i < n; i++) {
97-
TF_TString_Init(data.position(i));
98-
}
99-
}
100-
t.deallocator(new DeleteDeallocator(t));
95+
/**
96+
* Calls TF_AllocateTensor(), and registers a deallocator.
97+
*
98+
* @return TF_Tensor created. Do not call TF_DeleteTensor() on it.
99+
*/
100+
public static TF_Tensor allocateTensor(int dtype, long[] dims, long length) {
101+
TF_Tensor t = TF_AllocateTensor(dtype, dims, dims.length, length);
102+
if (t != null) {
103+
if (TF_TensorType(t) == TF_STRING) {
104+
// we need to initialize the strings themselves after allocating the tensor memory
105+
long n = TF_TensorElementCount(t);
106+
TF_TString data = new TF_TString(TF_TensorData(t));
107+
for (int i = 0; i < n; i++) {
108+
TF_TString_Init(data.position(i));
101109
}
102-
return t;
110+
}
111+
t.deallocator(new DeleteDeallocator(t));
103112
}
113+
return t;
114+
}
104115

105-
/** Registers a deallocator and returns this. */
106-
public TF_Tensor withDeallocator() {
107-
return (TF_Tensor)this.deallocator(new DeleteDeallocator((TF_Tensor)this));
108-
}
116+
/** Registers a deallocator and returns this. */
117+
public TF_Tensor withDeallocator() {
118+
return (TF_Tensor) this.deallocator(new DeleteDeallocator((TF_Tensor) this));
119+
}
109120

110-
/**
111-
* Calls the deallocator, if registered, otherwise has no effect.
112-
*/
113-
public void delete() {
114-
deallocate();
115-
}
121+
/** Calls the deallocator, if registered, otherwise has no effect. */
122+
public void delete() {
123+
deallocate();
124+
}
116125
}

0 commit comments

Comments
 (0)