[
https://issues.apache.org/jira/browse/OPENNLP-1167?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16292275#comment-16292275
]
ASF GitHub Bot commented on OPENNLP-1167:
-----------------------------------------
tteofili closed pull request #295: OPENNLP-1167 - Remove WV#toDouble/FloatArray
URL: https://github.com/apache/opennlp/pull/295
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/DoubleArrayVector.java
b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/DoubleArrayVector.java
index dcbee8632..79d03a3af 100644
---
a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/DoubleArrayVector.java
+++
b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/DoubleArrayVector.java
@@ -44,27 +44,17 @@ public double getAsDouble(int index) {
}
@Override
- public float[] toFloatArray() {
+ public FloatBuffer toFloatBuffer() {
float[] floatVector = new float[vector.length];
for (int i = 0; i < floatVector.length ; i++) {
floatVector[i] = (float) vector[i];
}
- return floatVector;
- }
-
- @Override
- public double[] toDoubleArray() {
- return toDoubleBuffer().array();
- }
-
- @Override
- public FloatBuffer toFloatBuffer() {
- return FloatBuffer.wrap(toFloatArray()).asReadOnlyBuffer();
+ return FloatBuffer.wrap(floatVector).asReadOnlyBuffer();
}
@Override
public DoubleBuffer toDoubleBuffer() {
- return DoubleBuffer.wrap(vector);
+ return DoubleBuffer.wrap(vector).asReadOnlyBuffer();
}
@Override
diff --git
a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/FloatArrayVector.java
b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/FloatArrayVector.java
index c6be1f10c..0ee728764 100644
---
a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/FloatArrayVector.java
+++
b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/FloatArrayVector.java
@@ -44,27 +44,17 @@ public double getAsDouble(int index) {
}
@Override
- public float[] toFloatArray() {
- return toFloatBuffer().array();
+ public FloatBuffer toFloatBuffer() {
+ return FloatBuffer.wrap(vector).asReadOnlyBuffer();
}
@Override
- public double[] toDoubleArray() {
+ public DoubleBuffer toDoubleBuffer() {
double[] doubleVector = new double[vector.length];
for (int i = 0; i < doubleVector.length ; i++) {
doubleVector[i] = vector[i];
}
- return doubleVector;
- }
-
- @Override
- public FloatBuffer toFloatBuffer() {
- return FloatBuffer.wrap(vector).asReadOnlyBuffer();
- }
-
- @Override
- public DoubleBuffer toDoubleBuffer() {
- return DoubleBuffer.wrap(toDoubleArray());
+ return DoubleBuffer.wrap(doubleVector).asReadOnlyBuffer();
}
@Override
diff --git
a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVector.java
b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVector.java
index 94acb54bb..fea95b1d2 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVector.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVector.java
@@ -35,9 +35,6 @@
float getAsFloat(int index);
double getAsDouble(int index);
- float[] toFloatArray();
- double[] toDoubleArray();
-
FloatBuffer toFloatBuffer();
DoubleBuffer toDoubleBuffer();
diff --git
a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVectorTable.java
b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVectorTable.java
index bf0085850..17c347a3b 100644
---
a/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVectorTable.java
+++
b/opennlp-tools/src/main/java/opennlp/tools/util/wordvector/WordVectorTable.java
@@ -27,6 +27,7 @@
*/
@Experimental
public interface WordVectorTable {
+
WordVector get(CharSequence token);
int size();
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> WordVector toArray methods should be removed
> --------------------------------------------
>
> Key: OPENNLP-1167
> URL: https://issues.apache.org/jira/browse/OPENNLP-1167
> Project: OpenNLP
> Issue Type: Task
> Components: word vectors
> Reporter: Tommaso Teofili
> Assignee: Tommaso Teofili
> Fix For: 1.8.4
>
>
> {{WordVector#toDoubleArray}} and {{WordVector#toFloatArray}} always require a
> copy, have size limitation and therefore should be probably removed.
> Additionally we should think whether it makes sense to keep
> {{FloatArrayVector#toDoubleBuffer}} and {{DoubleArrayVector#toFloatBuffer}}
> which also require a copy. The alternative is to throw an
> {{UnsupportedOperationException}} in such cases.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)