Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About castTo() method #7753

Closed
Charele opened this issue May 18, 2019 · 3 comments
Closed

About castTo() method #7753

Charele opened this issue May 18, 2019 · 3 comments

Comments

@Charele
Copy link

Charele commented May 18, 2019

@OverRide
public INDArray castTo(DataType dataType) {
if(isEmpty()){
if(dataType == dataType())
return this;
return Nd4j.empty(dataType);
}
val result = Nd4j.createUninitialized(dataType, this.shape(), this.ordering());
result.assign(this);
return result;
}

If this data type is equal with the target's, must we create other instance?
I mean:

@OverRide
public INDArray castTo(DataType dataType) {
if(dataType == dataType())
return this;
... ...

@AlexDBlack
Copy link
Contributor

What's the question here?

The code is right there, you can see what it does.
Empty arrays are immutable (no data) so we can return the same object.

And in future, just link the code directly, don't copy/paste with bad formatting.

@Override
public INDArray castTo(DataType dataType) {
if(isEmpty()){
if(dataType == dataType())
return this;
return Nd4j.empty(dataType);
}
val result = Nd4j.createUninitialized(dataType, this.shape(), this.ordering());
result.assign(this);
return result;
}

@Charele
Copy link
Author

Charele commented May 18, 2019

(Force on no-empty),
I mean if their data type are equal, can return "this" directly,
we don't must create another object,"val result...; return result"

@AlexDBlack
Copy link
Contributor

Yes, that's the way it is supposed to work - and (until now) the way I thought it already did.
That was (incorrectly) changed at some point.
#7754

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants