GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — New data generation functions and Neg trait implementation by 9prady9 · Pull Request #94 · arrayfire/arrayfire-rust

Conversation

@9prady9

@9prady9 9prady9 commented Dec 15, 2016

Copy link
Copy Markdown
Member

Fixes #93
Fixes #89

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
9prady9 added 2 commits December 15, 2016 12:30
@9prady9
new data generation function: constant_like
bcd9909
function to create an array with same shape and type as input array filled with a constant
@9prady9
Implement negation trait for Array
63293af
@9prady9 9prady9 added the Feature label Dec 15, 2016
@9prady9 9prady9 added this to the 3.4.1 milestone Dec 15, 2016
This was referenced Dec 15, 2016
Creating arrays similar to other arrays #93
Closed
Implement Neg overloaded operator for Array #89
Closed
@9prady9
9prady9 requested review from jramapuram and pavanky December 15, 2016 07:13
@pavanky

pavanky commented Dec 15, 2016

Copy link
Copy Markdown
Member

Are there non templated versions of random number generators ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jramapuram
jramapuram reviewed Dec 15, 2016
View reviewed changes

@jramapuram jramapuram left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just the one query.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/arith/mod.rs Outdated
type Output = Array;

fn neg(self) -> Self::Output {
constant_like(0.0, &self) - self

@jramapuram jramapuram Dec 15, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a benefit to this vs the following?

af::mul(&-1.0, &self);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@9prady9 9prady9 Dec 17, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are doing same number of operations (create a constant array and then do arithmetic operation of two arrays) under the hood except that the intrinsic operation is subtraction in the trait implementation where as the other version is doing multiplication. I think they would perform about the same - compiler may even optimise it for this particular cases (Multiplication by -1 and Subtraction from 0).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/data/mod.rs Outdated
/// # Return Values
///
/// Array with given constant value and input Array's shape and similar internal data type.
pub fn constant_like(value: f64, input: &Array) -> Array {

@jramapuram jramapuram Dec 15, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@9prady9

9prady9 commented Dec 17, 2016

Copy link
Copy Markdown
Member Author

@arrayfire/rust-devel Please check the latest commit, it should cover all the missing gaps now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9 9prady9 changed the title Constant_like and Neg trait New data generation functions and Neg trait implementation Dec 18, 2016
@9prady9
9prady9 requested a review from jramapuram December 19, 2016 07:57
jramapuram
jramapuram requested changes Dec 20, 2016
View reviewed changes
Comment thread src/data/mod.rs Outdated
/// # Return Values
///
/// Array filled with `value` and `dims` shape.
pub fn create_constant_i64(value: i64, dims: Dim4) -> Array {

@jramapuram jramapuram Dec 20, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you made these separate from the create_constant [precision], however can we do something to merge them? I.e. maybe an Enum or something? Not too big a deal either way though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@9prady9 9prady9 Dec 20, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jramapuram How can we do this using enum ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jramapuram jramapuram Jan 9, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of something like this: https://is.gd/taX9ac

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/data/mod.rs Outdated
/// # Return Values
///
/// Array of `dims` shape and filed with given constant `value`.
pub fn create_constant(real: f64, imag: f64, dims: Dim4, dtype: DType) -> Array {

@jramapuram jramapuram Dec 20, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove all the create_ parts from these functions? I think it is obvious that someone wants to create a constant if they call the constant function. It will also be more more consistent with the AF api

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@9prady9 9prady9 Dec 20, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't have same function names. If we remove the create_ prefix then name clash will occur.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jramapuram jramapuram Jan 9, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes forgot we already have that and need to specialize. See my gist for a possible solution: https://is.gd/taX9ac

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/data/mod.rs Outdated
/// # Return Values
///
/// Array filled with `value` and `dims` shape.
pub fn create_constant_u64(value: u64, dims: Dim4) -> Array {

@jramapuram jramapuram Dec 20, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment w.r.t. create_

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/data/mod.rs Outdated
/// # Return Values
/// Array
#[allow(unused_mut)]
pub fn create_range(dims: Dim4, seq_dim: i32, dtype: DType) -> Array {

@jramapuram jramapuram Dec 20, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment w.r.t. create_

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/data/mod.rs Outdated
///
/// Identity matrix
#[allow(unused_mut)]
pub fn create_identity(dims: Dim4, dtype: DType) -> Array {

@jramapuram jramapuram Dec 20, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment w.r.t. create_

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/data/mod.rs Outdated
///
/// Array
#[allow(unused_mut)]
pub fn create_iota(dims: Dim4, tdims: Dim4, dtype: DType) -> Array {

@jramapuram jramapuram Dec 20, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment w.r.t. create_

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jramapuram

jramapuram commented Dec 20, 2016

Copy link
Copy Markdown
Member

I found the need for constant a while ago. But since I don't really need U64_MAX & I64_MAX I approximated it with the following [using conv crate]:

use af;
use conv::{ConvUtil, Saturate};

/// Helper to return a constant value based on type
pub fn constant(dims: Dim4, aftype: DType, val: f32) -> Array {
  match aftype
  {
    DType::F32 => af::constant(val, dims),
    DType::F64 => af::constant(val.approx_as::<f64>().unwrap(), dims),
    DType::C32 => af::constant(Complex::new(val, 0f32)
                                , dims),
    DType::C64 => af::constant(Complex::new(val.approx_as::<f64>().unwrap(), 0f64)
                        , dims),
    DType::B8  => {
      if val > 0f32 {
        af::constant(true, dims)
      }else{
        af::constant(false, dims)
      }
    },
    DType::S32 => af::constant(val.approx_as::<i32>().saturate().unwrap(), dims),
    DType::U32 => af::constant(val.approx_as::<u32>().saturate().unwrap(), dims),
    DType::U8  => af::constant(val.approx_as::<u8>().saturate().unwrap(), dims),
    DType::S64 => af::constant(val.approx_as::<i64>().saturate().unwrap(), dims),
    DType::U64 => af::constant(val.approx_as::<u64>().saturate().unwrap(), dims),
    DType::S16 => af::constant(val.approx_as::<i16>().saturate().unwrap(), dims),
    DType::U16 => af::constant(val.approx_as::<u16>().saturate().unwrap(), dims),
  }
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9
9prady9 removed the request for review from pavanky December 20, 2016 10:06
@9prady9

9prady9 commented Dec 20, 2016

Copy link
Copy Markdown
Member Author

@jramapuram I don't like the create_ prefix either, but i couldn't figure out a way to keep both earlier versions of the data generation functions and the new ones with same function names. Even if i mark a function as deprecated, the new function cannot have the same name.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9
9prady9 requested review from jramapuram and pavanky December 21, 2016 14:20
@9prady9

9prady9 commented Jan 3, 2017

Copy link
Copy Markdown
Member Author

@pavanky @jramapuram Feedback pls, i want to release 3.4.1 of this wrapper this week if possible.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Jan 3, 2017

Copy link
Copy Markdown
Member

@jramapuram @9prady9

why won't the function shown here work:
#94 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Jan 3, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

That version is sacrificing accuracy of u64 and i64 by accepting the constant value as an f32

pub fn constant(dims: Dim4, aftype: DType, val: f32)

I don't think we can do that as a library.

Edited: Added to that, we can't have another function with same name as constant, hence the type suffixes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Jan 3, 2017

Copy link
Copy Markdown
Member

@9prady9 accept f64 and have special version called constant_long or something. This is what we do for the C and C++ versions anyway.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Jan 3, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I didn't check C++ API, but C API of arrayfire has different functions for u64, i64 and rest of the types.

Edited:

  • af_constant_ulong
  • af_constant_long
  • af_constant_complex and af_constant for test of the types
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Jan 3, 2017

Copy link
Copy Markdown
Member

@9prady9 I wasn't talking about having multiple functions, but about the name (specifically the create_ parts). Will @jramapuram's code causing a conflict?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Jan 3, 2017

Copy link
Copy Markdown
Member Author

Yes, we can't have same names.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Jan 3, 2017

Copy link
Copy Markdown
Member Author

For him it is working because he had them in different namespace.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jramapuram

jramapuram commented Jan 3, 2017

Copy link
Copy Markdown
Member

Sorry for the delay. Infrequent internet over the winter break. Will review in 2 days.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Jan 9, 2017

Copy link
Copy Markdown
Member Author

@arrayfire/rust-devel Awaiting feedback.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jramapuram

jramapuram commented Jan 9, 2017

Copy link
Copy Markdown
Member

Added a simple way to use Enums in comments. Another possible (but have not tested myself) way is to use generics: http://stackoverflow.com/questions/26810793/how-can-i-create-an-is-prime-function-that-is-generic-over-various-integer-types

See solution in that answer as well as comment in accepted answer. Not sure if the generics are robust enough to accept all numeric types yet though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9
New fns to create arrays using Dim4 and DType params
10a20d1
* constant_t
* range_t
* range_t
* iota_t
@9prady9
9prady9 force-pushed the constant_like_and_Negtrait branch from d202256 to 10a20d1 Compare January 10, 2017 16:09
@9prady9

9prady9 commented Jan 10, 2017

Copy link
Copy Markdown
Member Author

@jramapuram please check now. Using your suggestion, i have consolidated all the separate create_constant_* functions into a single function constant_t with the suffix _t suggesting that it takes additional type parameter (that's the shortest name i could come up with that is different from constant).

@pavanky please check now. I have renamed all create_* fns to have _t suffix now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Jan 10, 2017

Copy link
Copy Markdown
Member

looks good 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jramapuram
jramapuram approved these changes Jan 10, 2017
View reviewed changes
@jramapuram

jramapuram commented Jan 10, 2017

Copy link
Copy Markdown
Member

Looks great!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9
9prady9 merged commit 78a0353 into arrayfire:devel Jan 10, 2017
@9prady9
9prady9 deleted the constant_like_and_Negtrait branch January 10, 2017 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jramapuram jramapuram jramapuram approved these changes
@pavanky pavanky Awaiting requested review from pavanky

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Feature

Projects

None yet

Milestone

3.4.1

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@9prady9 @pavanky @jramapuram
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.